@@ -10,6 +10,7 @@ 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+ String issuerFromOidcDiscovery ;
1314
1415 OidcAuthority (URL authorityUrl ) throws MalformedURLException {
1516 super (createOidcDiscoveryUrl (authorityUrl ), AuthorityType .OIDC );
@@ -29,5 +30,49 @@ void setAuthorityProperties(OidcDiscoveryResponse instanceDiscoveryResponse) {
2930 this .tokenEndpoint = instanceDiscoveryResponse .tokenEndpoint ();
3031 this .deviceCodeEndpoint = instanceDiscoveryResponse .deviceCodeEndpoint ();
3132 this .selfSignedJwtAudience = this .tokenEndpoint ;
33+ this .issuerFromOidcDiscovery = instanceDiscoveryResponse .issuer ();
34+ }
35+
36+ /**
37+ * Validates the issuer from OIDC discovery.
38+ * Issuer is valid if it matches the authority URL (without the well-known segment)
39+ * or if it follows the CIAM issuer format.
40+ *
41+ * @return true if the issuer is valid, false otherwise
42+ */
43+ boolean isIssuerValid () {
44+ if (issuerFromOidcDiscovery == null ) {
45+ return false ;
46+ }
47+
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+
54+ // Case 1: Check against canonicalAuthorityUrl without the well-known segment
55+ String authorityWithoutWellKnown = canonicalAuthorityUrl .toString ();
56+ if (authorityWithoutWellKnown .endsWith (WELL_KNOWN_OPENID_CONFIGURATION )) {
57+ authorityWithoutWellKnown = authorityWithoutWellKnown .substring (0 ,
58+ authorityWithoutWellKnown .length () - WELL_KNOWN_OPENID_CONFIGURATION .length ());
59+
60+ // Remove trailing slash if present
61+ if (authorityWithoutWellKnown .endsWith ("/" )) {
62+ authorityWithoutWellKnown = authorityWithoutWellKnown .substring (0 , authorityWithoutWellKnown .length () - 1 );
63+ }
64+
65+ if (normalizedIssuer .equals (authorityWithoutWellKnown )) {
66+ return true ;
67+ }
68+ }
69+
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 );
74+ }
75+
76+ return false ;
3277 }
3378}
0 commit comments