Compare commits

..

4 Commits

Author SHA1 Message Date
Andrew Millington
4ab302a969 Fix capitalisation of inheritdoc 2019-08-31 19:10:59 +01:00
Andrew Millington
d40a37570c Add inherit docblocks to CryptKey 2019-08-31 19:06:05 +01:00
Andrew Millington
01d652ab29 Remove type hinting 2019-08-31 19:02:39 +01:00
Andrew Millington
f604109168 Update changelog 2019-08-31 18:59:03 +01:00
6 changed files with 23 additions and 43 deletions

View File

@@ -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)

View File

@@ -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;
}

View File

@@ -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();
}

View File

@@ -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.
*

View File

@@ -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;

View File

@@ -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()