Skip to content

Commit

Permalink
Merge pull request quarkusio#33442 from sberyozkin/oidc_spotify
Browse files Browse the repository at this point in the history
Update OIDC Spotify properties
  • Loading branch information
sberyozkin committed May 30, 2023
2 parents c042b4d + 18b8012 commit 51c7d6d
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ public class OidcDevConsoleProcessor extends AbstractDevConsoleProcessor {

private static final String KEYCLOAK = "Keycloak";
private static final String AZURE = "Azure";
private static final Set<String> OTHER_PROVIDERS = Set.of("Auth0", "Okta", "Google", "Github");
private static final Set<String> OTHER_PROVIDERS = Set.of("Auth0", "Okta", "Google", "Github", "Spotify");

OidcBuildTimeConfig oidcConfig;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ public class UserInfo extends AbstractJsonObjectResponse {
private static final String NAME = "name";
private static final String FIRST_NAME = "first_name";
private static final String FAMILY_NAME = "family_name";
private static final String DISPLAY_NAME = "display_name";

public UserInfo() {
}
Expand Down Expand Up @@ -40,6 +41,10 @@ public String getFamilyName() {
return getString(FAMILY_NAME);
}

public String getDisplayName() {
return getString(DISPLAY_NAME);
}

public String getPreferredUserName() {
return getString(Claims.preferred_username.name());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -118,11 +118,13 @@ private static OidcTenantConfig spotify() {

OidcTenantConfig.Authentication authentication = ret.getAuthentication();
authentication.setAddOpenidScope(false);
authentication.setScopes(List.of("user-read-email"));
authentication.setUserInfoRequired(true);
authentication.setScopes(List.of("user-read-private", "user-read-email"));
authentication.setIdTokenRequired(false);
authentication.setPkceRequired(true);

ret.getToken().setVerifyAccessTokenWithUserInfo(true);
ret.getToken().setPrincipalClaim("display_name");

return ret;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -315,7 +315,9 @@ public void testAcceptSpotifyProperties() {
assertEquals(OidcUtils.DEFAULT_TENANT_ID, config.getTenantId().get());
assertEquals(ApplicationType.WEB_APP, config.getApplicationType().get());
assertEquals("https://accounts.spotify.com", config.getAuthServerUrl().get());
assertEquals(List.of("user-read-email"), config.authentication.scopes.get());
assertEquals(List.of("user-read-private", "user-read-email"), config.authentication.scopes.get());
assertTrue(config.token.verifyAccessTokenWithUserInfo.get());
assertEquals("display_name", config.getToken().getPrincipalClaim().get());
}

@Test
Expand All @@ -328,6 +330,8 @@ public void testOverrideSpotifyProperties() {
tenant.getToken().setIssuer("http://localhost/wiremock");
tenant.authentication.setScopes(List.of("write"));
tenant.authentication.setForceRedirectHttpsScheme(false);
tenant.token.setPrincipalClaim("firstname");
tenant.token.setVerifyAccessTokenWithUserInfo(false);

OidcTenantConfig config = OidcUtils.mergeTenantConfig(tenant, KnownOidcProviders.provider(Provider.SPOTIFY));

Expand All @@ -337,6 +341,8 @@ public void testOverrideSpotifyProperties() {
assertEquals(List.of("write"), config.authentication.scopes.get());
assertEquals("http://localhost/wiremock", config.getToken().getIssuer().get());
assertFalse(config.authentication.forceRedirectHttpsScheme.get());
assertEquals("firstname", config.getToken().getPrincipalClaim().get());
assertFalse(config.token.verifyAccessTokenWithUserInfo.get());
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,9 @@ public class UserInfoTest {
+ "\"sub\": \"alice123456\","
+ "\"name\": \"alice\","
+ "\"first_name\": \"Alice\","
+ "\"family_name\": \"Alice\","
+ "\"family_name\": \"Brown\","
+ "\"preferred_username\": \"Alice Alice\","
+ "\"display_name\": \"Alice Brown\","
+ "\"email\": \"alice@email.com\","
+ "\"admin\": true,"
+ "\"custom\": null,"
Expand All @@ -40,14 +41,19 @@ public void testGetFirstName() {

@Test
public void testGetFamilyName() {
assertEquals("Alice", userInfo.getFamilyName());
assertEquals("Brown", userInfo.getFamilyName());
}

@Test
public void testPreferredName() {
assertEquals("Alice Alice", userInfo.getPreferredUserName());
}

@Test
public void testDisplayName() {
assertEquals("Alice Brown", userInfo.getDisplayName());
}

@Test
public void testGetEmail() {
assertEquals("alice@email.com", userInfo.getEmail());
Expand Down

0 comments on commit 51c7d6d

Please sign in to comment.