diff get_agent.py @ 39:c538dc39b851

user login fixes
author drewp@bigasterisk.com
date Sat, 19 Nov 2022 17:06:36 -0800
parents
children 293a694304b8
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/get_agent.py	Sat Nov 19 17:06:36 2022 -0800
@@ -0,0 +1,25 @@
+import logging
+
+import bottle
+import jwt
+from rdflib import URIRef
+
+log = logging.getLogger(__name__)
+
+jwks_client = jwt.PyJWKClient(uri='https://authenticate.bigasterisk.com/.well-known/pomerium/jwks.json')
+
+
+def bottleGetAgent() -> URIRef:
+    pomAssertion = bottle.request.headers.get('X-Pomerium-Jwt-Assertion', None)
+
+    sk = jwks_client.get_signing_key_from_jwt(pomAssertion)
+    j = jwt.decode(pomAssertion,
+                   key=sk.key,
+                   algorithms=['ES256'],
+                   audience="bigasterisk.com")
+
+    foaf = {
+        'drewpca@gmail.com': 'http://bigasterisk.com/foaf.rdf#drewp',
+        'kelsimp@gmail.com': 'http://bigasterisk.com/kelsi/foaf.rdf#kelsi',
+    }[j['email']]
+    return URIRef(foaf)