Skip to content
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

Deny access if user is not authenticated #1408

Conversation

hafezdivandari
Copy link
Contributor

@hafezdivandari hafezdivandari commented May 17, 2024

Setting the user instance has been forced on AuthCodeGrant::completeAuthorizationRequest() method, but it is not necessary when Authorization request is denied!

On Laravel Passport we support prompt=none when redirecting for authorization. Currently, we have to create the error response manually when user is not authenticated.

Here is the related code on Laravel Passport:

https://github.com/laravel/passport/blob/8ea1dd41745c89769fd8c4b207c4739eea707e95/src/Http/Controllers/AuthorizationController.php#L181-L204

After this PR we are able to simply do:

if (! is_null($user)) {
    $authRequest->setUser(new User($user->getAuthIdentifier()));
}

$authRequest->setAuthorizationApproved(false);

return $this->withErrorHandling(function () use ($authRequest) {
    return $this->convertResponse(
        $this->server->completeAuthorizationRequest($authRequest, new Psr7Response)
    );
});

@hafezdivandari
Copy link
Contributor Author

Hi @Sephster, hope you’re doing well. Any progress on the PRs related to Laravel Passport? I’ve listed them all here.

@hafezdivandari
Copy link
Contributor Author

Fixed via laravel/passport#1791

@hafezdivandari hafezdivandari deleted the deny-access-unauthenticated branch October 3, 2024 10:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants