Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update OIDC Spotify properties #33442

Merged
merged 1 commit into from
May 30, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@ -117,11 +117,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 @@ -312,7 +312,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 @@ -325,6 +327,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 @@ -334,6 +338,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\": \"[email protected]\","
+ "\"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("[email protected]", userInfo.getEmail());
Expand Down