Skip to content

[Security] OAuth2 Introspection Endpoint (RFC7662) #50027

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Feb 26, 2025

Conversation

Spomky
Copy link
Contributor

@Spomky Spomky commented Apr 15, 2023

Q A
Branch? 7.3
Bug fix? no
New feature? yes
Deprecations? no
Tickets none
License MIT
Doc PR symfony/symfony-docs#[TODO]

In addition to the excellent work of @vincentchalamon #48272, this PR allows getting the data from the OAuth2 Introspection Endpoint. This endpoint is defined in the RFC7662. It returns the following information that is used to retrieve the user:

  • If the access token is active
  • A set of claims that are similar to the OIDC one, including the sub or the username.

Example of configuration:

framework:
    http_client:
        scoped_clients:
            oauth2.client:
                base_uri: 'https://authorization-server.example.com/introspection'
                scope: 'https://authorization-server\.example\.com'
                headers:
                    Authorization: 'Basic Y2xpZW50OnBhc3N3b3Jk' # Introspection Endpoint usually requires client authentication

security:
    firewalls:
        main:
            pattern: ^/
            access_token:
                token_handler:
                    oauth2: ~
                token_extractors: 'header' 
                realm: 'My API'

@Spomky Spomky requested review from wouterj and chalasr as code owners April 15, 2023 15:26
@carsonbot carsonbot added this to the 6.3 milestone Apr 15, 2023
@Spomky Spomky marked this pull request as draft April 15, 2023 15:27
@Spomky Spomky changed the title OAuth2 Introspection Endpoint (RFC7662) [Security] OAuth2 Introspection Endpoint (RFC7662) Apr 16, 2023
@wouterj
Copy link
Member

wouterj commented Apr 16, 2023

Thanks for yet another security feature proposal!
First a practical thing: We're entering feature freeze very shortly, meaning that we don't merge newly opened feature PRs for 6.3 anymore (unless really needed or very small). So we have some more time to polish this PR for 6.4 :)

I want to discuss a general remark that I don't think I've shared publicly yet. (disclaimer: I know literally nothing about OAuth 2.0 and OIDC, except that it consists of a ton of different standards, so I can't determine if this applies to this PR)

My vision for Symfony Security is to provide a minimal implementation following industry best practices based on standards and let community libraries/bundle add all "bonus features". We don't have the man power nor knowledge to maintain let's say all OAuth, SAML, Webauthn and MFA standards.

When adding new features, I think we must always test it to those 3 conditions:

  • Is the feature based on a standard? (which is clearly yes for this one)
  • Is this feature required to have a working authentication/authorization system, within reason (i.e. if 90% of the apps use it when using OIDC)? (this is what I'm a bit unsure about for this specific PR)
  • Is this feature following industry best practices? (e.g. this is why I pushed a bit to add a JWT implementation in the OIDC PR, given that the user info handler is generally not recommended for production)

cc @chalasr

@Spomky Spomky marked this pull request as ready for review April 16, 2023 11:57
@chalasr
Copy link
Member

chalasr commented Apr 16, 2023

I agree with Wouter.
Implementing all OAuth2/OIDC features in core is a non-goal for now. Better improve community packages that are already supporting them or are meant to do so.

@Spomky
Copy link
Contributor Author

Spomky commented Apr 17, 2023

Hi @wouterj and @chalasr,

Many thanks for your feedback and advices. Hereafter my thoughts on this

First a practical thing: We're entering feature freeze very shortly, meaning that we don't merge newly opened feature PRs for 6.3 anymore (unless really needed or very small). So we have some more time to polish this PR for 6.4 :)

No problem. I based it on the branch 6.3, but it does not matter to rebase to another branch.

We don't have the man power nor knowledge to maintain let's say all OAuth, SAML, Webauthn and MFA standards.

Even if the community is large enough, I understand there is a risk to include specific authentication means that could be a problem in the future.

When adding new features, I think we must always test it to those 3 conditions

I was not aware of those, but seem to be fair enough.

Implementing all OAuth2/OIDC features in core is a non-goal for now. Better improve community packages that are already supporting them or are meant to do so.

Noted. Thanks. In this case, there is no need to go further here. I will continue that work in a side project. 👍

@Spomky Spomky closed this Apr 17, 2023
@Spomky
Copy link
Contributor Author

Spomky commented May 15, 2023

Hi,

I revised my mind and I would like to reopen this PR. I think this should be challenged a bit more.
Hereafter a (simplified) diagram showing where this new feature will be useful.

sequenceDiagram
    participant Client
    participant Authorization Server
    participant Resource Server
    Authorization Server->>Client: IDToken+Access Token (after consent+authentication)
    loop PR 48272 acts here
        Client->>Client: IDToken
        Client->>Authorization Server: Access Token (UserInfo Endpoint)
    end
    Client->>Resource Server: Access Token
    loop This PR acts here
        Resource Server->>Resource Server: Access Token (e.g. JWT, PASETO...)
        Resource Server->>Authorization Server: Access Token (Introspection Endpoint)
    end
Loading

As you can see, the features introduced with #48272 allow a Client application to authenticate end-users (by end-user, the OAuth spec means a person). The Client app can either use the IDToken (JWT) or the Access Token+UserInfo Endpoint to retreive the end-user details.

sequenceDiagram
    participant Client
    participant Authorization Server
    loop PR 48272 acts here
        Client->>Client: IDToken
        Client->>Authorization Server: Access Token (UserInfo Endpoint)
    end
Loading

This PR acts in a very similar way. The main differences are as follows:

  • It is s not meant to be used by the Client, but the Resource Server
  • The Resource Server is not supposed to receive the ID Token (unless Client + Resource Server = the same application)
  • The Resource Server can directly use the Access Token if it can be verified (e.g. JWT)
  • The "user" (consumer of the Resource Server) can be a end-user or an application (e.g. API to API communication)
sequenceDiagram
    participant Resource Server
    participant Authorization Server
    loop This PR acts here
        Resource Server->>Resource Server: Access Token (e.g. JWT, PASETO...)
        Resource Server->>Authorization Server: Access Token (Introspection Endpoint)
    end
Loading

The reason why I think this PR deserves more attention is that is cover the missing piece for covering most of the OAuth2 use cases.

I understand the point of view you say we could rely community on community works. And that's true that several solutions exist. But here, no third party library with exotic dependencies is needed1. We can directly use it with few configuration lines on e.g. ApiPlatform-based resource servers.

Also, I understand that Symfony does not aim at implementing all industry/web standards (even if all the Notifier channels make me think the opposite). However, OAuth2 is so widely used by the industry that it would be a shame not to support it, in particular after the works on the previous PRs. It is not a trendy technology, but a standard widely used for more than 10 years (and in continuous evolution).

At last but not least, the item Support for third-party authentication services (e.g. Auth0: https://auth0.com/) in [RFC] Symfony Security rework tracking issue proposed by @curry684 could be marked as checked as this feature will allow communication with auth0/Okta, OneLogin and many more.


1: this does not mean community works are useless. They all have great features, but having too much external dependencies is something we all try to avoid.

@Spomky Spomky marked this pull request as draft May 15, 2023 17:14
@Spomky Spomky closed this May 15, 2023
@Spomky Spomky force-pushed the features/oauth-rfc7662 branch from 33af1e0 to 398830c Compare May 15, 2023 17:25
@Spomky Spomky reopened this May 15, 2023
@Spomky Spomky force-pushed the features/oauth-rfc7662 branch 2 times, most recently from 013329c to 9fdb2ed Compare May 17, 2023 13:40
@xabbuh xabbuh added this to the 7.2 milestone May 15, 2024
@Spomky Spomky force-pushed the features/oauth-rfc7662 branch from f5938f4 to 432fdf1 Compare July 13, 2024 13:59
Copy link
Member

@chalasr chalasr left a comment

Choose a reason for hiding this comment

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

I changed my mind, given we have OAuth/OIDC support let's do it right + as complete as possible. 👍 once the small comments addressed & PR rebased

@Spomky
Copy link
Contributor Author

Spomky commented Jul 14, 2024

That's good news!
The PR is now rebased and I addressed the remarks raised earlier.

Copy link
Member

@nicolas-grekas nicolas-grekas left a comment

Choose a reason for hiding this comment

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

Here are some CS suggestions, please rebase also.

@fabpot fabpot modified the milestones: 7.2, 7.3 Nov 20, 2024
@Spomky Spomky force-pushed the features/oauth-rfc7662 branch 7 times, most recently from 737ece5 to c086a13 Compare December 25, 2024 16:56
@Spomky Spomky force-pushed the features/oauth-rfc7662 branch 2 times, most recently from 4ee96eb to dc56f23 Compare January 5, 2025 19:47
@Spomky Spomky force-pushed the features/oauth-rfc7662 branch from dc56f23 to ec41507 Compare January 18, 2025 07:09
@Spomky Spomky force-pushed the features/oauth-rfc7662 branch 2 times, most recently from 9681e6b to 8d3eef1 Compare February 13, 2025 08:06
In addition to the excellent work of @vincentchalamon symfony#48272, this PR allows getting the data from the OAuth2 Introspection Endpoint. This endpoint is defined in the [RFC7662](https://datatracker.ietf.org/doc/html/rfc7662). It returns the following information that is used to retrieve the user:

* If the access token is active
* A set of claims that are similar to the OIDC one, including the `sub` or the `username`.
@fabpot fabpot force-pushed the features/oauth-rfc7662 branch from 8d3eef1 to e68726f Compare February 26, 2025 07:55
@fabpot
Copy link
Member

fabpot commented Feb 26, 2025

Thank you @Spomky.

@fabpot fabpot merged commit 1f5ff48 into symfony:7.3 Feb 26, 2025
1 check was pending
@Spomky Spomky deleted the features/oauth-rfc7662 branch March 2, 2025 11:04
@fabpot fabpot mentioned this pull request May 2, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

10 participants