Skip to content

Commit d1e9e80

Browse files
End of userinfo changes
1 parent 8fcb309 commit d1e9e80

File tree

3 files changed

+24
-14
lines changed

3 files changed

+24
-14
lines changed

Dockerfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# image: tapis/authenticator
2-
FROM tapis/flaskbase:1.8.0
2+
FROM tapis/flaskbase:1.8.1
33

44
COPY requirements.txt /home/tapis/requirements.txt
55
RUN pip install -r /home/tapis/requirements.txt

service/auth.py

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -159,14 +159,6 @@ def authentication():
159159
# overwrite the headers via wsgi environ. request.headers itself is read-only
160160
tapis_token = auth_token.replace('Bearer ', '')
161161
logger.debug(f"found auth header; setting environ X-Tapis-Token to {tapis_token}")
162-
163-
# tokens might have aud, if jwt.decode in tapisservice doesn't specify expected aud you'll
164-
# get invalid aud. Either we can somehow pop aud or specify to jwt.decode(options={'verify_aud': False})
165-
# Instead of verify = false we can also specify a list of valid auds. Pop aud would require
166-
# re-encoding+sigining key. We don't have private tenant key in auth though. Ignoring for now, only
167-
# bookstack looks for this when running their auth.
168-
# resolve_tenant_id_for_request decode needs aud to expect - https://github.com/jpadilla/pyjwt/blob/master/docs/usage.rst#audience-claim-aud
169-
170162
# modify the WSGI environment directly
171163
# wsgi requires headers be uppercase, no dashes, and prefixed with HTTP_
172164
request.environ['HTTP_X_TAPIS_TOKEN'] = tapis_token
@@ -176,11 +168,19 @@ def authentication():
176168
# debug logs
177169
try:
178170
headers = request.headers
179-
logger.debug(f"before auth.authentication(). request.headers: {headers}")
171+
logger.debug(f"before auth.authentication(). request.headers: {headers.keys()}")
180172
except Exception as e:
181173
pass
182-
183-
auth.authentication()
174+
175+
# tokens might have aud, if jwt.decode in tapisservice doesn't specify expected aud you'll
176+
# get invalid aud. Either we can somehow pop aud or specify to jwt.decode(options={'verify_aud': False})
177+
# Instead of verify = false we can also specify a list of valid auds. Pop aud would require
178+
# re-encoding+signing key. We don't have private tenant key in auth though. Ignoring for now, only
179+
# bookstack looks for this when running their auth.
180+
# resolve_tenant_id_for_request decode needs aud to expect - https://github.com/jpadilla/pyjwt/blob/master/docs/usage.rst#audience-claim-aud
181+
# Edit, expected_aud now exists. Bookstack asks for aud == client_id. For now we'll just allow any aud, especially as this is one endpoint.
182+
183+
auth.authentication(expected_aud=["*"])
184184
# always resolve the request tenant id based on the URL:
185185
auth.resolve_tenant_id_for_request()
186186
# make sure this request is for a tenant served by this authenticator

service/controllers.py

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
from openapi_core import openapi_request_validator
1111
from openapi_core.contrib.flask import FlaskOpenAPIRequest
1212
from jwcrypto import jwk
13+
import jwt
1314
import sqlalchemy
1415
import secrets
1516
import random
@@ -212,7 +213,6 @@ def _handle_userinfo_request(request, oidc=False):
212213
# note that the user info endpoint is more limited for custom oauth idp extensions in general because the
213214
# custom OAuth server may not provide a profile endpoint.
214215
custom_oa2_extension_type = tenant_configs_cache.get_custom_oa2_extension_type(tenant_id=tenant_id)
215-
216216
## token should maybe already have:
217217
# jti iss sub exp tapis/tenant_id tapis/token_type
218218
# tapis/delegation tapis/delegation_sub tapis/username
@@ -240,7 +240,17 @@ def _handle_userinfo_request(request, oidc=False):
240240
data_rights = get_user_data_rights(username)
241241
if data_rights:
242242
userinfo["data_rights"] = " ".join(data_rights)
243-
return jsonify(userinfo.serialize)
243+
244+
# return token + userinfo as return for bookstack OIDC userinfo call.
245+
# bookstack at leasts needs sub claim.
246+
try:
247+
token_dict = jwt.decode(g.x_tapis_token, options={"verify_signature": False})
248+
newinfo = userinfo.serialize
249+
newinfo.update(token_dict)
250+
except Exception as e:
251+
logger.debug(f"Error creating userinfo+token object: {e}, token: {g.x_tapis_token}")
252+
raise errors.ResourceError("Error with token and userinfo objects.")
253+
return jsonify(newinfo)
244254

245255
return utils.ok(result=userinfo.serialize, msg="User profile retrieved successfully.")
246256

0 commit comments

Comments
 (0)