Can't parse Azure OIDC Metadata: Unencoded { and } chars in URI

Issue #460 open
Romain Pelletier created an issue

By migrating from pac4hj-oauth 5.7 to 6.0.1 (use oauth2-oidcs-sdk 11.9.1), I get the following error when calling Azure OIDC Service, actually new URI() doesn't like characters such as “{ }”

Caused by: com.nimbusds.oauth2.sdk.ParseException: Illegal character in path at index 34: https://login.microsoftonline.com/{tenantid}/v2.0 
at com.nimbusds.oauth2.sdk.util.JSONObjectUtils.getURI(JSONObjectUtils.java:533) 
at com.nimbusds.oauth2.sdk.as.AuthorizationServerMetadata.parse(AuthorizationServerMetadata.java:1781) 
at com.nimbusds.openid.connect.sdk.op.OIDCProviderMetadata.parse(OIDCProviderMetadata.java:1302) 
at com.nimbusds.openid.connect.sdk.op.OIDCProviderMetadata.parse(OIDCProviderMetadata.java:1698)
 at org.pac4j.oidc.metadata.OidcOpMetadataResolver.retrieveMetadata(OidcOpMetadataResolver.java:98)
... 99 more 

Caused by: java.net.URISyntaxException: Illegal character in path at index 34: https://login.microsoftonline.com/{tenantid}/v2.0 
at java.base/java.net.URI$Parser.fail(URI.java:2976) at java.base/java.net.URI$Parser.checkChars(URI.java:3147)
at java.base/java.net.URI$Parser.parseHierarchical(URI.java:3229) at java.base/java.net.URI$Parser.parse(URI.java:3177)
at java.base/java.net.URI.<init>(URI.java:623)
at com.nimbusds.oauth2.sdk.util.JSONObjectUtils.getURI(JSONObjectUtils.java:529)

Comments (6)

  1. Romain Pelletier reporter

    yes parameter “issuer”, line 1781 of the AuthorizationServerMetadata class

    Issuer issuer = new Issuer(JSONObjectUtils.getURI(jsonObject, "issuer").toString());
    

  2. Klaasjan Brand

    I’ve run into this problem too, it seems to be unique to Microsoft’s implementation of the Azure ‘common’ flow, which is not OIDC compliant. Regrettably they don’t see a solution and are not able or planning to fix this.

    Beside the non-parsable characters there’s also a mismatch on the returned issuer that prevents us from using pac4j 6 to log into Azure, which is a regression from previous versions where this worked.

    There are multiple in depth descriptions about Azure’s behaviour, like here: https://github.com/MicrosoftDocs/azure-docs/issues/38545

  3. Adrian Schmid (adsc)

    We’ve had the same issue aswell when using the “common” tenant. The issue resolved itself when we used our real Tenant-ID in the URI:

  4. Klaasjan Brand

    Adrian: That’s only a solution if you know in advance which tenant you’re using. We’ve got multiple customers using different Azure domains and use the common flow to let Azure figure out the tenant the user belongs to.

  5. Log in to comment