Skip to content

Commit 0c86312

Browse files
authored
Merge pull request #1230 from marc-mabe/user-credentials-error
Respond with helpful and spec complient error on invalid user credentials
2 parents dc7fa33 + 3e31fe9 commit 0c86312

File tree

4 files changed

+10
-3
lines changed

4 files changed

+10
-3
lines changed

src/Exception/OAuthServerException.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -189,7 +189,7 @@ public static function invalidScope($scope, $redirectUri = null)
189189
*/
190190
public static function invalidCredentials()
191191
{
192-
return new static('The user credentials were incorrect.', 6, 'invalid_credentials', 401);
192+
return new static('The user credentials were incorrect.', 6, 'invalid_grant', 400);
193193
}
194194

195195
/**

src/Grant/PasswordGrant.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ protected function validateUser(ServerRequestInterface $request, ClientEntityInt
106106
if ($user instanceof UserEntityInterface === false) {
107107
$this->getEmitter()->emit(new RequestEvent(RequestEvent::USER_AUTHENTICATION_FAILED, $request));
108108

109-
throw OAuthServerException::invalidGrant();
109+
throw OAuthServerException::invalidCredentials();
110110
}
111111

112112
return $user;

tests/Exception/OAuthServerExceptionTest.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -137,4 +137,11 @@ public function testCanGetRedirectionUri()
137137

138138
$this->assertSame('https://example.com/error', $exceptionWithRedirect->getRedirectUri());
139139
}
140+
141+
public function testInvalidCredentialsIsInvalidGrant()
142+
{
143+
$exception = OAuthServerException::invalidCredentials();
144+
145+
$this->assertSame('invalid_grant', $exception->getErrorType());
146+
}
140147
}

tests/Grant/PasswordGrantTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -211,7 +211,7 @@ public function testRespondToRequestBadCredentials()
211211
$responseType = new StubResponseType();
212212

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

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

0 commit comments

Comments
 (0)