diff options
author | Frederick Muriuki Muriithi | 2024-04-20 16:48:45 +0300 |
---|---|---|
committer | Frederick Muriuki Muriithi | 2024-04-20 16:48:45 +0300 |
commit | 6671e9a32e00bb01a744d7b564193d54f454e2ce (patch) | |
tree | e79f2e96bab399ed82042874399a2d6ad132e542 /gn_auth/auth/authentication/oauth2/server.py | |
parent | cfda9d6cd15763e65fa851d964033e37f377239c (diff) | |
download | gn-auth-6671e9a32e00bb01a744d7b564193d54f454e2ce.tar.gz |
Setup token validators at app initialisation.
Diffstat (limited to 'gn_auth/auth/authentication/oauth2/server.py')
-rw-r--r-- | gn_auth/auth/authentication/oauth2/server.py | 8 |
1 files changed, 8 insertions, 0 deletions
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"])) |