FriendsOfSymfony / FOSOAuthServerBundle

A server side OAuth2 Bundle for Symfony
1.09k stars 451 forks source link

How to get OAuthToken instead of UserPasswordToken? #673

Open softrare opened 3 years ago

softrare commented 3 years ago

I want to get the AccessToken after the user authenticated.

    $token = $tokenStorage->getToken();

    if($token instanceof OAuthToken) {
        /** @var AccessToken $accessToken */
        $accessToken = $accessTokenManager->findTokenByToken(
            $token->getToken()
        );
    }

Unfortunately the $token is always UsernamePasswordToken never OAuthToken so getToken() is not available. But it's still a normal and working oauth process and there is a normal accesstoken made and stored. I am sure I'm missing something. Anyone has a tip?

EDIT: Ok, I understood now that you first get a UsernamePasswordToken and after that an OAuthToken, but there seems to be no event where I can grab the OAuthToken from directly after the accesstoken is being created.