aboutsummaryrefslogtreecommitdiff
path: root/gn2/wqflask/oauth2/client.py
diff options
context:
space:
mode:
authorFrederick Muriuki Muriithi2024-08-05 17:19:34 -0500
committerAlexander_Kabui2024-08-28 15:02:46 +0300
commitc2c8d8298e3f10492cc26f76fe9d8e3053bcd4ef (patch)
tree36a811ce23d8eb44ab32bc62156db96aebc8dba3 /gn2/wqflask/oauth2/client.py
parentf142f53a388945e4dd85083d6c989c14a882f0ce (diff)
downloadgenenetwork2-c2c8d8298e3f10492cc26f76fe9d8e3053bcd4ef.tar.gz
Override 'client_secret_post' auth with a JSON equivalent
In order to use JSON consistently across the board, we make even the authentication method use JSON rather than FORMDATA.
Diffstat (limited to 'gn2/wqflask/oauth2/client.py')
-rw-r--r--gn2/wqflask/oauth2/client.py15
1 files changed, 14 insertions, 1 deletions
diff --git a/gn2/wqflask/oauth2/client.py b/gn2/wqflask/oauth2/client.py
index 6f137f52..89d8a57e 100644
--- a/gn2/wqflask/oauth2/client.py
+++ b/gn2/wqflask/oauth2/client.py
@@ -9,8 +9,9 @@ from datetime import datetime, timedelta
from flask import current_app as app
from pymonad.either import Left, Right, Either
-from authlib.jose import KeySet, JsonWebKey, JsonWebToken
+from authlib.common.urls import url_decode
from authlib.jose.errors import BadSignatureError
+from authlib.jose import KeySet, JsonWebKey, JsonWebToken
from authlib.integrations.requests_client import OAuth2Session
from gn2.wqflask.oauth2 import session
@@ -137,6 +138,16 @@ def oauth2_client():
return 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(),
@@ -146,6 +157,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__()