-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathclerk.py
More file actions
33 lines (26 loc) · 1.07 KB
/
clerk.py
File metadata and controls
33 lines (26 loc) · 1.07 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# import os
# import jwt
# from jwt import PyJWKClient
# from flask import request, jsonify
# CLERK_JWKS_URL = os.getenv("CLERK_JWKS_URL")
# def verify_user_token():
# auth_header = request.headers.get("Authorization")
# if not auth_header or not auth_header.startswith("Bearer "):
# return None, jsonify({"error": "Missing or invalid Authorization header"}), 401
# token = auth_header.split(" ")[1]
# # print("clerk token: ", token)
# try:
# jwks_client = PyJWKClient(CLERK_JWKS_URL)
# signing_key = jwks_client.get_signing_key_from_jwt(token).key
# payload = jwt.decode(
# token,
# signing_key,
# algorithms=["RS256"],
# audience=os.getenv("CLERK_FRONTEND_API"),
# )
# clerk_id = payload.get("sub")
# email = payload.get("email", "unknown@example.com")
# return {"clerk_id": clerk_id, "email": email}, None, None
# except Exception as e:
# print("Token verification failed: ", e)
# return None, jsonify({"error": "Unauthorized"}), 401