comparison get_agent.py @ 2:76cec592435c

special getFoafAgent version
author drewp@bigasterisk.com
date Sun, 27 Aug 2023 13:17:50 -0700
parents 4365c72c59f6
children 6e0d47f9e56d
comparison
equal deleted inserted replaced
1:3b82ee3b9d79 2:76cec592435c
9 from rdflib import URIRef 9 from rdflib import URIRef
10 from starlette.requests import Request 10 from starlette.requests import Request
11 11
12 log = logging.getLogger(__name__) 12 log = logging.getLogger(__name__)
13 tzlocal = datetime.datetime.now().astimezone().tzinfo 13 tzlocal = datetime.datetime.now().astimezone().tzinfo
14
14 15
15 @dataclass 16 @dataclass
16 class Agent: 17 class Agent:
17 email: str 18 email: str
18 agent: URIRef 19 agent: URIRef
83 agent=foafAgentFromAuthEmail(claims['email']), 84 agent=foafAgentFromAuthEmail(claims['email']),
84 expiration=datetime.datetime.fromtimestamp(claims['exp']).astimezone(tzlocal), 85 expiration=datetime.datetime.fromtimestamp(claims['exp']).astimezone(tzlocal),
85 issuedAt=datetime.datetime.fromtimestamp(claims['iat']).astimezone(tzlocal), 86 issuedAt=datetime.datetime.fromtimestamp(claims['iat']).astimezone(tzlocal),
86 name=claims['name'], 87 name=claims['name'],
87 ) 88 )
89
90
91 async def getFoafAgent(req) -> URIRef | None:
92 """this is special because fingerprint needs to be able to send
93 x-foaf-agent AND we need to get agents the normal way from pomerium"""
94
95 if 'X-Pomerium-Jwt-Assertion' in req.headers:
96 agent = await getAgent(req)
97 if agent:
98 return agent.agent
99 else:
100 if 'x-foaf-agent' in req.headers:
101 # we can trust fingerprint-unlocker to give us a x-foaf-agent derived from the fingerprint
102 return URIRef(req.headers['x-foaf-agent'])
103
104 return None