alancting / oauth2-microsoft-openid

Microsoft OAuth 2.0 support for the PHP League's OAuth 2.0 Client
MIT License
1 stars 1 forks source link

getCredentials must not be null #6

Open bettinz opened 3 years ago

bettinz commented 3 years ago

Hello, is the documentation updated? Right now I've this error:

The return value of "Alancting\OAuth2\OpenId\Client\Security\Authenticator\AdfsAuthenticator::getCredentials()" must not be null. Return false from "Alancting\OAuth2\OpenId\Client\Security\Authenticator\AdfsAuthenticator::supports()" instead.

The configuration is: security.yaml

security:
    encoders:
        App\UserModule\Domain\Model\User:
            algorithm: auto

    providers:
        app_user_provider:
            entity:
                class:  App\UserModule\Domain\Model\User
                property: username
#
    firewalls:
        login:
            pattern: ^/api/login
            stateless: true
            anonymous: true
            json_login:
                check_path: /api/login_check
                success_handler: lexik_jwt_authentication.handler.authentication_success
                failure_handler: lexik_jwt_authentication.handler.authentication_failure

        apidoc:
            pattern: ^/api/docs
            security: false
            anonymous: true

        api:
            pattern: ^/api
            stateless: true
            guard:
                authenticators:
                    - lexik_jwt_authentication.jwt_token_authenticator

        dev:
            pattern: ^/(_(profiler|wdt)|css|images|js)/
            security: false
        main:
            anonymous: true
            lazy: true
            guard:
                authenticators:
                    - alancting.microsoft.adfs.authenticator
                provider: app_user_provider
            entry_point: alancting.microsoft.adfs.authenticator

the controller:

public function connect(Request $request, ClientRegistry $clientRegistry)
    {
        return new Response();
    }

    public function connectCheckAction(Request $request, ClientRegistry $clientRegistry)
    {
        return new Response();
    }

    /**
     * After going to microsoft, you're redirected back here
     * because this is the "redirect_route" you configured
     * in config/packages/knpu_oauth2_client.yaml
     *
     */
    public function logoutAction(Request $request, ClientRegistry $clientRegistry)
    {
        return new Response();
    }

routes.yaml


api_login_check:
    path: /api/login_check

microsoft_openid_connect:
    path: /adfs/connect
    controller: App\UserModule\Infrastructure\Controller\OAuth2LoginController::connect

microsoft_openid_connect_check:
    path: /signin
    controller: App\UserModule\Infrastructure\Controller\OAuth2LoginController::connectCheckAction

microsoft_openid_logout:
    path: /adfs/logout
    controller: App\UserModule\Infrastructure\Controller\OAuth2LoginController::logoutAction

knpu_oauth2_client.yaml:

knpu_oauth2_client:
    clients:
        microsoft_openid:
            type: generic
            provider_class: Alancting\OAuth2\OpenId\Client\Provider\AdfsProvider
            client_class: Alancting\OAuth2\OpenId\Client\Client\AdfsClient
            client_id: "%env(ADFS_CLIENT_ID)%"
            client_secret: "%env(ADFS_CLIENT_SECRET)%"
            redirect_route: microsoft_openid_connect_check
            provider_options:
                hostname: "%env(ADFS_HOSTNAME)%"
                user_key: unique_name
                microsoft_resource_scopes:
                    - profile
                    - offline_access

Thanks 😄

greynor commented 8 months ago

Hi there,

I've got the exact same problem here. If I try to change the return of $this->oAuthCredential to "false" if it's null, then the next error occurs Call to a member function getIdTokenJWT() on bool

So this cannot be the solution. Help would be great! It's not working currently with knpu