mirror of
https://github.com/elyby/oauth2-server.git
synced 2025-05-31 14:12:07 +05:30
Compare commits
4 Commits
adaptation
...
abstract_c
Author | SHA1 | Date | |
---|---|---|---|
|
4ab302a969 | ||
|
d40a37570c | ||
|
01d652ab29 | ||
|
f604109168 |
@@ -6,6 +6,9 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
|
||||
|
||||
## [Unreleased]
|
||||
|
||||
### Added (v9)
|
||||
- A CryptKeyInterface to allow developers to change the CryptKey implementation with greater ease (PR #1044)
|
||||
|
||||
### Fixed
|
||||
- Clients are now explicitly prevented from using the Client Credentials grant unless they are confidential to conform
|
||||
with the OAuth2 spec (PR #1035)
|
||||
|
@@ -101,12 +101,18 @@ class CryptKey implements CryptKeyInterface
|
||||
return 'file://' . $keyPath;
|
||||
}
|
||||
|
||||
public function getKeyPath(): string
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getKeyPath()
|
||||
{
|
||||
return $this->keyPath;
|
||||
}
|
||||
|
||||
public function getPassPhrase(): ?string
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getPassPhrase()
|
||||
{
|
||||
return $this->passPhrase;
|
||||
}
|
||||
|
@@ -1,5 +1,4 @@
|
||||
<?php
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace League\OAuth2\Server;
|
||||
|
||||
@@ -10,12 +9,12 @@ interface CryptKeyInterface
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getKeyPath(): string;
|
||||
public function getKeyPath();
|
||||
|
||||
/**
|
||||
* Retrieve key pass phrase.
|
||||
*
|
||||
* @return null|string
|
||||
*/
|
||||
public function getPassPhrase(): ?string;
|
||||
public function getPassPhrase();
|
||||
}
|
||||
|
@@ -294,9 +294,14 @@ class OAuthServerException extends Exception
|
||||
|
||||
$payload = $this->getPayload();
|
||||
|
||||
$redirectUri = $this->getRedirectUri($useFragment);
|
||||
if ($redirectUri !== null) {
|
||||
return $response->withStatus(302)->withHeader('Location', $redirectUri);
|
||||
if ($this->redirectUri !== null) {
|
||||
if ($useFragment === true) {
|
||||
$this->redirectUri .= (strstr($this->redirectUri, '#') === false) ? '#' : '&';
|
||||
} else {
|
||||
$this->redirectUri .= (strstr($this->redirectUri, '?') === false) ? '?' : '&';
|
||||
}
|
||||
|
||||
return $response->withStatus(302)->withHeader('Location', $this->redirectUri . http_build_query($payload));
|
||||
}
|
||||
|
||||
foreach ($headers as $header => $content) {
|
||||
@@ -354,31 +359,6 @@ class OAuthServerException extends Exception
|
||||
return $this->redirectUri !== null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the redirectUri with all necessary args.
|
||||
*
|
||||
* Null will be returned if the exception doesn't contain the redirectUri.
|
||||
*
|
||||
* @param bool $useFragment True if errors should be in the URI fragment instead of query string
|
||||
*
|
||||
* @return string|null
|
||||
*/
|
||||
public function getRedirectUri(bool $useFragment = false): ?string
|
||||
{
|
||||
if ($this->redirectUri === null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
$redirectUri = $this->redirectUri;
|
||||
if ($useFragment) {
|
||||
$redirectUri .= strpos($this->redirectUri, '#') === false ? '#' : '&';
|
||||
} else {
|
||||
$redirectUri .= strpos($this->redirectUri, '?') === false ? '?' : '&';
|
||||
}
|
||||
|
||||
return $redirectUri . http_build_query($this->getPayload());
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the HTTP status code to send when the exceptions is output.
|
||||
*
|
||||
|
@@ -4,6 +4,7 @@ namespace LeagueTests;
|
||||
|
||||
use DateInterval;
|
||||
use League\OAuth2\Server\AuthorizationServer;
|
||||
use League\OAuth2\Server\CryptKeyInterface;
|
||||
use League\OAuth2\Server\Exception\OAuthServerException;
|
||||
use League\OAuth2\Server\Grant\AuthCodeGrant;
|
||||
use League\OAuth2\Server\Grant\ClientCredentialsGrant;
|
||||
@@ -152,7 +153,7 @@ class AuthorizationServerTest extends TestCase
|
||||
$encryptionKey = 'file://' . __DIR__ . '/Stubs/public.key';
|
||||
|
||||
$responseTypePrototype = new class extends BearerTokenResponse {
|
||||
/* @return null|\League\OAuth2\Server\CryptKeyInterface */
|
||||
/* @return null|CryptKeyInterface */
|
||||
public function getPrivateKey()
|
||||
{
|
||||
return $this->privateKey;
|
||||
|
@@ -71,14 +71,6 @@ class OAuthServerExceptionTest extends TestCase
|
||||
$exceptionWithRedirect = OAuthServerException::accessDenied('some hint', 'https://example.com/error');
|
||||
|
||||
$this->assertTrue($exceptionWithRedirect->hasRedirect());
|
||||
$this->assertSame(
|
||||
'https://example.com/error?error=access_denied&error_description=The+resource+owner+or+authorization+server+denied+the+request.&hint=some+hint&message=The+resource+owner+or+authorization+server+denied+the+request.',
|
||||
$exceptionWithRedirect->getRedirectUri()
|
||||
);
|
||||
$this->assertSame(
|
||||
'https://example.com/error#error=access_denied&error_description=The+resource+owner+or+authorization+server+denied+the+request.&hint=some+hint&message=The+resource+owner+or+authorization+server+denied+the+request.',
|
||||
$exceptionWithRedirect->getRedirectUri(true)
|
||||
);
|
||||
}
|
||||
|
||||
public function testDoesNotHaveRedirect()
|
||||
@@ -86,7 +78,6 @@ class OAuthServerExceptionTest extends TestCase
|
||||
$exceptionWithoutRedirect = OAuthServerException::accessDenied('Some hint');
|
||||
|
||||
$this->assertFalse($exceptionWithoutRedirect->hasRedirect());
|
||||
$this->assertNull($exceptionWithoutRedirect->getRedirectUri());
|
||||
}
|
||||
|
||||
public function testHasPrevious()
|
||||
|
Reference in New Issue
Block a user