-
Notifications
You must be signed in to change notification settings - Fork 6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Request user info when AS returns no scopes
Closes gh-12144
- Loading branch information
Showing
3 changed files
with
34 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -458,14 +458,36 @@ public void loadUserWhenTokenContainsScopesThenIndividualScopeAuthorities() { | |
@Test | ||
public void loadUserWhenTokenDoesNotContainScopesThenNoScopeAuthorities() { | ||
OidcUserService userService = new OidcUserService(); | ||
OidcUserRequest request = new OidcUserRequest(TestClientRegistrations.clientRegistration().build(), | ||
TestOAuth2AccessTokens.noScopes(), TestOidcIdTokens.idToken().build()); | ||
OidcUserRequest request = new OidcUserRequest(this.clientRegistrationBuilder.build(), | ||
TestOAuth2AccessTokens.noScopes(), this.idToken); | ||
OidcUser user = userService.loadUser(request); | ||
assertThat(user.getAuthorities()).hasSize(1); | ||
Iterator<? extends GrantedAuthority> authorities = user.getAuthorities().iterator(); | ||
assertThat(authorities.next()).isInstanceOf(OidcUserAuthority.class); | ||
} | ||
|
||
@Test | ||
public void loadUserWhenTokenDoesNotContainScopesAndUserInfoUriThenUserInfoRequested() { | ||
// @formatter:off | ||
String userInfoResponse = "{\n" | ||
+ " \"sub\": \"subject1\",\n" | ||
+ " \"name\": \"first last\",\n" | ||
+ " \"given_name\": \"first\",\n" | ||
+ " \"family_name\": \"last\",\n" | ||
+ " \"preferred_username\": \"user1\",\n" | ||
+ " \"email\": \"[email protected]\"\n" | ||
+ "}\n"; | ||
// @formatter:on | ||
this.server.enqueue(jsonResponse(userInfoResponse)); | ||
String userInfoUri = this.server.url("/user").toString(); | ||
ClientRegistration clientRegistration = this.clientRegistrationBuilder.userInfoUri(userInfoUri).build(); | ||
OidcUserService userService = new OidcUserService(); | ||
OidcUserRequest request = new OidcUserRequest(clientRegistration, TestOAuth2AccessTokens.noScopes(), | ||
this.idToken); | ||
OidcUser user = userService.loadUser(request); | ||
assertThat(user.getUserInfo()).isNotNull(); | ||
} | ||
|
||
private MockResponse jsonResponse(String json) { | ||
// @formatter:off | ||
return new MockResponse() | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters