Skip to content

Commit 7b65618

Browse files
authored
Merge pull request #1402 from thephpleague/fix-passport-compatibility
Fix Passport Compatibility for V9
2 parents f7a19cd + 26b33a6 commit 7b65618

28 files changed

+163
-115
lines changed

CHANGELOG.md

+3
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,9 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
88
### Fixed
99
- Basic authorization is now case insensitive (PR #1403)
1010

11+
### Changed
12+
- Request parameters are now parsed into strings to use internally in the library (PR #1402)
13+
1114
## [9.0.0-RC1] - released 2024-03-27
1215
### Added
1316
- Device Authorization Grant added (PR #1074)

examples/src/Entities/UserEntity.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,8 @@ class UserEntity implements UserEntityInterface
1919
/**
2020
* Return the user's identifier.
2121
*/
22-
public function getIdentifier(): mixed
22+
public function getIdentifier(): string
2323
{
24-
return 1;
24+
return '1';
2525
}
2626
}

phpcs.xml.dist

+2
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@
1414
<file>tests</file>
1515
<file>examples</file>
1616

17+
<exclude-pattern>examples/vendor/*</exclude-pattern>
18+
1719
<rule ref="PSR12">
1820
<exclude name="Generic.Files.LineLength.TooLong" />
1921
</rule>

phpstan.neon.dist

+1-5
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,4 @@ parameters:
22
level: 8
33
paths:
44
- src
5-
- tests
6-
ignoreErrors:
7-
-
8-
message: '#Call to an undefined method League\\OAuth2\\Server\\ResponseTypes\\ResponseTypeInterface::getAccessToken\(\)\.#'
9-
path: tests/Grant/ClientCredentialsGrantTest.php
5+
- tests

src/CryptKey.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -43,13 +43,13 @@ class CryptKey implements CryptKeyInterface
4343

4444
public function __construct(string $keyPath, protected ?string $passPhrase = null, bool $keyPermissionsCheck = true)
4545
{
46-
if (strpos($keyPath, self::FILE_PREFIX) !== 0 && $this->isValidKey($keyPath, $this->passPhrase ?? '')) {
46+
if (str_starts_with($keyPath, self::FILE_PREFIX) === false && $this->isValidKey($keyPath, $this->passPhrase ?? '')) {
4747
$this->keyContents = $keyPath;
4848
$this->keyPath = '';
4949
// There's no file, so no need for permission check.
5050
$keyPermissionsCheck = false;
5151
} elseif (is_file($keyPath)) {
52-
if (strpos($keyPath, self::FILE_PREFIX) !== 0) {
52+
if (str_starts_with($keyPath, self::FILE_PREFIX) === false) {
5353
$keyPath = self::FILE_PREFIX . $keyPath;
5454
}
5555

src/Entities/RefreshTokenEntityInterface.php

+5-1
Original file line numberDiff line numberDiff line change
@@ -18,13 +18,17 @@ interface RefreshTokenEntityInterface
1818
{
1919
/**
2020
* Get the token's identifier.
21+
*
22+
* @return non-empty-string
2123
*/
2224
public function getIdentifier(): string;
2325

2426
/**
2527
* Set the token's identifier.
28+
*
29+
* @param non-empty-string $identifier
2630
*/
27-
public function setIdentifier(mixed $identifier): void;
31+
public function setIdentifier(string $identifier): void;
2832

2933
/**
3034
* Get the token's expiry date time.

src/Entities/ScopeEntityInterface.php

+2
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@ interface ScopeEntityInterface extends JsonSerializable
1818
{
1919
/**
2020
* Get the scope's identifier.
21+
*
22+
* @return non-empty-string
2123
*/
2224
public function getIdentifier(): string;
2325
}

src/Entities/TokenInterface.php

+8-2
Original file line numberDiff line numberDiff line change
@@ -18,13 +18,17 @@ interface TokenInterface
1818
{
1919
/**
2020
* Get the token's identifier.
21+
*
22+
* @return non-empty-string
2123
*/
2224
public function getIdentifier(): string;
2325

2426
/**
2527
* Set the token's identifier.
28+
*
29+
* @param non-empty-string $identifier
2630
*/
27-
public function setIdentifier(mixed $identifier): void;
31+
public function setIdentifier(string $identifier): void;
2832

2933
/**
3034
* Get the token's expiry date time.
@@ -45,8 +49,10 @@ public function setUserIdentifier(string $identifier): void;
4549

4650
/**
4751
* Get the token user's identifier.
52+
*
53+
* @return non-empty-string|null
4854
*/
49-
public function getUserIdentifier(): string|int|null;
55+
public function getUserIdentifier(): string|null;
5056

5157
/**
5258
* Get the client that the token was issued to.

src/Entities/Traits/DeviceCodeTrait.php

+3
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,9 @@ abstract public function getExpiryDateTime(): DateTimeImmutable;
5959
*/
6060
abstract public function getScopes(): array;
6161

62+
/**
63+
* @return non-empty-string
64+
*/
6265
abstract public function getIdentifier(): string;
6366

6467
public function getLastPolledAt(): ?DateTimeImmutable

src/Entities/Traits/EntityTrait.php

+4-1
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,10 @@ public function getIdentifier(): string
2727
return $this->identifier;
2828
}
2929

30-
public function setIdentifier(mixed $identifier): void
30+
/**
31+
* @param non-empty-string $identifier
32+
*/
33+
public function setIdentifier(string $identifier): void
3134
{
3235
$this->identifier = $identifier;
3336
}

src/Entities/UserEntityInterface.php

+3-1
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@ interface UserEntityInterface
1616
{
1717
/**
1818
* Return the user's identifier.
19+
*
20+
* @return non-empty-string
1921
*/
20-
public function getIdentifier(): mixed;
22+
public function getIdentifier(): string;
2123
}

src/Exception/OAuthServerException.php

+3-3
Original file line numberDiff line numberDiff line change
@@ -269,9 +269,9 @@ public function generateHttpResponse(ResponseInterface $response, bool $useFragm
269269

270270
if ($this->redirectUri !== null) {
271271
if ($useFragment === true) {
272-
$this->redirectUri .= (strstr($this->redirectUri, '#') === false) ? '#' : '&';
272+
$this->redirectUri .= (str_contains($this->redirectUri, '#') === false) ? '#' : '&';
273273
} else {
274-
$this->redirectUri .= (strstr($this->redirectUri, '?') === false) ? '?' : '&';
274+
$this->redirectUri .= (str_contains($this->redirectUri, '?') === false) ? '?' : '&';
275275
}
276276

277277
return $response->withStatus(302)->withHeader('Location', $this->redirectUri . http_build_query($payload));
@@ -310,7 +310,7 @@ public function getHttpHeaders(): array
310310
// include the "WWW-Authenticate" response header field
311311
// matching the authentication scheme used by the client.
312312
if ($this->errorType === 'invalid_client' && $this->requestHasAuthorizationHeader()) {
313-
$authScheme = strpos($this->serverRequest->getHeader('Authorization')[0], 'Bearer') === 0 ? 'Bearer' : 'Basic';
313+
$authScheme = str_starts_with($this->serverRequest->getHeader('Authorization')[0], 'Bearer') ? 'Bearer' : 'Basic';
314314

315315
$headers['WWW-Authenticate'] = $authScheme . ' realm="OAuth"';
316316
}

src/Grant/AbstractAuthorizeGrant.php

+2-3
Original file line numberDiff line numberDiff line change
@@ -18,16 +18,15 @@
1818
use League\OAuth2\Server\RequestTypes\AuthorizationRequestInterface;
1919

2020
use function http_build_query;
21-
use function strstr;
2221

2322
abstract class AbstractAuthorizeGrant extends AbstractGrant
2423
{
2524
/**
26-
* @param mixed[] $params
25+
* @param array<array-key,mixed> $params
2726
*/
2827
public function makeRedirectUri(string $uri, array $params = [], string $queryDelimiter = '?'): string
2928
{
30-
$uri .= (strstr($uri, $queryDelimiter) === false) ? $queryDelimiter : '&';
29+
$uri .= str_contains($uri, $queryDelimiter) ? '&' : $queryDelimiter;
3130

3231
return $uri . http_build_query($params);
3332
}

0 commit comments

Comments
 (0)