Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions flask_oauthlib/provider/oauth2.py
Original file line number Diff line number Diff line change
Expand Up @@ -131,11 +131,18 @@ def validate_client_id(self, client_id):
if token_generator and not callable(token_generator):
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I just copied the block that handled "the other generator". I agree with "isinstance", but let's do that in a separate commit - and then fix both cases of course. I'll upload that soon.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(as I wrote above - callable() is "okey" again, so I'll don't upload any new commits to fix that, unless you insist)

token_generator = import_string(token_generator)

refresh_token_generator = self.app.config.get(
'OAUTH2_PROVIDER_REFRESH_TOKEN_GENERATOR', None
)
if refresh_token_generator and not callable(refresh_token_generator):
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

callable?

I think isinstance is better.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Well, callable is "undeprecated" as of http://bugs.python.org/issue10518 so I guess callable() would be the way to do it?

refresh_token_generator = import_string(refresh_token_generator)

if hasattr(self, '_validator'):
return Server(
self._validator,
token_expires_in=expires_in,
token_generator=token_generator,
refresh_token_generator=refresh_token_generator,
)

if hasattr(self, '_clientgetter') and \
Expand All @@ -161,6 +168,7 @@ def validate_client_id(self, client_id):
validator,
token_expires_in=expires_in,
token_generator=token_generator,
refresh_token_generator=refresh_token_generator,
)
raise RuntimeError('application not bound to required getters')

Expand Down
24 changes: 23 additions & 1 deletion tests/oauth2/test_oauth2.py
Original file line number Diff line number Diff line change
Expand Up @@ -389,7 +389,7 @@ class TestTokenGenerator(OAuthSuite):

def create_oauth_provider(self, app):

def generator(request, refresh_token=False):
def generator(request):
return 'foobar'

app.config['OAUTH2_PROVIDER_TOKEN_GENERATOR'] = generator
Expand All @@ -403,6 +403,28 @@ def test_get_access_token(self):
assert data['refresh_token'] == 'foobar'


class TestRefreshTokenGenerator(OAuthSuite):

def create_oauth_provider(self, app):

def at_generator(request):
return 'foobar'

def rt_generator(request):
return 'abracadabra'

app.config['OAUTH2_PROVIDER_TOKEN_GENERATOR'] = at_generator
app.config['OAUTH2_PROVIDER_REFRESH_TOKEN_GENERATOR'] = rt_generator
return default_provider(app)

def test_get_access_token(self):
rv = self.client.post(authorize_url, data={'confirm': 'yes'})
rv = self.client.get(clean_url(rv.location))
data = json.loads(u(rv.data))
assert data['access_token'] == 'foobar'
assert data['refresh_token'] == 'abracadabra'


class TestConfidentialClient(OAuthSuite):

def create_oauth_provider(self, app):
Expand Down