aboutsummaryrefslogtreecommitdiff
path: root/gn_auth
diff options
context:
space:
mode:
authorFrederick Muriuki Muriithi2024-04-20 16:48:45 +0300
committerFrederick Muriuki Muriithi2024-04-20 16:48:45 +0300
commit6671e9a32e00bb01a744d7b564193d54f454e2ce (patch)
treee79f2e96bab399ed82042874399a2d6ad132e542 /gn_auth
parentcfda9d6cd15763e65fa851d964033e37f377239c (diff)
downloadgn-auth-6671e9a32e00bb01a744d7b564193d54f454e2ce.tar.gz
Setup token validators at app initialisation.
Diffstat (limited to 'gn_auth')
-rw-r--r--gn_auth/auth/authentication/oauth2/resource_server.py2
-rw-r--r--gn_auth/auth/authentication/oauth2/server.py8
2 files changed, 8 insertions, 2 deletions
diff --git a/gn_auth/auth/authentication/oauth2/resource_server.py b/gn_auth/auth/authentication/oauth2/resource_server.py
index c062b28..2405ee2 100644
--- a/gn_auth/auth/authentication/oauth2/resource_server.py
+++ b/gn_auth/auth/authentication/oauth2/resource_server.py
@@ -15,5 +15,3 @@ class BearerTokenValidator(_BearerTokenValidator):
None, lambda tok: tok)
require_oauth = ResourceProtector()
-
-require_oauth.register_token_validator(BearerTokenValidator())
diff --git a/gn_auth/auth/authentication/oauth2/server.py b/gn_auth/auth/authentication/oauth2/server.py
index 09a3449..db2a0d5 100644
--- a/gn_auth/auth/authentication/oauth2/server.py
+++ b/gn_auth/auth/authentication/oauth2/server.py
@@ -4,6 +4,7 @@ import datetime
from typing import Callable
from flask import Flask, current_app
+from authlib.oauth2.rfc7523 import JWTBearerTokenValidator
from authlib.oauth2.rfc6749.errors import InvalidClientError
from authlib.integrations.flask_oauth2 import AuthorizationServer
@@ -19,6 +20,8 @@ from .grants.jwt_bearer_grant import JWTBearerGrant, JWTBearerTokenGenerator
from .endpoints.revocation import RevocationEndpoint
from .endpoints.introspection import IntrospectionEndpoint
+from .resource_server import require_oauth, BearerTokenValidator
+
def create_query_client_func() -> Callable:
"""Create the function that loads the client."""
def __query_client__(client_id: uuid.UUID):
@@ -75,3 +78,8 @@ def setup_oauth2_server(app: Flask) -> None:
query_client=create_query_client_func(),
save_token=create_save_token_func(OAuth2Token))
app.config["OAUTH2_SERVER"] = server
+
+ ## Set up the token validators
+ require_oauth.register_token_validator(BearerTokenValidator())
+ require_oauth.register_token_validator(
+ JWTBearerTokenValidator(app.config["JWT_PUBLIC_KEY"]))