public function getAccessToken()
    {
        if (!$this->isStateless) {
            $expectedState = $this->getSession()->get(self::OAUTH2_SESSION_STATE_KEY);
            $actualState = $this->getCurrentRequest()->query->get('state');
            if (!$actualState || ($actualState !== $expectedState)) {
                throw new InvalidStateException('Invalid state');
            }
        }

        $code = $this->getCurrentRequest()->get('code');

        if (!$code) {
            throw new MissingAuthorizationCodeException('No "code" parameter was found (usually this is a query parameter)!');
        }

        return $this->provider->getAccessToken('authorization_code', [
            'code' => $code,
        ]);
    }
public function getAccessToken()
    {
        if (!$this->isStateless) {
            $expectedState = $this->getSession()->get(self::OAUTH2_SESSION_STATE_KEY);
            $actualState = $this->getCurrentRequest()->query->get('state');
            if (!$actualState || ($actualState !== $expectedState)) {
                throw new InvalidStateException('Invalid state');
            }
        }

        $code = $this->getCurrentRequest()->get('code');

        if (!$code) {
            throw new MissingAuthorizationCodeException('No "code" parameter was found (usually this is a query parameter)!');
        }

        return $this->provider->getAccessToken('authorization_code', [
            'code' => $code,
        ]);
    }
public function getAccessToken ( ) { if ( ! $ this -> isStateless ) { $ expectedState = $ this -> getSession ( ) -> get ( self :: OAUTH2_SESSION_STATE_KEY ) ; $ actualState = $ this -> getCurrentRequest ( ) -> query -> get ( 'state' ) ; if ( ! $ actualState || ( $ actualState !== $ expectedState ) ) { throw new InvalidStateException ( 'Invalid state' ) ; } } $ code = $ this -> getCurrentRequest ( ) -> get ( 'code' ) ; if ( ! $ code ) { throw new MissingAuthorizationCodeException ( 'No "code" parameter was found (usually this is a query parameter)!' ) ; } return $ this -> provider -> getAccessToken ( 'authorization_code' , [ 'code' => $ code , ] ) ; }
Call this after the user is redirected back to get the access token.

@return \League\OAuth2\Client\Token\AccessToken

@throws InvalidStateException
@throws MissingAuthorizationCodeException
@throws IdentityProviderException If token cannot be fetched
Call this after the user is redirected back to get the access token .