diff options
author | John Nduli | 2024-07-31 10:54:42 +0300 |
---|---|---|
committer | Frederick Muriuki Muriithi | 2024-08-02 15:45:48 -0500 |
commit | f540322213fc7949695283a82eb8513c4a8a7f3e (patch) | |
tree | dabe0249a2697cb59ff9ba9fd841e6916a7f92ad /gn_auth | |
parent | 13c14ade387e78e290267c055f24b035c9e2868c (diff) | |
download | gn-auth-f540322213fc7949695283a82eb8513c4a8a7f3e.tar.gz |
fix: use json to support parsing oauth2 requests
The local sign in request used by gn2 uses json. However, the default
parsing assumes form data, see:
- https://github.com/lepture/authlib/blob/v1.2.0/authlib/integrations/flask_oauth2/authorization_server.py#L72
- https://github.com/lepture/authlib/blob/v1.2.0/authlib/integrations/flask_helpers.py#L5
We create a custom Authorization server that defaults to `use_json=True`
when creating the oauth request object
Diffstat (limited to 'gn_auth')
-rw-r--r-- | gn_auth/auth/authentication/oauth2/server.py | 12 |
1 files changed, 11 insertions, 1 deletions
diff --git a/gn_auth/auth/authentication/oauth2/server.py b/gn_auth/auth/authentication/oauth2/server.py index 63cbf37..175b640 100644 --- a/gn_auth/auth/authentication/oauth2/server.py +++ b/gn_auth/auth/authentication/oauth2/server.py @@ -10,6 +10,8 @@ from flask import Flask, current_app from authlib.jose import jwt, KeySet, JsonWebKey from authlib.oauth2.rfc6749.errors import InvalidClientError from authlib.integrations.flask_oauth2 import AuthorizationServer +from authlib.oauth2.rfc6749 import OAuth2Request +from authlib.integrations.flask_helpers import create_oauth_request from gn_auth.auth.db import sqlite3 as db from gn_auth.auth.jwks import ( @@ -134,9 +136,17 @@ def make_jwt_token_generator(app): return __generator__ + +class JsonAuthorizationServer(AuthorizationServer): + + def create_oauth2_request(self, request): + res = create_oauth_request(request, OAuth2Request, True) + return res + + def setup_oauth2_server(app: Flask) -> None: """Set's up the oauth2 server for the flask application.""" - server = AuthorizationServer() + server = JsonAuthorizationServer() server.register_grant(PasswordGrant) # Figure out a common `code_verifier` for GN2 and GN3 and set |