@@ -10,6 +10,8 @@ public class OidcAuthority extends Authority {
1010 //Part of the OpenIdConnect standard, this is appended to the authority to create the endpoint that has OIDC metadata
1111 static final String WELL_KNOWN_OPENID_CONFIGURATION = ".well-known/openid-configuration" ;
1212 private static final String AUTHORITY_FORMAT = "https://%s/%s/" ;
13+ private static final String CIAM_AUTHORITY_FORMAT = "https://%s.ciamlogin.com/%s" ;
14+
1315 String issuerFromOidcDiscovery ;
1416
1517 OidcAuthority (URL authorityUrl ) throws MalformedURLException {
@@ -45,32 +47,25 @@ boolean isIssuerValid() {
4547 return false ;
4648 }
4749
48- // Normalize issuer by removing trailing slashes
49- String normalizedIssuer = issuerFromOidcDiscovery ;
50- while (normalizedIssuer .endsWith ("/" )) {
51- normalizedIssuer = normalizedIssuer .substring (0 , normalizedIssuer .length () - 1 );
52- }
53-
5450 // Case 1: Check against canonicalAuthorityUrl without the well-known segment
5551 String authorityWithoutWellKnown = canonicalAuthorityUrl .toString ();
5652 if (authorityWithoutWellKnown .endsWith (WELL_KNOWN_OPENID_CONFIGURATION )) {
5753 authorityWithoutWellKnown = authorityWithoutWellKnown .substring (0 ,
5854 authorityWithoutWellKnown .length () - WELL_KNOWN_OPENID_CONFIGURATION .length ());
5955
60- // Remove trailing slash if present
61- if (authorityWithoutWellKnown .endsWith ("/" )) {
62- authorityWithoutWellKnown = authorityWithoutWellKnown .substring (0 , authorityWithoutWellKnown .length () - 1 );
63- }
56+ // Normalize both URLs to ensure consistent comparison
57+ String normalizedAuthority = Authority .enforceTrailingSlash (authorityWithoutWellKnown );
58+ String normalizedIssuer = Authority .enforceTrailingSlash (issuerFromOidcDiscovery );
6459
65- if (normalizedIssuer .equals (authorityWithoutWellKnown )) {
60+ if (normalizedIssuer .equals (normalizedAuthority )) {
6661 return true ;
6762 }
6863 }
6964
70- // Case 2: Check CIAM format: "https://{tenant}.ciamlogin.com/{tenant}/ "
71- if (tenant != null && ! tenant . isEmpty ( )) {
72- String ciamPattern = "https://" + tenant + ".ciamlogin.com/" + tenant ;
73- return normalizedIssuer .startsWith (ciamPattern );
65+ // Case 2: Check CIAM format: "https://{tenant}.ciamlogin.com/{tenant}"
66+ if (! StringHelper . isNullOrBlank ( tenant )) {
67+ String ciamPattern = String . format ( CIAM_AUTHORITY_FORMAT , tenant , tenant ) ;
68+ return issuerFromOidcDiscovery .startsWith (ciamPattern );
7469 }
7570
7671 return false ;
0 commit comments