aboutsummaryrefslogtreecommitdiff
path: root/gn3/auth/authentication/oauth2/server.py
diff options
context:
space:
mode:
authorFrederick Muriuki Muriithi2023-05-27 13:50:51 +0300
committerFrederick Muriuki Muriithi2023-05-27 13:50:51 +0300
commit45a7a6bc59eb28cdd2ceeee0e84506cf292b6466 (patch)
treebe2ae04bdd0dc095f873c788e434c1338ee1dda4 /gn3/auth/authentication/oauth2/server.py
parentd03ca8f2cb25dceb785044f31d6ad4a6914c6f16 (diff)
downloadgenenetwork3-45a7a6bc59eb28cdd2ceeee0e84506cf292b6466.tar.gz
Document Use of OAuth2 Clients
* docs/authentication_and_authorisation/oauth2_clients.md: New documentation * gn3/auth/authentication/oauth2/server.py: Raise appropriate error if no client is found. * gn3/auth/authentication/oauth2/views.py: Handle exception in the case where a UI should be presented to the user, rather than presenting the raw JSON response to the user. * gn3/errors.py: Handle any authlib OAuth2Error at the application's top-level * gn3/templates/oauth2/oauth2_error.html: Handle any authlib OAuth2Error at the application's top-level
Diffstat (limited to 'gn3/auth/authentication/oauth2/server.py')
-rw-r--r--gn3/auth/authentication/oauth2/server.py8
1 files changed, 7 insertions, 1 deletions
diff --git a/gn3/auth/authentication/oauth2/server.py b/gn3/auth/authentication/oauth2/server.py
index e9946b4..7d7113a 100644
--- a/gn3/auth/authentication/oauth2/server.py
+++ b/gn3/auth/authentication/oauth2/server.py
@@ -4,6 +4,7 @@ import datetime
from typing import Callable
from flask import Flask, current_app
+from authlib.oauth2.rfc6749.errors import InvalidClientError
from authlib.integrations.flask_oauth2 import AuthorizationServer
# from authlib.oauth2.rfc7636 import CodeChallenge
@@ -24,7 +25,12 @@ def create_query_client_func() -> Callable:
# use current_app rather than passing the db_uri to avoid issues
# when config changes, e.g. while testing.
with db.connection(current_app.config["AUTH_DB"]) as conn:
- return client(conn, client_id).maybe(None, lambda clt: clt) # type: ignore[misc]
+ the_client = client(conn, client_id).maybe(
+ None, lambda clt: clt) # type: ignore[misc]
+ if bool(the_client):
+ return the_client
+ raise InvalidClientError(
+ "No client found for the given CLIENT_ID and CLIENT_SECRET.")
return __query_client__