filsh / yii2-oauth2-server

A wrapper for implementing an OAuth2 Server(https://github.com/bshaffer/oauth2-server-php)
MIT License
332 stars 167 forks source link

RESTful Apis Get accessToken from user object #124

Closed veronicavg closed 7 years ago

veronicavg commented 7 years ago

When I perform the social login from my app, in the rest controller I create the user instance (if not exist), then i have to return the access token. In this case i don't have the password, i must create the token from the user object. How can i do that?

veronicavg commented 7 years ago

I find this

public function createAccessToken($clientId, $userId, $scope = null, $includeRefreshToken = true)
    {
        $accessToken = $this->getAccessTokenResponseType();
        return $accessToken->createAccessToken($clientId, $userId, $scope, $includeRefreshToken);
    }

in Server.php. But how to use it?

mtangoo commented 7 years ago

have you read instructions in readme? If yes what's your problem?

veronicavg commented 7 years ago

Read and read again. I solved my problem in that way:

$module = Yii::$app->getModule('oauth2');
$token = $module->getServer()->createAccessToken("testclient", $id_utente, 'default', true);

Not so easy to understand. Maybe need a method in User models like "getAccessToken()"