Skip to content

Commit e07c183

Browse files
committed
add hint to error logs
1 parent 01537cf commit e07c183

File tree

3 files changed

+20
-3
lines changed

3 files changed

+20
-3
lines changed

lib/Controller/OAuth2AccessTokenController.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ public function __invoke(ServerRequest $request): \Psr\Http\Message\ResponseInte
5353
'errorDescription' => $e->getPayload()["error_description"],
5454
'oidc' => [
5555
'endpoint' => 'token',
56+
'hint' => $e->getHint(),
5657
]
5758
]
5859
);
@@ -64,13 +65,18 @@ public function __invoke(ServerRequest $request): \Psr\Http\Message\ResponseInte
6465
try {
6566
return $this->authorizationServer->respondToAccessTokenRequest($request, new Response());
6667
} catch (Exception $e) {
68+
$hint = null;
69+
if ($e instanceof OidcServerException) {
70+
$hint = $e->getHint();
71+
}
6772
MetricLogger::getInstance()->logMetric(
6873
'oidc',
6974
'error',
7075
[
7176
'message' => $e->getMessage(),
7277
'oidc' => [
7378
'endpoint' => 'token',
79+
'hint' => $hint,
7480
'clientId' => $this->getClientIdFromTokenRequest($request),
7581
'grantType' => $this->getRequestParameter("grant_type", $request)
7682
]

lib/Controller/OAuth2AuthorizationController.php

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -87,16 +87,21 @@ public function __invoke(ServerRequest $request): ResponseInterface
8787
} catch (Exception $e) {
8888
if (!($e instanceof BadRequest)) {
8989
$queryParams = $request->getQueryParams();
90-
$scope = $queryParams['scope'];
90+
$scope = $queryParams['scope'] ?? "";
91+
$hint = null;
92+
if ($e instanceof OidcServerException) {
93+
$hint = $e->getHint();
94+
}
9195
MetricLogger::getInstance()->logMetric(
9296
'oidc',
9397
'error',
9498
[
9599
'message' => $e->getMessage(),
96-
'clientId' => $queryParams['client_id'],
100+
'clientId' => $queryParams['client_id'] ?? null,
97101
'scopes' => ($scope === null || $scope === "") ? [] : explode(" ", $scope),
98102
'oidc' => [
99103
'endpoint' => 'authorize',
104+
'hint' => $hint,
100105
]
101106
// authorize endpoint doesn't contain secrets so okay to log all params
102107
+ $queryParams

lib/Controller/OpenIdConnectUserInfoController.php

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,7 @@ public function __invoke(ServerRequest $request): Response
8787
'errorDescription' => $e->getPayload()["error_description"],
8888
'oidc' => [
8989
'endpoint' => 'userinfo',
90+
'hint' => $e->getHint(),
9091
]
9192
]
9293
);
@@ -128,14 +129,19 @@ public function __invoke(ServerRequest $request): Response
128129

129130
return new JsonResponse($claims);
130131
} catch (Exception $e) {
132+
$hint = null;
133+
if ($e instanceof OidcServerException) {
134+
$hint = $e->getHint();
135+
}
131136
MetricLogger::getInstance()->logMetric(
132137
'oidc',
133138
'error',
134139
[
135140
'message' => $e->getMessage(),
136141
'oidc' => [
137142
'endpoint' => 'userinfo',
138-
'tokenId' => $tokenId
143+
'tokenId' => $tokenId,
144+
'hint' => $hint,
139145
]
140146

141147
]

0 commit comments

Comments
 (0)