mirror of
https://github.com/elyby/oauth2-server.git
synced 2024-12-22 13:09:44 +05:30
Extract validateRedirectUri()
This commit is contained in:
parent
0d20c755d4
commit
a31bc7d4cc
@ -193,25 +193,45 @@ abstract class AbstractGrant implements GrantTypeInterface
|
|||||||
throw OAuthServerException::invalidClient();
|
throw OAuthServerException::invalidClient();
|
||||||
}
|
}
|
||||||
|
|
||||||
// If a redirect URI is provided ensure it matches what is pre-registered
|
|
||||||
$redirectUri = $this->getRequestParameter('redirect_uri', $request, null);
|
$redirectUri = $this->getRequestParameter('redirect_uri', $request, null);
|
||||||
|
|
||||||
if ($redirectUri !== null) {
|
if ($redirectUri !== null) {
|
||||||
if (is_string($client->getRedirectUri())
|
$this->validateRedirectUri($redirectUri, $client, $request);
|
||||||
&& (strcmp($client->getRedirectUri(), $redirectUri) !== 0)
|
|
||||||
) {
|
|
||||||
$this->getEmitter()->emit(new RequestEvent(RequestEvent::CLIENT_AUTHENTICATION_FAILED, $request));
|
|
||||||
throw OAuthServerException::invalidClient();
|
|
||||||
} elseif (is_array($client->getRedirectUri())
|
|
||||||
&& in_array($redirectUri, $client->getRedirectUri(), true) === false
|
|
||||||
) {
|
|
||||||
$this->getEmitter()->emit(new RequestEvent(RequestEvent::CLIENT_AUTHENTICATION_FAILED, $request));
|
|
||||||
throw OAuthServerException::invalidClient();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return $client;
|
return $client;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Validate redirectUri from the request.
|
||||||
|
* If a redirect URI is provided ensure it matches what is pre-registered
|
||||||
|
*
|
||||||
|
* @param string $redirectUri
|
||||||
|
* @param ClientEntityInterface $client
|
||||||
|
* @param ServerRequestInterface $request
|
||||||
|
*
|
||||||
|
* @throws OAuthServerException
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
protected function validateRedirectUri(
|
||||||
|
string $redirectUri,
|
||||||
|
ClientEntityInterface $client,
|
||||||
|
ServerRequestInterface $request
|
||||||
|
) {
|
||||||
|
if (is_string($client->getRedirectUri())
|
||||||
|
&& (strcmp($client->getRedirectUri(), $redirectUri) !== 0)
|
||||||
|
) {
|
||||||
|
$this->getEmitter()->emit(new RequestEvent(RequestEvent::CLIENT_AUTHENTICATION_FAILED, $request));
|
||||||
|
throw OAuthServerException::invalidClient();
|
||||||
|
} elseif (is_array($client->getRedirectUri())
|
||||||
|
&& in_array($redirectUri, $client->getRedirectUri(), true) === false
|
||||||
|
) {
|
||||||
|
$this->getEmitter()->emit(new RequestEvent(RequestEvent::CLIENT_AUTHENTICATION_FAILED, $request));
|
||||||
|
throw OAuthServerException::invalidClient();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Validate scopes in the request.
|
* Validate scopes in the request.
|
||||||
*
|
*
|
||||||
|
@ -242,19 +242,7 @@ class AuthCodeGrant extends AbstractAuthorizeGrant
|
|||||||
$redirectUri = $this->getQueryStringParameter('redirect_uri', $request);
|
$redirectUri = $this->getQueryStringParameter('redirect_uri', $request);
|
||||||
|
|
||||||
if ($redirectUri !== null) {
|
if ($redirectUri !== null) {
|
||||||
if (
|
$this->validateRedirectUri($redirectUri, $client, $request);
|
||||||
is_string($client->getRedirectUri())
|
|
||||||
&& (strcmp($client->getRedirectUri(), $redirectUri) !== 0)
|
|
||||||
) {
|
|
||||||
$this->getEmitter()->emit(new RequestEvent(RequestEvent::CLIENT_AUTHENTICATION_FAILED, $request));
|
|
||||||
throw OAuthServerException::invalidClient();
|
|
||||||
} elseif (
|
|
||||||
is_array($client->getRedirectUri())
|
|
||||||
&& in_array($redirectUri, $client->getRedirectUri(), true) === false
|
|
||||||
) {
|
|
||||||
$this->getEmitter()->emit(new RequestEvent(RequestEvent::CLIENT_AUTHENTICATION_FAILED, $request));
|
|
||||||
throw OAuthServerException::invalidClient();
|
|
||||||
}
|
|
||||||
} elseif (is_array($client->getRedirectUri()) && count($client->getRedirectUri()) !== 1
|
} elseif (is_array($client->getRedirectUri()) && count($client->getRedirectUri()) !== 1
|
||||||
|| empty($client->getRedirectUri())) {
|
|| empty($client->getRedirectUri())) {
|
||||||
$this->getEmitter()->emit(new RequestEvent(RequestEvent::CLIENT_AUTHENTICATION_FAILED, $request));
|
$this->getEmitter()->emit(new RequestEvent(RequestEvent::CLIENT_AUTHENTICATION_FAILED, $request));
|
||||||
|
@ -138,19 +138,7 @@ class ImplicitGrant extends AbstractAuthorizeGrant
|
|||||||
$redirectUri = $this->getQueryStringParameter('redirect_uri', $request);
|
$redirectUri = $this->getQueryStringParameter('redirect_uri', $request);
|
||||||
|
|
||||||
if ($redirectUri !== null) {
|
if ($redirectUri !== null) {
|
||||||
if (
|
$this->validateRedirectUri($redirectUri, $client, $request);
|
||||||
is_string($client->getRedirectUri())
|
|
||||||
&& (strcmp($client->getRedirectUri(), $redirectUri) !== 0)
|
|
||||||
) {
|
|
||||||
$this->getEmitter()->emit(new RequestEvent(RequestEvent::CLIENT_AUTHENTICATION_FAILED, $request));
|
|
||||||
throw OAuthServerException::invalidClient();
|
|
||||||
} elseif (
|
|
||||||
is_array($client->getRedirectUri())
|
|
||||||
&& in_array($redirectUri, $client->getRedirectUri(), true) === false
|
|
||||||
) {
|
|
||||||
$this->getEmitter()->emit(new RequestEvent(RequestEvent::CLIENT_AUTHENTICATION_FAILED, $request));
|
|
||||||
throw OAuthServerException::invalidClient();
|
|
||||||
}
|
|
||||||
} elseif (is_array($client->getRedirectUri()) && count($client->getRedirectUri()) !== 1
|
} elseif (is_array($client->getRedirectUri()) && count($client->getRedirectUri()) !== 1
|
||||||
|| empty($client->getRedirectUri())) {
|
|| empty($client->getRedirectUri())) {
|
||||||
$this->getEmitter()->emit(new RequestEvent(RequestEvent::CLIENT_AUTHENTICATION_FAILED, $request));
|
$this->getEmitter()->emit(new RequestEvent(RequestEvent::CLIENT_AUTHENTICATION_FAILED, $request));
|
||||||
|
Loading…
Reference in New Issue
Block a user