Skip to content

Conversation

@fhanik
Copy link
Contributor

@fhanik fhanik commented Oct 8, 2025

When configuring an Oauth2.0 provider that returns opaque access tokens, the UAA throws an error trying to parse it as it assumes it is a JWT id_token

Easy to reproduce by adding Github as an OAuth provider in uaa.yml

login:
  oauth:
    providers:
      github:
        type: oauth2.0
        authUrl:     https://github.com/login/oauth/authorize
        tokenUrl:     https://github.com/login/oauth/access_token
        userInfoUrl:     https://api.github.com/user
        issuer: https://github.com
        relyingPartyId: <your-github-app-client-id>
        relyingPartySecret: <your-github-app-client-secret>
        performRpInitiatedLogout: false
        scopes:
          - openid
        linkText: Login with Github
        showLinkText: true
        attributeMappings:
          user_name: login
        clientAuthInBody: true
        externalGroupsWhitelist:
          - "*"

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR fixes the OAuth 2.0 authorization code flow by preventing the UAA from incorrectly parsing opaque access tokens as JWT ID tokens. The fix allows OAuth 2.0 providers like GitHub that return opaque access tokens to work properly with the UAA.

  • Modified token handling logic to differentiate between OAuth 2.0 access tokens and OIDC ID tokens
  • Added test coverage to verify OAuth 2.0 authorization flow with opaque access tokens works correctly

Reviewed Changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.

File Description
ExternalOAuthAuthenticationManager.java Added conditional logic to properly handle OAuth 2.0 access tokens vs OIDC ID tokens
ExternalOAuthAuthenticationManagerTest.java Added test case to verify OAuth 2.0 flow with opaque access tokens

Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

Comment on lines +613 to +615
String tokenFieldName = getTokenFieldName(identityProvider.getConfig());
String token = getTokenFromCode(codeToken, identityProvider);
if ("access_token".equals(tokenFieldName) && token != null && OAUTH20.equals(identityProvider.getType())) {
Copy link

Copilot AI Oct 9, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The hardcoded string 'access_token' should be extracted to a constant to improve maintainability and reduce the risk of typos.

Copilot uses AI. Check for mistakes.
@strehle
Copy link
Member

strehle commented Oct 9, 2025

When configuring an Oauth2.0 provider that returns opaque access tokens, the UAA throws an error trying to parse it as it assumes it is a JWT id_token

Easy to reproduce by adding Github as an OAuth provider in uaa.yml

login:
  oauth:
    providers:
      github:
        type: oauth2.0
        authUrl:     https://github.com/login/oauth/authorize
        tokenUrl:     https://github.com/login/oauth/access_token
        userInfoUrl:     https://api.github.com/user
        issuer: https://github.com
        relyingPartyId: <your-github-app-client-id>
        relyingPartySecret: <your-github-app-client-secret>
        performRpInitiatedLogout: false
        scopes:
          - openid
        linkText: Login with Github
        showLinkText: true
        attributeMappings:
          user_name: login
        clientAuthInBody: true
        externalGroupsWhitelist:
          - "*"
@fhanik fhanik force-pushed the pr/fix-oauth2.0-authorization-flow branch from 9b59471 to 1aa6826 Compare October 13, 2025 18:28
@fhanik
Copy link
Contributor Author

fhanik commented Oct 13, 2025

@strehle @adrianhoelzl-sap It appears that we no longer have an actual Github OAuth2.0 test, so I added one to make it clear.

You can take commit 4ab33f7 against develop and see it failing.

@github-project-automation github-project-automation bot moved this from Inbox to Pending Merge | Prioritized in Foundational Infrastructure Working Group Oct 16, 2025
@fhanik fhanik merged commit fc111e5 into cloudfoundry:develop Oct 16, 2025
33 checks passed
@github-project-automation github-project-automation bot moved this from Pending Merge | Prioritized to Done in Foundational Infrastructure Working Group Oct 16, 2025
@fhanik fhanik deleted the pr/fix-oauth2.0-authorization-flow branch October 16, 2025 14:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Development

Successfully merging this pull request may close these issues.

2 participants