From 7e690f4e689cf1d1db5457be70ee78c5bee65297 Mon Sep 17 00:00:00 2001 From: juanifioren Date: Thu, 12 Mar 2015 12:40:36 -0300 Subject: [PATCH] Move Grant Code creation logic into a functon. --- oidc_provider/lib/endpoints/authorize.py | 12 +++++------- oidc_provider/lib/utils/token.py | 19 ++++++++++++++++++- 2 files changed, 23 insertions(+), 8 deletions(-) diff --git a/oidc_provider/lib/endpoints/authorize.py b/oidc_provider/lib/endpoints/authorize.py index 362dd56..d6682f5 100644 --- a/oidc_provider/lib/endpoints/authorize.py +++ b/oidc_provider/lib/endpoints/authorize.py @@ -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. diff --git a/oidc_provider/lib/utils/token.py b/oidc_provider/lib/utils/token.py index 0dcd019..74d04cb 100644 --- a/oidc_provider/lib/utils/token.py +++ b/oidc_provider/lib/utils/token.py @@ -67,4 +67,21 @@ def create_token(user, client, id_token_dic, scope): seconds=settings.get('OIDC_TOKEN_EXPIRE')) token.scope = scope - return token \ No newline at end of file + 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 \ No newline at end of file