aboutsummaryrefslogtreecommitdiff
path: root/gn3/auth/authentication/oauth2/views.py
diff options
context:
space:
mode:
authorFrederick Muriuki Muriithi2022-12-19 16:02:19 +0300
committerFrederick Muriuki Muriithi2022-12-22 09:05:53 +0300
commitb0641272491eb51d321b1b8a7d062e395e70800f (patch)
treec9b2065ea60399579c4c4d84c648b61ed67402ba /gn3/auth/authentication/oauth2/views.py
parente9031e28594fcd21371adb2b9b26e17a1df95599 (diff)
downloadgenenetwork3-b0641272491eb51d321b1b8a7d062e395e70800f.tar.gz
auth: implement OAuth2 flow.oauth2_auth_flow
Add code to implement the OAuth2 flow. * Add test fixtures for setting up users and OAuth2 clients * Add tests for token generation with the "Password Grant" flow * Fix some issues with test due to changes in the database connection's row_factory
Diffstat (limited to 'gn3/auth/authentication/oauth2/views.py')
-rw-r--r--gn3/auth/authentication/oauth2/views.py42
1 files changed, 42 insertions, 0 deletions
diff --git a/gn3/auth/authentication/oauth2/views.py b/gn3/auth/authentication/oauth2/views.py
new file mode 100644
index 0000000..58fa6d4
--- /dev/null
+++ b/gn3/auth/authentication/oauth2/views.py
@@ -0,0 +1,42 @@
+"""Endpoints for the oauth2 server"""
+import uuid
+
+from flask import Blueprint, current_app as app
+
+from .endpoints.revocation import RevocationEndpoint
+from .endpoints.introspection import IntrospectionEndpoint
+
+oauth2 = Blueprint("oauth2", __name__)
+
+@oauth2.route("/register-client", methods=["GET", "POST"])
+def register_client():
+ """Register an OAuth2 client."""
+ return "WOULD REGISTER ..."
+
+@oauth2.route("/delete-client/<uuid:client_id>", methods=["GET", "POST"])
+def delete_client(client_id: uuid.UUID):
+ """Delete an OAuth2 client."""
+ return f"WOULD DELETE OAUTH2 CLIENT {client_id}."
+
+@oauth2.route("/authorise", methods=["GET", "POST"])
+def authorise():
+ """Authorise a user"""
+ return "WOULD AUTHORISE THE USER."
+
+@oauth2.route("/token", methods=["POST"])
+def token():
+ """Retrieve the authorisation token."""
+ server = app.config["OAUTH2_SERVER"]
+ return server.create_token_response()
+
+@oauth2.route("/revoke", methods=["POST"])
+def revoke_token():
+ """Revoke the token."""
+ return app.config["OAUTH2_SERVER"].create_endpoint_response(
+ RevocationEndpoint.ENDPOINT_NAME)
+
+@oauth2.route("/introspect", methods=["POST"])
+def introspect_token():
+ """Provide introspection information for the token."""
+ return app.config["OAUTH2_SERVER"].create_endpoint_response(
+ IntrospectionEndpoint.ENDPOINT_NAME)