aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMunyoki Kilyungi2024-03-06 13:28:54 +0300
committerMunyoki Kilyungi2024-03-08 15:03:52 +0300
commitfb015a2c4a6b176030e29bdc299c5213200dcf29 (patch)
tree6b23e199c902230bc98a49eb04f5a8745f33455e
parent4dd67293c9bb515514bb905ad8a965caf021aac2 (diff)
downloadgn-auth-fb015a2c4a6b176030e29bdc299c5213200dcf29.tar.gz
Explicitly add keyword arguments to AuthorisationCode.
This improves readability. * gn_auth/auth/authentication/oauth2/grants/authorisation_code_grant.py (AuthorisationCodeGrant.save_authorization_code): Use keyword arguments. * gn_auth/auth/authentication/oauth2/models/authorization_code.py (authorisation_code): Ditto. Signed-off-by: Munyoki Kilyungi <me@bonfacemunyoki.com>
-rw-r--r--gn_auth/auth/authentication/oauth2/grants/authorisation_code_grant.py20
-rw-r--r--gn_auth/auth/authentication/oauth2/models/authorization_code.py15
2 files changed, 25 insertions, 10 deletions
diff --git a/gn_auth/auth/authentication/oauth2/grants/authorisation_code_grant.py b/gn_auth/auth/authentication/oauth2/grants/authorisation_code_grant.py
index e866c41..98c36ee 100644
--- a/gn_auth/auth/authentication/oauth2/grants/authorisation_code_grant.py
+++ b/gn_auth/auth/authentication/oauth2/grants/authorisation_code_grant.py
@@ -31,11 +31,21 @@ class AuthorisationCodeGrant(grants.AuthorizationCodeGrant):
client = request.client
nonce = "".join(random.sample(string.ascii_letters + string.digits,
k=self.AUTHORIZATION_CODE_LENGTH))
- return __save_authorization_code__(AuthorisationCode(
- uuid.uuid4(), code, client, request.redirect_uri, request.scope,
- nonce, int(datetime.now().timestamp()),
- create_s256_code_challenge(app.config["SECRET_KEY"]),
- "S256", request.user))
+ return __save_authorization_code__(
+ AuthorisationCode(
+ code_id=uuid.uuid4(),
+ code=code,
+ client=client,
+ redirect_uri=request.redirect_uri,
+ scope=request.scope,
+ nonce=nonce,
+ auth_time=int(datetime.now().timestamp()),
+ code_challenge=create_s256_code_challenge(
+ app.config["SECRET_KEY"]
+ ),
+ code_challenge_method="S256",
+ user=request.user)
+ )
def query_authorization_code(self, code, client):
"""Retrieve the code from the database."""
diff --git a/gn_auth/auth/authentication/oauth2/models/authorization_code.py b/gn_auth/auth/authentication/oauth2/models/authorization_code.py
index 6c586f3..55299cd 100644
--- a/gn_auth/auth/authentication/oauth2/models/authorization_code.py
+++ b/gn_auth/auth/authentication/oauth2/models/authorization_code.py
@@ -68,11 +68,16 @@ def authorisation_code(conn: db.DbConnection ,
result = cursor.fetchone()
if result:
return Just(AuthorisationCode(
- UUID(result["code_id"]), result["code"], client,
- result["redirect_uri"], result["scope"], result["nonce"],
- int(result["auth_time"]), result["code_challenge"],
- result["code_challenge_method"],
- user_by_id(conn, UUID(result["user_id"]))))
+ code_id=UUID(result["code_id"]),
+ code=result["code"],
+ client=client,
+ redirect_uri=result["redirect_uri"],
+ scope=result["scope"],
+ nonce=result["nonce"],
+ auth_time=int(result["auth_time"]),
+ code_challenge=result["code_challenge"],
+ code_challenge_method=result["code_challenge_method"],
+ user=user_by_id(conn, UUID(result["user_id"]))))
return Nothing
def save_authorisation_code(conn: db.DbConnection,