Skip to content

Commit

Permalink
return userobject (#41)
Browse files Browse the repository at this point in the history
a new header X-Auth-User is returned that contains all the user information
  • Loading branch information
robkooper authored Jun 13, 2023
1 parent 2d50ee6 commit 671f901
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 8 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ From version 1.2.0 the file IP2LOCATION-LITE-DB5.BIN is no longer part of the do

## Added
- New user default usage to zero [#38](https://github.com/IN-CORE/incore-auth/issues/38)
- Return a user object that contains username, fullname, email, groups and roles.


# [1.6.0] - 2023-03-14
Expand Down
22 changes: 14 additions & 8 deletions incore_auth/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -282,9 +282,10 @@ def request_userinfo(request_info):
return

# get name of user
request_info["firstname"] = access_token["given_name"]
request_info["lastname"] = access_token["family_name"]
request_info["fullname"] = access_token["name"]
request_info["firstname"] = access_token.get("given_name", "")
request_info["lastname"] = access_token.get("family_name", "")
request_info["fullname"] = access_token.get("name", "")
request_info["email"] = access_token.get("email", "")

# retrieve the groups the user belongs to from access token
request_info['username'] = access_token["preferred_username"]
Expand Down Expand Up @@ -356,6 +357,7 @@ def verify_token():
"firstname": "",
"lastname": "",
"fullname": "",
"email": "",
"method": request.method,
"url": request.path,
"resource": "",
Expand Down Expand Up @@ -404,20 +406,24 @@ def verify_token():
# everything is ok
user_info = {"preferred_username": request_info['username']}
group_info = {"groups": request_info['groups']}
user_object = {
"username": request_info['username'],
"email": request_info['email'],
"fullname": request_info['fullname'],
"groups": request_info['groups'],
"roles": request_info['roles'],
}

response = Response(status=200)
response.headers['X-Auth-UserInfo'] = json.dumps(user_info)
response.headers['X-Auth-UserGroup'] = json.dumps(group_info)
response.headers['X-Auth-User'] = json.dumps(user_object)

if request.headers.get('Authorization') is not None:
response.headers['Authorization'] = unquote_plus(request.headers['Authorization'])
elif request.cookies.get('Authorization') is not None:
response.headers['Authorization'] = unquote_plus(request.cookies['Authorization'])

if request.headers.get('X-Auth-UserGroup') is not None:
response.headers['X-Auth-UserGroup'] = request.headers.get('X-Auth-UserGroup')
elif request.cookies.get('X-Auth-UserGroup') is not None:
response.headers['X-Auth-UserGroup'] = request.cookies['X-Auth-UserGroup']

return response


Expand Down

0 comments on commit 671f901

Please sign in to comment.