Compare commits

..

4 Commits

Author SHA1 Message Date
ErickSkrauch
08e470e81a Merge branch 'export_redirect_uri' into adaptation 2019-08-23 00:17:49 +03:00
ErickSkrauch
677c10a61d Add tests 2019-08-23 00:15:10 +03:00
ErickSkrauch
3684a76ade Add getter for the OAuthServerException::redirectUri param and make it public 2019-08-23 00:00:15 +03:00
ErickSkrauch
a777ca2adc Merge branch 'abstract_crypt_key' into adaptation 2019-08-18 01:13:35 +03:00
6 changed files with 43 additions and 23 deletions

View File

@@ -6,9 +6,6 @@ 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)

View File

@@ -101,18 +101,12 @@ class CryptKey implements CryptKeyInterface
return 'file://' . $keyPath;
}
/**
* {@inheritdoc}
*/
public function getKeyPath()
public function getKeyPath(): string
{
return $this->keyPath;
}
/**
* {@inheritdoc}
*/
public function getPassPhrase()
public function getPassPhrase(): ?string
{
return $this->passPhrase;
}

View File

@@ -1,4 +1,5 @@
<?php
declare(strict_types=1);
namespace League\OAuth2\Server;
@@ -9,12 +10,12 @@ interface CryptKeyInterface
*
* @return string
*/
public function getKeyPath();
public function getKeyPath(): string;
/**
* Retrieve key pass phrase.
*
* @return null|string
*/
public function getPassPhrase();
public function getPassPhrase(): ?string;
}

View File

@@ -294,14 +294,9 @@ class OAuthServerException extends Exception
$payload = $this->getPayload();
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));
$redirectUri = $this->getRedirectUri($useFragment);
if ($redirectUri !== null) {
return $response->withStatus(302)->withHeader('Location', $redirectUri);
}
foreach ($headers as $header => $content) {
@@ -359,6 +354,31 @@ 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.
*

View File

@@ -4,7 +4,6 @@ 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;
@@ -153,7 +152,7 @@ class AuthorizationServerTest extends TestCase
$encryptionKey = 'file://' . __DIR__ . '/Stubs/public.key';
$responseTypePrototype = new class extends BearerTokenResponse {
/* @return null|CryptKeyInterface */
/* @return null|\League\OAuth2\Server\CryptKeyInterface */
public function getPrivateKey()
{
return $this->privateKey;

View File

@@ -71,6 +71,14 @@ 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()
@@ -78,6 +86,7 @@ class OAuthServerExceptionTest extends TestCase
$exceptionWithoutRedirect = OAuthServerException::accessDenied('Some hint');
$this->assertFalse($exceptionWithoutRedirect->hasRedirect());
$this->assertNull($exceptionWithoutRedirect->getRedirectUri());
}
public function testHasPrevious()