Skip to content
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

How do I authenticate using an access token based on client credentials? #634

Open
Evertt opened this issue Nov 13, 2019 · 1 comment
Open

Comments

@Evertt
Copy link

Evertt commented Nov 13, 2019

I retrieve an access token using the client_credentials grant type. Then I try to access a protected resource using this access token, but then I always get the error HttpException : Full authentication is required to access this resource.

I'm wondering if I set up my config wrongly. Here's my fos_auth_server.yaml:

fos_oauth_server:
    db_driver: orm
    client_class:        App\Entity\OAuth2\Client
    access_token_class:  App\Entity\OAuth2\AccessToken
    refresh_token_class: App\Entity\OAuth2\RefreshToken
    auth_code_class:     App\Entity\OAuth2\AuthCode

And here's my security.yaml:

security:
    encoders:
        App\Entity\User:
            algorithm: auto

    providers:
        app_user_provider:
            entity:
                class: App\Entity\User
                property: email

    firewalls:
        dev:
            pattern: ^/(_(profiler|wdt)|css|images|js)/
            security: false

        main:
            anonymous: true

        oauth_token:
            pattern:    ^/oauth/v2/token
            security:   false

        api:
            pattern:    ^(?!/oauth).*
            fos_oauth:  true
            stateless:  true
            provider:   app_user_provider

    access_control:
        - { path: ^(?!/oauth).*, roles: [ IS_AUTHENTICATED_FULLY ] }

What's also interesting is that when I get an access token based on client_credentials, then of course that access token is not connected to any user. So I'm wondering if maybe Symfony is throwing that exception, because no user can be found. If that's the case, how can I configure Symfony that it's okay if no user can be found?

@niamzor
Copy link

niamzor commented Feb 7, 2020

@Evertt I'm curious if you find a solution ?
I am currently thinking about a way to authenticate a PHP application accessing a PHP API. The client_credentials grant type seems the way to go in my case.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants