Skip to content

Commit

Permalink
Preferred_username is part of rest_users.get and rest_current-user.g…
Browse files Browse the repository at this point in the history
…et response as screen_name. Closes #178
  • Loading branch information
index-git committed Dec 7, 2020
1 parent 4d39645 commit da814db
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 6 deletions.
1 change: 1 addition & 0 deletions doc/rest.md
Original file line number Diff line number Diff line change
Expand Up @@ -576,6 +576,7 @@ Content-Type: `application/json`

JSON array of objects representing users of Layman with following structure:
- **username**: String. Username of the user.
- **screen_name**: String. Screen name of the user.
- **given_name**: String. Given name of the user.
- **family_name**: String. Family name of the user
- **middle_name**: String. Middle name of the user
Expand Down
13 changes: 7 additions & 6 deletions src/layman/authn/oauth2_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -242,7 +242,7 @@ def test_authn_get_current_user_without_username(client):
claims = resp_json['claims']
assert {
'email', 'email_verified', 'family_name', 'given_name', 'iss', 'middle_name', 'name',
'preferred_username', 'sub', 'updated_at'
'preferred_username', 'sub', 'updated_at', 'screen_name'
} == set(claims.keys())
assert claims['email'] == 'test@liferay.com'
assert claims['email_verified'] is True
Expand All @@ -251,6 +251,7 @@ def test_authn_get_current_user_without_username(client):
assert claims['middle_name'] == ''
assert claims['name'] == 'Test Test'
assert claims['preferred_username'] == 'test'
assert claims['screen_name'] == 'test'
assert claims['sub'] == '20139'


Expand All @@ -260,14 +261,14 @@ def test_get_current_user_anonymous(client):
rv = client.get(rest_path)
assert rv.status_code == 200
resp_json = rv.get_json()
assert resp_json['authenticated'] is False
assert {'authenticated', 'claims'} == set(resp_json.keys())
assert resp_json['authenticated'] is False, resp_json
assert {'authenticated', 'claims'} == set(resp_json.keys()), resp_json
claims = resp_json['claims']
assert {
'iss', 'name', 'nickname'
} == set(claims.keys())
assert claims['name'] == 'Anonymous'
assert claims['nickname'] == 'Anonymous'
} == set(claims.keys()), claims
assert claims['name'] == 'Anonymous', claims
assert claims['nickname'] == 'Anonymous', claims


@pytest.mark.usefixtures('app_context')
Expand Down
1 change: 1 addition & 0 deletions src/layman/user/rest_users.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ def get():
infos = [
{
"username": username,
"screen_name": info.get("preferred_username"),
"given_name": info.get("given_name"),
"family_name": info.get("family_name"),
"middle_name": info.get("middle_name"),
Expand Down
2 changes: 2 additions & 0 deletions src/layman/user/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ def get_user_profile(user_obj):
result = {k: v for k, v in result.items() if v is not None}
claims = get_open_id_claims().copy()
result['claims'] = claims
if result['claims'].get('preferred_username'):
result['claims']['screen_name'] = result['claims']['preferred_username']
return result


Expand Down

0 comments on commit da814db

Please sign in to comment.