Skip to content

Commit

Permalink
Merge pull request #1230 from marc-mabe/user-credentials-error
Browse files Browse the repository at this point in the history
Respond with helpful and spec complient error on invalid user credentials
  • Loading branch information
Sephster authored Jul 10, 2021
2 parents dc7fa33 + 3e31fe9 commit 0c86312
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 3 deletions.
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

0 comments on commit 0c86312

Please sign in to comment.