uafrica / oauth-server

OAuth Server
Other
51 stars 51 forks source link

How to receive scope information #23

Open Romain17 opened 8 years ago

Romain17 commented 8 years ago

Hello uafrica,

Thanks for your plugin. I implemented and it work well.

I just have a question about the scope parameters. Indeed i send scope parameters in my request but i don't receive the information in response. Can you tell me how to use them ?

Thanks! Romain

irongomme commented 7 years ago

I'm also interested to know how to retrieve scopes information for an authenticated request ... Because OauthAuthenticate only retrieve user informations, but nothing about scopes !

sukihub commented 7 years ago

Hi :) use AccessTokenEntity, it offers hasScope() method. You can get current access token from Auth component $this->Auth->getAuthenticate('OAuthServer.OAuth')->Server->getAccessToken() or OAuth component ($this->OAuth->Server->getAccessToken())

irongomme commented 7 years ago

Thanks, I think it's a good start, but :

$this->Auth->getAuthenticate('OAuthServer.OAuth')->Server->getAccessToken() returns me null

and

$this->OAuth->Server->getAccessToken() raise : Call to undefined method League\OAuth2\Server\AuthorizationServer::getAccessToken()

irongomme commented 7 years ago

Finally, I make it works with this sample :

//Get the resource server
$resServer = $this->Auth->getAuthenticate('OAuthServer.OAuth')->Server;

//This line feeds accessToken to the resource server
$resServer->isValidRequest();

//Then i can test my scope
if ($resServer->getAccessToken()->hasScope('admin')) {
    // Code
}