Move Grant Code creation logic into a functon.

This commit is contained in:
juanifioren 2015-03-12 12:40:36 -03:00
parent 6e317bc75c
commit 7e690f4e68
2 changed files with 23 additions and 8 deletions

View file

@ -95,13 +95,11 @@ class AuthorizeEndpoint(object):
if self.grant_type == 'authorization_code': if self.grant_type == 'authorization_code':
code = Code() code = create_code(
code.user = self.request.user user=self.request.user,
code.client = self.client client=self.client,
code.code = uuid.uuid4().hex scope=self.params.scope)
code.expires_at = timezone.now() + timedelta(
seconds=settings.get('OIDC_CODE_EXPIRE'))
code.scope = self.params.scope
code.save() code.save()
# Create the response uri. # Create the response uri.

View file

@ -68,3 +68,20 @@ def create_token(user, client, id_token_dic, scope):
token.scope = scope token.scope = scope
return token return token
def create_code(user, client, scope):
"""
Create and populate a Code object.
Return a Code object.
"""
code = Code()
code.user = user
code.client = client
code.code = uuid.uuid4().hex
code.expires_at = timezone.now() + timedelta(
seconds=settings.get('OIDC_CODE_EXPIRE'))
code.scope = scope
return code