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

Respond with helpful and spec complient error on invalid user credentials #1230

Merged
merged 2 commits into from
Jul 10, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/Exception/OAuthServerException.php
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,7 @@ public static function invalidScope($scope, $redirectUri = null)
*/
public static function invalidCredentials()
{
return new static('The user credentials were incorrect.', 6, 'invalid_credentials', 401);
return new static('The user credentials were incorrect.', 6, 'invalid_grant', 400);
}

/**
Expand Down
2 changes: 1 addition & 1 deletion src/Grant/PasswordGrant.php
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ protected function validateUser(ServerRequestInterface $request, ClientEntityInt
if ($user instanceof UserEntityInterface === false) {
$this->getEmitter()->emit(new RequestEvent(RequestEvent::USER_AUTHENTICATION_FAILED, $request));

throw OAuthServerException::invalidGrant();
throw OAuthServerException::invalidCredentials();
}

return $user;
Expand Down
7 changes: 7 additions & 0 deletions tests/Exception/OAuthServerExceptionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -137,4 +137,11 @@ public function testCanGetRedirectionUri()

$this->assertSame('https://example.com/error', $exceptionWithRedirect->getRedirectUri());
}

public function testInvalidCredentialsIsInvalidGrant()
{
$exception = OAuthServerException::invalidCredentials();

$this->assertSame('invalid_grant', $exception->getErrorType());
}
}
2 changes: 1 addition & 1 deletion tests/Grant/PasswordGrantTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,7 @@ public function testRespondToRequestBadCredentials()
$responseType = new StubResponseType();

$this->expectException(\League\OAuth2\Server\Exception\OAuthServerException::class);
$this->expectExceptionCode(10);
$this->expectExceptionCode(6);

$grant->respondToAccessTokenRequest($serverRequest, $responseType, new DateInterval('PT5M'));
}
Expand Down