Search code examples
spring-bootazurespring-securityazure-ad-b2cspring-security-oauth2

springboot oauth2 client azure active directory b2c issuer-uri problem


i set up spring boot with oauth2 client and here is my properties:

spring:
  security:
    oauth2:
      client:
        registration:
          azuread:
            authorization-grant-type: authorization_code
            client-id: 'client id'
            client-secret: 'secret'
            provider: azuread
            scope: openid
            client-name: demo
            user-flows:
                sign-up-or-sign-in: <policy name>
        provider:
          azuread:
            issuer-uri: https://{clientId}.b2clogin.com/{clientId}.onmicrosoft.com/<policy-name>/v2.0/.well-known/openid-configuration

when spring start up it complains: "The Issuer provided in the configuration metadata did not match the requested issuer" i checked implementation and found that azure b2c issuer-uri does not have policy or userflow in issuer-uri but we have to set policy name in spring configuration as path variable and after spring rest call to https://{clientId}.b2clogin.com/{clientId}.onmicrosoft.com//v2.0/.well-known/openid-configuration , spring will check response to compare it with auzre response in which they are not the same

expected: https://{clientId}.b2clogin.com/{clientId}.onmicrosoft.com//v2.0/

result:
https://{clientId}.b2clogin.com/{clientId}.onmicrosoft.com/v2.0/

tried spring boot oauth2 reference check azure b2c AD doc and spring sample , but i don't want to use spring boot azure AD b2c starter, only using oauth2 client


Solution

  • The error you are getting is due to incorrect metadata.The metadata should have tenantId rather than clientId.

    It should be https://{tenantId}.b2clogin.com/{tenantId}.onmicrosoft.com/{policy-name}/v2.0/.well-known/openid-configuration where tenantId is the name of your Azure Active Directory Tenant.