aboutsummaryrefslogtreecommitdiff
path: root/gn_auth
diff options
context:
space:
mode:
authorFrederick Muriuki Muriithi2024-09-26 11:28:03 -0500
committerFrederick Muriuki Muriithi2024-09-26 11:28:03 -0500
commit8e758d67de9f5047a33c7c9266ac058856edcfc7 (patch)
treebe958aaa54385cfe4387082baefccd469aa307c8 /gn_auth
parent446830c9b13d91f4dc04e7858e592ae2e5b8367d (diff)
downloadgn-auth-8e758d67de9f5047a33c7c9266ac058856edcfc7.tar.gz
Lint: Add documentation strings. Fix import order.
Diffstat (limited to 'gn_auth')
-rw-r--r--gn_auth/hooks.py11
1 files changed, 9 insertions, 2 deletions
diff --git a/gn_auth/hooks.py b/gn_auth/hooks.py
index a4240f4..bd7380b 100644
--- a/gn_auth/hooks.py
+++ b/gn_auth/hooks.py
@@ -1,14 +1,19 @@
+"""Authorisation hooks implementation"""
+import functools
from typing import List
+
from flask import request_finished
from flask import request, current_app
+
from gn_auth.auth.db import sqlite3 as db
-import functools
def register_hooks(app):
+ """Initialise hooks system on the application."""
request_finished.connect(edu_domain_hook, app)
def handle_register_request(func):
+ """Decorator for handling user registration hooks."""
@functools.wraps(func)
def wrapper(*args, **kwargs):
if request.method == "POST" and request.endpoint == "oauth2.users.register_user":
@@ -19,7 +24,8 @@ def handle_register_request(func):
@handle_register_request
-def edu_domain_hook(sender, response, **extra):
+def edu_domain_hook(_sender, response, **_extra):
+ """Hook to run whenever a user with a `.edu` domain registers."""
if response.status_code >= 400:
return
data = request.get_json()
@@ -30,6 +36,7 @@ def edu_domain_hook(sender, response, **extra):
def apply_edu_role(email):
+ """Assign 'hook-role-from-edu-domain' to user."""
with db.connection(current_app.config["AUTH_DB"]) as conn:
with db.cursor(conn) as cursor:
cursor.execute("SELECT user_id FROM users WHERE email= ?", (email,) )