Skip to content
This repository has been archived by the owner on Jan 18, 2025. It is now read-only.

Fix flask required decorator to redirect on expired credentials. #452

Conversation

theacodes
Copy link
Contributor

No description provided.

@theacodes
Copy link
Contributor Author

/r @dhermes or @nathanielmanistaatgoogle

@elibixby ran into this in his application. Apparently I was mistaken in just checking credentials.invalid which doesn't actually get set to True until a request fails.

@waprin a similar change is probably need to the django helper.

@waprin
Copy link
Contributor

waprin commented Mar 4, 2016

acknowledged, I'll take a look at Django.


response = client.get('/protected')
self.assertEqual(response.status_code, httplib.OK)
self.assertTrue('Hello' in response.data.decode('utf-8'))

This comment was marked as spam.

This comment was marked as spam.

@theacodes
Copy link
Contributor Author

Thanks for the review, just FYI I won't be able to fix the few nits for a few days. Will ping when ready.

@theacodes theacodes force-pushed the flask-util-expired-credentials branch from 861cc4b to 3a30e21 Compare March 11, 2016 18:07
@theacodes
Copy link
Contributor Author

Comments addressed.

@dhermes
Copy link
Contributor

dhermes commented Mar 11, 2016

LoL Python 2.6. You need to swap out for unittest2 in tests.contrib.test_flask_util.

@theacodes theacodes force-pushed the flask-util-expired-credentials branch from 3a30e21 to a5e0223 Compare March 11, 2016 19:15
@theacodes
Copy link
Contributor Author

LoL Python 2.6

ugh. Fixed.


response = client.get('/protected')
self.assertEqual(response.status_code, httplib.FOUND)
self.assertTrue('oauth2authorize' in response.headers['Location'])

This comment was marked as spam.

@theacodes theacodes force-pushed the flask-util-expired-credentials branch from a5e0223 to 1966a6f Compare March 11, 2016 21:03
@theacodes
Copy link
Contributor Author

@nathanielmanistaatgoogle all of the instances self.assertTrue(y in z) have been changed to self.assertIn(y, z).

@theacodes theacodes force-pushed the flask-util-expired-credentials branch from 1966a6f to 947997c Compare March 11, 2016 21:15
@@ -443,7 +443,12 @@ def credentials(self):

def has_credentials(self):
"""Returns True if there are valid credentials for the current user."""
return self.credentials and not self.credentials.invalid
if not self.credentials:
return False

This comment was marked as spam.

This comment was marked as spam.

@theacodes theacodes force-pushed the flask-util-expired-credentials branch from 947997c to 98e2899 Compare March 11, 2016 21:30
if not self.credentials:
return False
# Is the access token expired? If so, do we have an refresh token?
if (self.credentials.access_token_expired

This comment was marked as spam.

This comment was marked as spam.

@theacodes theacodes force-pushed the flask-util-expired-credentials branch from 98e2899 to a82146a Compare March 11, 2016 21:48
@nathanielmanistaatgoogle
Copy link
Contributor

Looks good; waiting on fresh test results.

nathanielmanistaatgoogle added a commit that referenced this pull request Mar 11, 2016
Fix flask required decorator to redirect on expired credentials.
@nathanielmanistaatgoogle nathanielmanistaatgoogle merged commit 20dcfe2 into googleapis:master Mar 11, 2016
@theacodes
Copy link
Contributor Author

Thanks. :)

On Fri, Mar 11, 2016 at 1:53 PM Nathaniel Manista notifications@github.com
wrote:

Merged #452 #452.


Reply to this email directly or view it on GitHub
#452 (comment).

@theacodes theacodes mentioned this pull request Apr 15, 2016
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants