changeset 2:76cec592435c

special getFoafAgent version
author drewp@bigasterisk.com
date Sun, 27 Aug 2023 13:17:50 -0700
parents 3b82ee3b9d79
children 89d47e203fc2
files get_agent.py
diffstat 1 files changed, 17 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/get_agent.py	Sun Aug 27 11:20:30 2023 -0700
+++ b/get_agent.py	Sun Aug 27 13:17:50 2023 -0700
@@ -12,6 +12,7 @@
 log = logging.getLogger(__name__)
 tzlocal = datetime.datetime.now().astimezone().tzinfo
 
+
 @dataclass
 class Agent:
     email: str
@@ -85,3 +86,19 @@
         issuedAt=datetime.datetime.fromtimestamp(claims['iat']).astimezone(tzlocal),
         name=claims['name'],
     )
+
+
+async def getFoafAgent(req) -> URIRef | None:
+    """this is special because fingerprint needs to be able to send 
+    x-foaf-agent AND we need to get agents the normal way from pomerium"""
+
+    if 'X-Pomerium-Jwt-Assertion' in req.headers:
+        agent = await getAgent(req)
+        if agent:
+            return agent.agent
+    else:
+        if 'x-foaf-agent' in req.headers:
+            # we can trust fingerprint-unlocker to give us a x-foaf-agent derived from the fingerprint
+            return URIRef(req.headers['x-foaf-agent'])
+
+    return None