diff --git a/src/Exception/OAuthServerException.php b/src/Exception/OAuthServerException.php index 64adebf14..a0be0a5dd 100644 --- a/src/Exception/OAuthServerException.php +++ b/src/Exception/OAuthServerException.php @@ -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); } /** diff --git a/src/Grant/PasswordGrant.php b/src/Grant/PasswordGrant.php index 4e12fa535..fd32d2688 100644 --- a/src/Grant/PasswordGrant.php +++ b/src/Grant/PasswordGrant.php @@ -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; diff --git a/tests/Exception/OAuthServerExceptionTest.php b/tests/Exception/OAuthServerExceptionTest.php index 7ece08032..38b86d433 100644 --- a/tests/Exception/OAuthServerExceptionTest.php +++ b/tests/Exception/OAuthServerExceptionTest.php @@ -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()); + } } diff --git a/tests/Grant/PasswordGrantTest.php b/tests/Grant/PasswordGrantTest.php index 0be3d4826..b53ab2357 100644 --- a/tests/Grant/PasswordGrantTest.php +++ b/tests/Grant/PasswordGrantTest.php @@ -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')); }