|
4 | 4 |
|
5 | 5 | namespace SimpleSAML\Module\oidc\Controllers\OAuth2; |
6 | 6 |
|
| 7 | +use DateTimeImmutable; |
7 | 8 | use Exception; |
8 | 9 | use SimpleSAML\Error\ConfigurationError; |
9 | 10 | use SimpleSAML\Module\oidc\Bridges\OAuth2Bridge; |
10 | 11 | use SimpleSAML\Module\oidc\Codebooks\ApiScopesEnum; |
| 12 | +use SimpleSAML\Module\oidc\Codebooks\FlowTypeEnum; |
11 | 13 | use SimpleSAML\Module\oidc\Entities\AccessTokenEntity; |
12 | 14 | use SimpleSAML\Module\oidc\Entities\UserEntity; |
13 | 15 | use SimpleSAML\Module\oidc\Exceptions\AuthorizationException; |
@@ -339,11 +341,12 @@ protected function resolveAccessTokenPayload( |
339 | 341 | // The user claims of the released scopes, and only of those, so that a scope the decision took away can |
340 | 342 | // not leave its claims behind. They are read from the resource owner's record as it is now: the claims |
341 | 343 | // the UserInfo endpoint releases for the same token, from the same record, so a resource server learns the |
342 | | - // same about the user whichever endpoint it asks. The 'claims' request parameter (OpenID Connect Core 1.0 |
343 | | - // section 5.5) targets the ID token and the UserInfo endpoint and plays no part here, as it plays none in |
344 | | - // the access token's own user claims. Nothing is read from the presented token: it is a snapshot taken |
345 | | - // when it was minted. A released identity claim which is not a non-empty string throws, and is answered |
346 | | - // as the OP's failure. |
| 344 | + // same about the user whichever endpoint it asks. A token of the pre-authorized code flow, which UserInfo |
| 345 | + // refuses, releases the attributes of its Credential Offer instead (resolveResourceOwner()). The 'claims' |
| 346 | + // request parameter (OpenID Connect Core 1.0 section 5.5) targets the ID token and the UserInfo endpoint |
| 347 | + // and plays no part here, as it plays none in the access token's own user claims. Nothing is read from the |
| 348 | + // presented token: it is a snapshot taken when it was minted. A released identity claim which is not a |
| 349 | + // non-empty string throws, and is answered as the OP's failure. |
347 | 350 | $userClaims = $resourceOwner instanceof UserEntity ? |
348 | 351 | $this->claimTranslatorExtractor->extract($releasedScopes, $resourceOwner->getClaims()) : |
349 | 352 | []; |
@@ -399,6 +402,11 @@ protected function resolveDpopJkt(ParsedJws $accessToken): string|false|null |
399 | 402 | /** |
400 | 403 | * The resource owner whose user claims an active access token releases, as their record is now. |
401 | 404 | * |
| 405 | + * A token of the pre-authorized code flow is about the attributes its Credential Offer was made with, which it |
| 406 | + * carries (PreAuthCodeGrant), and never about the claims of the record it names: that may be an existing user's, |
| 407 | + * holding that user's own. Its resource owner is a user built from the offer's attributes; the record still |
| 408 | + * decides whether the user exists. A token stored before tokens carried the attributes releases none. |
| 409 | + * |
402 | 410 | * Null for a token issued without a user (a client credentials token, a pre-authorized code with no holder). |
403 | 411 | * False when the token is not to be reported as active: its own record is gone, or its resource owner's is. The |
404 | 412 | * validator has already looked the token's record up, so the former only happens when the record went between |
@@ -449,7 +457,26 @@ protected function resolveResourceOwner(ParsedJws $accessToken): UserEntity|fals |
449 | 457 | return false; |
450 | 458 | } |
451 | 459 |
|
452 | | - return $user; |
| 460 | + if ($accessTokenEntity->getFlowTypeEnum() !== FlowTypeEnum::VciPreAuthorizedCode) { |
| 461 | + return $user; |
| 462 | + } |
| 463 | + |
| 464 | + $offerClaims = $accessTokenEntity->getOfferClaims(); |
| 465 | + |
| 466 | + if (is_null($offerClaims)) { |
| 467 | + $this->loggerService->warning( |
| 468 | + sprintf( |
| 469 | + 'Access token %s of the pre-authorized code flow carries no Credential Offer attributes (it was ' . |
| 470 | + 'stored before tokens carried them). It releases no user claims.', |
| 471 | + $jti, |
| 472 | + ), |
| 473 | + ); |
| 474 | + } |
| 475 | + |
| 476 | + // A user built from the offer's attributes, which is not stored; the record read above is left as it is. |
| 477 | + $now = new DateTimeImmutable(); |
| 478 | + |
| 479 | + return new UserEntity($userIdentifier, $now, $now, $offerClaims ?? []); |
453 | 480 | } |
454 | 481 |
|
455 | 482 |
|
|
0 commit comments