Skip to content

Commit

Permalink
Merge pull request quarkusio#44906 from sberyozkin/oidc_config_mappin…
Browse files Browse the repository at this point in the history
…g_updates

Update OidcTenantConfigBuilder shortcuts
  • Loading branch information
gastaldi authored Dec 18, 2024
2 parents 9943ebd + eecda81 commit 7984bf3
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -466,20 +466,11 @@ public OidcTenantConfigBuilder token(Token token) {
}

/**
* @param verifyAccessTokenWithUserInfo {@link Token#verifyAccessTokenWithUserInfo()}
* @param principalClaim {@link Token#principalClaim()}
* @return this builder
*/
public OidcTenantConfigBuilder token(boolean verifyAccessTokenWithUserInfo, String principalClaim) {
return token().verifyAccessTokenWithUserInfo(verifyAccessTokenWithUserInfo).principalClaim(principalClaim).end();
}

/**
* @param verifyAccessTokenWithUserInfo {@link Token#verifyAccessTokenWithUserInfo()}
* @return this builder
*/
public OidcTenantConfigBuilder token(boolean verifyAccessTokenWithUserInfo) {
return token().verifyAccessTokenWithUserInfo(verifyAccessTokenWithUserInfo).end();
public OidcTenantConfigBuilder token(String principalClaim) {
return token().principalClaim(principalClaim).end();
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ private static OidcTenantConfig slack() {
return OidcTenantConfig
.authServerUrl("https://slack.com")
.applicationType(WEB_APP)
.token().principalClaim("name").end()
.token("name")
.authentication()
.forceRedirectHttpsScheme()
.scopes("profile", "email")
Expand Down Expand Up @@ -64,7 +64,7 @@ private static OidcTenantConfig github() {
.authorizationPath("authorize")
.tokenPath("access_token")
.userInfoPath("https://api.github.com/user")
.token(true, "name")
.token().verifyAccessTokenWithUserInfo(true).principalClaim("name").end()
.authentication(authBuilder.build())
.build();
}
Expand Down Expand Up @@ -93,7 +93,7 @@ private static OidcTenantConfig google() {
.authServerUrl("https://accounts.google.com")
.applicationType(WEB_APP)
.authentication().scopes("openid", "email", "profile").end()
.token(true, "name")
.token().verifyAccessTokenWithUserInfo(true).principalClaim("name").end()
.build();
}

Expand Down Expand Up @@ -171,7 +171,7 @@ private static OidcTenantConfig spotify() {
.authorizationPath("authorize")
.tokenPath("api/token")
.userInfoPath("https://api.spotify.com/v1/me")
.token(true, "display_name")
.token().verifyAccessTokenWithUserInfo(true).principalClaim("display_name").end()
.authentication(authentication)
.build();
}
Expand All @@ -183,7 +183,7 @@ private static OidcTenantConfig strava() {
.discoveryEnabled(false)
.authorizationPath("authorize")
.tokenPath("token")
.token(true)
.token().verifyAccessTokenWithUserInfo(true).end()
.userInfoPath("https://www.strava.com/api/v3/athlete");

builder.authentication()
Expand Down Expand Up @@ -218,7 +218,7 @@ private static OidcTenantConfig discord() {
.authorizationPath("authorize")
.tokenPath("token")
.jwksPath("keys")
.token(true)
.token().verifyAccessTokenWithUserInfo(true).end()
.authentication().scopes("identify", "email").idTokenRequired(false).end()
.userInfoPath("https://discord.com/api/users/@me")
.build();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1089,7 +1089,7 @@ public void testTokenBuilder() {
.requiredClaims(Map.of("III", "IV"))
.audience("extra");
var config2 = second.end()
.token(false, "prince")
.token().verifyAccessTokenWithUserInfo(false).principalClaim("prince").end()
.build();
var builtSecond = config2.token();
assertFalse(builtSecond.verifyAccessTokenWithUserInfo().orElseThrow());
Expand All @@ -1107,7 +1107,7 @@ public void testTokenBuilder() {
assertTrue(builtSecond.audience().orElseThrow().contains("extra"));
assertEquals("prince", builtSecond.principalClaim().orElse(null));

var config3 = OidcTenantConfig.builder(config2).token(true).build();
var config3 = OidcTenantConfig.builder(config2).token().verifyAccessTokenWithUserInfo().end().build();
assertTrue(config3.token().verifyAccessTokenWithUserInfo().orElseThrow());

assertEquals("haha", config3.tenantId().orElse(null));
Expand Down

0 comments on commit 7984bf3

Please sign in to comment.