Skip to content

Commit 63f530b

Browse files
author
Shilen Patel
committed
Updated to log the id token during token requests and logout error with the id token hint
1 parent 2e597c8 commit 63f530b

File tree

5 files changed

+25
-3
lines changed

5 files changed

+25
-3
lines changed

lib/Controller/LogoutController.php

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -144,13 +144,24 @@ public function __invoke(ServerRequest $request): Response
144144

145145
return $this->resolveResponse($logoutRequest, $wasLogoutActionCalled);
146146
} catch (Exception $e) {
147+
$requestMethod = strtoupper($request->getMethod());
148+
$idTokenHintParam = '';
149+
if ($requestMethod === 'GET') {
150+
$idTokenHintParam = $request->getQueryParams()['id_token_hint'] ?? '';
151+
} elseif ($requestMethod === 'POST') {
152+
if (is_array($parsedBody = $request->getParsedBody())) {
153+
$idTokenHintParam = $parsedBody['id_token_hint'] ?? '';
154+
}
155+
}
156+
147157
MetricLogger::getInstance()->logMetric(
148158
'oidc',
149159
'error',
150160
[
151161
'message' => $e->getMessage(),
152162
'oidc' => [
153163
'endpoint' => 'logout',
164+
'idTokenHint' => $idTokenHintParam
154165
]
155166

156167
]

lib/Controller/OAuth2AccessTokenController.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,6 @@ public function __invoke(ServerRequest $request): \Psr\Http\Message\ResponseInte
6464
try {
6565
return $this->authorizationServer->respondToAccessTokenRequest($request, new Response());
6666
} catch (Exception $e) {
67-
// TODO log anything else?
6867
MetricLogger::getInstance()->logMetric(
6968
'oidc',
7069
'error',

lib/Controller/OpenIdConnectUserInfoController.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,6 @@ public function __invoke(ServerRequest $request): Response
128128

129129
return new JsonResponse($claims);
130130
} catch (Exception $e) {
131-
// TODO log anything else? Assume the token is passed through the authorization header? OK to log that, or a prefix if there's no sensitive data there, or a hash of it?
132131
MetricLogger::getInstance()->logMetric(
133132
'oidc',
134133
'error',

lib/Server/Grants/AuthCodeGrant.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -481,9 +481,10 @@ public function respondToAccessTokenRequest(
481481
'token',
482482
[
483483
'authCodeId' => $authCodePayload->auth_code_id,
484+
'sub' => $authCodePayload->user_id,
485+
'scopes' => $scopes,
484486
'grantType' => $this->getIdentifier(),
485487
'clientId' => $client->getIdentifier(),
486-
'sub' => $authCodePayload->user_id
487488
]
488489
);
489490

lib/Server/ResponseTypes/IdTokenResponse.php

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414

1515
namespace SimpleSAML\Module\oidc\Server\ResponseTypes;
1616

17+
use CirrusIdentity\SSP\Utils\MetricLogger;
1718
use Exception;
1819
use League\OAuth2\Server\Entities\AccessTokenEntityInterface;
1920
use League\OAuth2\Server\Entities\ScopeEntityInterface;
@@ -102,6 +103,17 @@ protected function getExtraParams(AccessTokenEntityInterface $accessToken): arra
102103
$this->getSessionId()
103104
);
104105

106+
MetricLogger::getInstance()->logMetric(
107+
'oidc',
108+
'idToken',
109+
[
110+
'idTokenClaims' => array_keys($token->claims()->all()),
111+
'sub' => $token->claims()->get("sub"),
112+
'scopes' => $accessToken->getScopes(),
113+
'clientId' => $accessToken->getClient()->getIdentifier()
114+
]
115+
);
116+
105117
return [
106118
'id_token' => $token->toString(),
107119
];

0 commit comments

Comments
 (0)