-
Notifications
You must be signed in to change notification settings - Fork 790
Enable client credentials grant type #34
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Enable client credentials grant type #34
Conversation
4b286b7 to
870ebce
Compare
| * | ||
| * @param \Illuminate\Http\Request $request | ||
| * @param \Closure $next | ||
| * @return mixed |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Missing @throws \Illuminate\Auth\AuthenticationException
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Updated, thanks!
|
Why define a whole new middleware? The TokenGuard will already call the validateAuthenticatedRequest method on the resource server. |
|
For this type of grants there's no User, the TokenGuard expects to be able to successfully retrieve a user. |
|
I'm also interested in this, I was using lucadegasperi/oauth2-server-laravel with client_credential tokens before upgrading to 5.3. At the moment I'm just extending the PassportServiceProvider, adding ClientCredentialsGrant as you have, and swapping it for the PassportServiceProvider in app/config.php |
| * | ||
| * @throws \Illuminate\Auth\AuthenticationException | ||
| */ | ||
| public function handle($request, Closure $next) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If you wanted to check scopes too, something along the following lines works:
This then works in the same way as the CheckForAnyScope middleware.
public function handle($request, Closure $next, ...$scopes)
{
$psr = (new DiactorosFactory)->createRequest($request);
try {
/**
* @var $serverRequest ServerRequest
*/
$serverRequest = $this->server->validateAuthenticatedRequest($psr);
} catch (OAuthServerException $e) {
throw new AuthenticationException;
}
foreach ($scopes as $scope) {
if (!in_array($scope,$serverRequest->getAttribute('oauth_scopes'))) {
throw new AuthenticationException;
}
}
return $next($request);
}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This works except when you try to request access token with '*' as scope. Seems like the logic for handling all scope in client credential grant is left out.
|
Hi everyone, Thanks ENx |
|
An access_token that was generated by |
|
@ankurk91 yeah, you can use the same client for multiple grants but it's not recommended. It's best to only use one grant per client. |
|
Thanks for the answer. |
This grant type is useful to allow clients to access data that's not owned by a certain user, for example: searching tweets, listing supported countries, etc...
The PR implements a middleware that can be used to check for client credentials.