Skip to content

Commit 803137d

Browse files
authored
Merge pull request #14 from flownative/bugfix-authorization-reuse-0.x
Hotfix: generate random authorization id for authorization code flows
2 parents 60c9401 + 82df385 commit 803137d

File tree

2 files changed

+14
-1
lines changed

2 files changed

+14
-1
lines changed

Classes/Authorization.php

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
use League\OAuth2\Client\Token\AccessToken;
1818
use League\OAuth2\Client\Token\AccessTokenInterface;
1919
use Neos\Flow\Annotations as Flow;
20+
use Ramsey\Uuid\Uuid;
2021

2122
/**
2223
* An OAuth2 Authorization
@@ -71,6 +72,7 @@ class Authorization
7172
* @param string $clientId
7273
* @param string $grantType
7374
* @param string $scope
75+
* @throws OAuthClientException
7476
*/
7577
public function __construct(string $serviceName, string $clientId, string $grantType, string $scope)
7678
{
@@ -89,9 +91,19 @@ public function __construct(string $serviceName, string $clientId, string $grant
8991
* @param string $grantType
9092
* @param string $scope
9193
* @return string
94+
* @throws OAuthClientException
9295
*/
9396
public static function calculateAuthorizationId(string $serviceName, string $clientId, string $grantType, string $scope): string
9497
{
98+
// Hotfix: An authorization using Authorization Code Flow must not be deterministic.
99+
// This is properly implemented and solved in the 2.x branch of this package
100+
if ($scope === self::GRANT_AUTHORIZATION_CODE) {
101+
try {
102+
return $serviceName . '-' . $clientId . '-' . Uuid::uuid4()->toString();
103+
} catch (\Exception $e) {
104+
throw new OAuthClientException(sprintf('Failed generating authorization id for %s %s', $serviceName, $clientId), 1597311416, $e);
105+
}
106+
}
95107
return sha1($serviceName . $clientId . $grantType . $scope);
96108
}
97109

composer.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,8 @@
1717
"require": {
1818
"neos/flow": "^4.0 || ^5.0 || ^6.0 || dev-master",
1919
"guzzlehttp/guzzle": "6.3.*",
20-
"league/oauth2-client": "2.*"
20+
"league/oauth2-client": "2.*",
21+
"ramsey/uuid": "^3.0 || ^4.0"
2122
},
2223
"autoload": {
2324
"psr-4": {

0 commit comments

Comments
 (0)