spring-projects / spring-projects/spring-security

Azure AD Multi-Tenant OIDC Discovery Fails Due to '{tenantid}' in Issuer URI

Open
#17,948 4 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

in: oauth2
Dominant language
Java
Stars
9.6k
Forks
6.3k
Avg merge
2d 11h
Merged PRs (30d)
52

Description

Describe the bug
When configuring Spring Security's OAuth2 client for multi-tenant Azure Active Directory (Microsoft Entra ID) by setting the spring.security.oauth2.client.provider.<id>.issuer-uri to https://login.microsoftonline.com/common/v2.0 or https://login.microsoftonline.com/organizations/v2.0 and relying on issuer auto-discovery, the application fails to start with an UnsatisfiedDependencyException and a URISyntaxException.

The root cause is that the OpenID Connect discovery document fetched from these multi-tenant Azure AD endpoints contains an issuer field with a {tenantid} placeholder (e.g., "issuer": "https://login.microsoftonline.com/{tenantid}/v2.0"). The underlying URI parser considers {tenantid} an "Illegal character in path," leading to the URISyntaxException during the ClientRegistrations.parse step.

This prevents proper multi-tenant configuration through simple issuer-uri auto-discovery as per Spring Security's standard OIDC client configuration.

To Reproduce
Steps to reproduce the behavior:

  1. Create a Spring Boot 3.5.x application with spring-boot-starter-oauth2-client and spring-boot-starter-security.

  2. Configure application.yml with Azure AD (Entra ID) client details, specifically setting the issuer-uri to the multi-tenant common endpoint:

spring:
  security:
    oauth2:
      client:
        registration:
          entra:
            client-id: <YOUR_AZURE_AD_CLIENT_ID>
            client-secret: <YOUR_AZURE_AD_CLIENT_SECRET>
            redirect-uri: "{baseUrl}/oauth2/code/{registrationId}"
            authorization-grant-type: authorization_code
            scope:
              - openid
              - profile
              - email
              - User.Read
        provider:
          entra:
            issuer-uri: https://login.microsoftonline.com/common/v2.0 # Or https://login.microsoftonline.com/organizations/v2.0
  1. Run the Spring Boot application.

Expected behavior
The application should start successfully, and Spring Security should be able to resolve the OIDC configuration for multi-tenant Azure AD, allowing users from different Azure AD organizations to authenticate. The {tenantid} placeholder in the discovered issuer should be handled gracefully, allowing for multi-tenant applications.

Sample
A minimal sample involve an empty Spring Boot application with the application.yml configuration as described.
Such reproduction is created here : https://github.com/Dyskal/azure-oauth2-mre

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start at the ClientRegistrations.parse step described in the report and reproduce the failure with the linked minimal Spring Boot sample using the common or organizations issuer. Trace how the discovered issuer containing {tenantid} is parsed, then verify that the application starts and multi-tenant OIDC discovery works for the reported configuration.

Written by the indexing model from the issue text.

Assessment

Tech stack
java, spring-boot
Domain
authentication, security
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.