diff options
author | Frederick Muriuki Muriithi | 2024-08-06 10:34:23 -0500 |
---|---|---|
committer | Frederick Muriuki Muriithi | 2024-08-06 10:34:23 -0500 |
commit | e852490b41afc6b765be3a609a84f887a7b2df6c (patch) | |
tree | 2df7ae5154e2fd0a389a080491df5ebd4a3f3e9b | |
parent | e4cf16ebfc90dd668b203d6841b67dc599926811 (diff) | |
download | gn-uploader-e852490b41afc6b765be3a609a84f887a7b2df6c.tar.gz |
Override `client_secret_post`: use JSON
Override the `client_secret_post` auth method to use JSON rather than
FORMDATA in order to gain some consistency while communicating with
the auth server.
-rw-r--r-- | uploader/oauth2/client.py | 13 |
1 files changed, 13 insertions, 0 deletions
diff --git a/uploader/oauth2/client.py b/uploader/oauth2/client.py index 09e165a..6dde9cb 100644 --- a/uploader/oauth2/client.py +++ b/uploader/oauth2/client.py @@ -9,6 +9,7 @@ from flask import request, current_app as app from pymonad.either import Left, Right, Either from authlib.jose import jwt +from authlib.common.urls import url_decode from authlib.jose import KeySet, JsonWebKey from authlib.jose.errors import BadSignatureError from authlib.integrations.requests_client import OAuth2Session @@ -87,6 +88,16 @@ def oauth2_client(): """Update the token when refreshed.""" session.set_user_token(token) + def __json_auth__(client, method, uri, headers, body): + return ( + uri, + {**headers, "Content-Type": "application/json"}, + json.dumps({ + **dict(url_decode(body)), + "client_id": oauth2_clientid(), + "client_secret": oauth2_clientsecret() + })) + def __client__(token) -> OAuth2Session: client = OAuth2Session( oauth2_clientid(), @@ -96,6 +107,8 @@ def oauth2_client(): token_endpoint_auth_method="client_secret_post", token=token, update_token=__update_token__) + client.register_client_auth_method( + ("client_secret_post", __json_auth__)) return client __update_auth_server_jwks__(session.session_info()) |