-
Notifications
You must be signed in to change notification settings - Fork 786
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
Use middleware 'auth:api' and 'client' simultanaous #898
Comments
Please see #379 |
Sorry to reopen this, but how does #379 solve the current issue? |
I found an alternative method for my specific problem. I wait next Passport version to update properly my code. |
Ah sorry, I misunderstood the original question. You don't need to add the |
If I'm not mistaken @jcharcosset is in the same boat as myself. I'm building a public API where users and machines can access all the endpoints the same way.
I'd like a simple way to allow both (client credentials and password) tokens to access the same endpoints over the same middleware. Like OP said they don't work simultaneously when you do, for example, something like :
The intended behavior I'm aiming for is that of an OR (if it passes any of those conditions, allow access) instead of an AND like it currently is for Laravel. Hope that's a bit more clear. |
i want to use both of |
Using these at the same time isn't feasible as explained here: #898 (comment) |
Okay thank you. @driesvints |
if you want to use the same entry point in api.php
if $user is null, just do the process without auth in your controller. Because both client token and user token can access the same route with the middleware "client" and also you get the user from guard. |
After searching and trying many solutions i create this one
so now you can add it to your kernel file and use it |
I have the same use case as @jcharcosset and @fer8a: an API that should be accessible with both client access tokens and personal access tokens. My implementation was roughly the same as @fer8a has posted, but as of v8 of Passport this isn't working any more due to PR #1040. Is there anybody who has a suggestion how this can be fixed (except for writing my own middleware)? |
I also have the same problem as @madman-81 and @jcharcosset and @fer8a. In a lot of our projects we have for example an api route to register a new user. This route is protected with the Because of the changes by the PR #1040 it seems that I will now need 2 separate oauth clients? This seems very strange. |
Since already 4 people run into this issue, shouldn't this issue be reopened? |
@gendronb @madman-81 you can see my solution above your comments
|
It seems link the AuthGuardMiddleware and ClientCredMiddleware are classes of your own? For now I've done something similar and created my own middleware as well, but as an extension of the CheckClientCredentials middleware from Passport. I've overridden the handle() function and left out the firstparty-check that has been added in the PR. It looks like this now: class CheckAPICredentials extends CheckClientCredentials
{
/**
* Validate the scopes and token on the incoming request.
*
* @param \Psr\Http\Message\ServerRequestInterface $psr
* @param array $scopes
* @return void
* @throws \Laravel\Passport\Exceptions\MissingScopeException|\Illuminate\Auth\AuthenticationException
*/
protected function validate($psr, $scopes)
{
$token = $this->repository->find($psr->getAttribute('oauth_access_token_id'));
if (! $token ) {
throw new AuthenticationException;
}
if (in_array('*', $token->scopes)) {
return;
}
foreach ($scopes as $scope) {
if ($token->cant($scope)) {
throw new MissingScopeException($scope);
}
}
}
} I guess it could be nice to have this (or something similar) as a standard middleware in Passport? Because the main issue in the PR was that that the name suggested it was checking on Client tokens and it accepted all tokens. |
#1125 is opened for this issue. |
I'm sorry to ride this dead horse again, but can someone please explain how the problem got solved? Is it even solved? Because I still can't use endpoints with both. When I use the normal grant client and client middleware, I don't get the user. When I use the personal client and auth:api, the client grant auth fails completely. |
+1 It's not possible to use both the I think that while there's no out-of-the-box possibility to solve this issue, I'm either going to:
|
I use Laravel 5.7.* and Passport ^7.0 .
To consume my API with javaScript, I added CreateFreshApiToken middleware.
I would also like to implement Client Credentials Grant Tokens authentication so that a machine can use the API.
But, the two middlewares "client" and "auth:api" doesn't work together.
If I put "auth:api" middleware only, I can't access my API from web. And reciprocally, if I put "client" middleware only, I can't access my API from another machine.
Best regards,
The text was updated successfully, but these errors were encountered: