Skip to content

Commit

Permalink
RefreshTokenGrant
Browse files Browse the repository at this point in the history
  • Loading branch information
ib-lundgren committed Dec 19, 2012
1 parent eee4b60 commit ae2c5b9
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 0 deletions.
1 change: 1 addition & 0 deletions AUTHORS
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,4 @@ Michael Vogt
Barry Warsaw
Silas Snider
Tom Christie
Chez
43 changes: 43 additions & 0 deletions oauthlib/oauth2/draft25/grant_types.py
Original file line number Diff line number Diff line change
Expand Up @@ -473,3 +473,46 @@ def validate_token_request(self, request):
raise errors.UnsupportedGrantTypeError()

self.request_validator.validate_request_scopes(request)


class RefreshTokenGrant(GrantTypeBase):

@property
def scope(self):
return ('default',)

def __init__(self, request_validator=None):
self.request_validator = request_validator or RequestValidator()

def create_token_response(self, request, token_handler):
"""
Validate the refresh token grant and the actual refresh token.
The client MUST use the refresh token provided on issue of the
access token.
"""
try:
self.validate_token_request(request)
except errors.OAuth2Error as e:
return None, {}, e.json, 400
return None, {}, json.dumps(token_handler.create_token(request, refresh_token=True)), 200

def validate_token_request(self, request):

if request.grant_type != 'refresh_token':
raise errors.UnsupportedGrantTypeError()

if request.refresh_token is None:
raise errors.InvalidRequestError(
description='Missing refresh token parameter.')

# TODO: document diff client & client_id, former is authenticated
# outside spec, i.e. http basic
if not self.request_validator.validate_client(
request.client, request.grant_type):
raise errors.UnauthorizedClientError()

# validate_refresh_token must be provided by the provided request_validator.
if not self.request_validator.validate_refresh_token(
request.client, request.refresh_token):
raise errors.InvalidRequestError()

0 comments on commit ae2c5b9

Please sign in to comment.