Skip to content

Commit 01537cf

Browse files
author
Shilen Patel
committed
Logging changes per Patrick
1 parent f54f80d commit 01537cf

File tree

6 files changed

+22
-2
lines changed

6 files changed

+22
-2
lines changed

lib/Controller/OAuth2AuthorizationController.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,16 +86,20 @@ public function __invoke(ServerRequest $request): ResponseInterface
8686
return $this->authorizationServer->completeAuthorizationRequest($authorizationRequest, new Response());
8787
} catch (Exception $e) {
8888
if (!($e instanceof BadRequest)) {
89+
$queryParams = $request->getQueryParams();
90+
$scope = $queryParams['scope'];
8991
MetricLogger::getInstance()->logMetric(
9092
'oidc',
9193
'error',
9294
[
9395
'message' => $e->getMessage(),
96+
'clientId' => $queryParams['client_id'],
97+
'scopes' => ($scope === null || $scope === "") ? [] : explode(" ", $scope),
9498
'oidc' => [
9599
'endpoint' => 'authorize',
96100
]
97101
// authorize endpoint doesn't contain secrets so okay to log all params
98-
+ $request->getQueryParams()
102+
+ $queryParams
99103
]
100104
);
101105
}

lib/Server/AuthorizationServer.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,16 +76,20 @@ public function validateAuthorizationRequest(ServerRequestInterface $request): O
7676
$resultBag = $this->requestRulesManager->check($request, $rulesToExecute);
7777
} catch (OidcServerException $exception) {
7878
$reason = sprintf("%s %s", $exception->getMessage(), $exception->getHint() ?? '');
79+
$queryParams = $request->getQueryParams();
80+
$scope = $queryParams['scope'];
7981
MetricLogger::getInstance()->logMetric(
8082
'oidc',
8183
'error',
8284
[
8385
'message' => $reason,
86+
'clientId' => $queryParams['client_id'],
87+
'scopes' => ($scope === null || $scope === "") ? [] : explode(" ", $scope),
8488
'oidc' => [
8589
'endpoint' => 'authorize',
8690
]
8791
// authorize endpoint doesn't contain secrets so okay to log all params
88-
+ $request->getQueryParams()
92+
+ $queryParams
8993

9094
]
9195
);

lib/Server/Grants/AuthCodeGrant.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -238,6 +238,7 @@ public function completeOidcAuthorizationRequest(
238238
'authorize',
239239
[
240240
'authCodeId' => $authCode->getIdentifier(),
241+
'sub' => $user->getIdentifier(),
241242
'scopes' => $authCode->getScopes(),
242243
'grantType' => $this->getIdentifier(),
243244
'clientId' => $authCode->getClient()->getIdentifier()
@@ -481,6 +482,7 @@ public function respondToAccessTokenRequest(
481482
'token',
482483
[
483484
'authCodeId' => $authCodePayload->auth_code_id,
485+
'tokenId' => $accessToken->getIdentifier(),
484486
'sub' => $authCodePayload->user_id,
485487
'scopes' => $scopes,
486488
'grantType' => $this->getIdentifier(),

lib/Server/Grants/ImplicitGrant.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -230,6 +230,8 @@ private function completeOidcAuthorizationRequest(AuthorizationRequest $authoriz
230230
'authorize',
231231
[
232232
'idTokenClaims' => array_keys($idToken->claims()->all()),
233+
'idTokenId' => $idToken->claims()->get("jti"),
234+
'tokenId' => $accessToken->getIdentifier(),
233235
'sub' => $idToken->claims()->get("sub"),
234236
'scopes' => $finalizedScopes,
235237
'grantType' => $this->getIdentifier(),

lib/Server/Grants/RefreshTokenGrant.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
use League\OAuth2\Server\ResponseTypes\ResponseTypeInterface;
1111
use Psr\Http\Message\ServerRequestInterface;
1212
use SimpleSAML\Module\oidc\Server\Exceptions\OidcServerException;
13+
use SimpleSAML\Module\oidc\Server\ResponseTypes\IdTokenResponse;
1314

1415
class RefreshTokenGrant extends OAuth2RefreshTokenGrant
1516
{
@@ -62,6 +63,7 @@ public function respondToAccessTokenRequest(
6263
'token',
6364
[
6465
'oldRefreshTokenPrefix' => substr($encryptedRefreshToken, 0, 20),
66+
'tokenId' => $responseType instanceof IdTokenResponse ? $responseType->getTokenId() : null,
6567
'grantType' => $this->getIdentifier(),
6668
'clientId' => $client->getIdentifier()
6769
]

lib/Server/ResponseTypes/IdTokenResponse.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,7 @@ protected function getExtraParams(AccessTokenEntityInterface $accessToken): arra
108108
'idToken',
109109
[
110110
'idTokenClaims' => array_keys($token->claims()->all()),
111+
'idTokenId' => $token->claims()->get("jti"),
111112
'sub' => $token->claims()->get("sub"),
112113
'scopes' => $accessToken->getScopes(),
113114
'clientId' => $accessToken->getClient()->getIdentifier()
@@ -187,4 +188,9 @@ public function setSessionId(?string $sessionId): void
187188
{
188189
$this->sessionId = $sessionId;
189190
}
191+
192+
public function getTokenId(): ?string
193+
{
194+
return $this->accessToken->getIdentifier();
195+
}
190196
}

0 commit comments

Comments
 (0)