oauth2-proxy: Azure provider fails when scope is not Microsoft Graph

My AAD application is configured for the following API permissions: Screenshot from 2023-11-08 16-15-02 to be able to authenticate against Azure Kubernetes.

The proxy is configured like follows:

provider: azure
oidc-issuer-url: https://login.microsoftonline.com/[REDACTED]/v2.0
scope: 6dae42f8-4368-4678-94ff-3960e28e3630/.default

and I get the error: The scope 6dae42f8-4368-4678-94ff-3960e28e3630/.default https://graph.microsoft.com/.default is not valid. static scope limit exceeded. because the proxy adds the scope https://graph.microsoft.com/.default, but in my case I don’t need Microsoft Graph.

If I try to use provider: oidc instead, I get the error Error redeeming code during OAuth2 callback: token response did not contain an id_token.

One possible solution would be to allow passing custom scopes without adding https://graph.microsoft.com/.default.

About this issue

  • Original URL
  • State: closed
  • Created 3 years ago
  • Comments: 16 (7 by maintainers)

Most upvoted comments

I had a similar problem with the oidc provider logging in to Azure, in my case I tracked it down to the fact that the proxy was unable to fetch the groups from the userinfo endpoint without the Microsoft Graph scope. In my case I don’t actually care about group membership (I’m only using OIDC for authentication, I handle authorization directly in my own app) so I ended up with the following workaround (sorry, I use alpha config, and and envsubst-type transformation on my config file to insert the right values for the @FOO@ placeholders):

providers:
- provider: oidc
  id: AzureAD
  clientID: '@CLIENT_ID@'
  clientSecretFile: '@CLIENT_SECRET_FILE@'
  scope: '@OAUTH_SCOPE@'
  oidcConfig:
    emailClaim: email
    groupsClaim: groups
    audienceClaims: ["aud"]
    insecureSkipNonce: true
    # set next line to true when using the "common" issuer URL, since the actual
    # token issuer in this case has a specific tenant ID instead of "common"
    insecureSkipIssuerVerification: false
    issuerURL: https://login.microsoftonline.com/@OIDC_TENANT_ID@/v2.0
    userIDClaim: email
    # By default oauth2-proxy discovers the userinfo URL, and then fails to log
    # in as it can't fetch the groups list from there.  We don't care about AAD
    # group memberships, so instead we must disable discovery and manually
    # configure the other URLs that would normally be discovered but leave the
    # profileURL blank.  This way it doesn't attempt to fetch groups at all.
    skipDiscovery: true
    jwksURL: https://login.microsoftonline.com/@OIDC_TENANT_ID@/discovery/v2.0/keys
  loginURL: https://login.microsoftonline.com/@OIDC_TENANT_ID@/oauth2/v2.0/authorize
  redeemURL: https://login.microsoftonline.com/@OIDC_TENANT_ID@/oauth2/v2.0/token

essentially, skip discovery and instead configure the login, redeem and jwks URLs by hand. If no profile URL is set then it will just use the ID token groups (if any) and not try to enrich the list by calling out to the userinfo endpoint.