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':
code = Code()
code.user = self.request.user
code.client = self.client
code.code = uuid.uuid4().hex
code.expires_at = timezone.now() + timedelta(
seconds=settings.get('OIDC_CODE_EXPIRE'))
code.scope = self.params.scope
code = create_code(
user=self.request.user,
client=self.client,
scope=self.params.scope)
code.save()
# Create the response uri.

View file

@ -67,4 +67,21 @@ def create_token(user, client, id_token_dic, scope):
seconds=settings.get('OIDC_TOKEN_EXPIRE'))
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