Skip to content

Commit d7650fb

Browse files
committed
Fix QA PHPStan findings in OAuth examples and auth middleware
1 parent ba5ef52 commit d7650fb

File tree

3 files changed

+16
-8
lines changed

3 files changed

+16
-8
lines changed

examples/server/oauth-keycloak/McpElements.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,8 @@ final class McpElements
3030
* Confirms the user is authenticated.
3131
*
3232
* The fact that this tool executes means the request passed OAuth validation.
33+
*
34+
* @return array<string, mixed>
3335
*/
3436
#[McpTool(
3537
name: 'get_auth_status',
@@ -65,6 +67,8 @@ public function getAuthStatus(RequestContext $context): array
6567

6668
/**
6769
* Simulates calling a protected external API.
70+
*
71+
* @return array<string, mixed>
6872
*/
6973
#[McpTool(
7074
name: 'call_protected_api',
@@ -91,6 +95,8 @@ public function callProtectedApi(
9195

9296
/**
9397
* Returns the current server time and status.
98+
*
99+
* @return array<string, mixed>
94100
*/
95101
#[McpResource(
96102
uri: 'server://status',

examples/server/oauth-microsoft/McpElements.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,8 @@ final class McpElements
2828
{
2929
/**
3030
* Confirms the user is authenticated with Microsoft.
31+
*
32+
* @return array<string, mixed>
3133
*/
3234
#[McpTool(
3335
name: 'get_auth_status',
@@ -64,6 +66,8 @@ public function getAuthStatus(RequestContext $context): array
6466

6567
/**
6668
* Simulates calling Microsoft Graph API.
69+
*
70+
* @return array<string, mixed>
6771
*/
6872
#[McpTool(
6973
name: 'call_graph_api',
@@ -89,6 +93,8 @@ public function callGraphApi(
8993

9094
/**
9195
* Lists simulated emails.
96+
*
97+
* @return array<string, mixed>
9298
*/
9399
#[McpTool(
94100
name: 'list_emails',
@@ -109,6 +115,8 @@ public function listEmails(int $count = 5): array
109115

110116
/**
111117
* Returns the current server status.
118+
*
119+
* @return array<string, mixed>
112120
*/
113121
#[McpResource(
114122
uri: 'server://status',

src/Server/Transport/Http/Middleware/AuthorizationMiddleware.php

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -79,14 +79,12 @@ private function buildErrorResponse(ServerRequestInterface $request, Authorizati
7979
$response = $this->responseFactory->createResponse($result->getStatusCode());
8080
$header = $this->buildAuthenticateHeader($request, $result);
8181

82-
if (null !== $header) {
83-
$response = $response->withHeader('WWW-Authenticate', $header);
84-
}
82+
$response = $response->withHeader('WWW-Authenticate', $header);
8583

8684
return $response;
8785
}
8886

89-
private function buildAuthenticateHeader(ServerRequestInterface $request, AuthorizationResult $result): ?string
87+
private function buildAuthenticateHeader(ServerRequestInterface $request, AuthorizationResult $result): string
9088
{
9189
$parts = [];
9290

@@ -105,10 +103,6 @@ private function buildAuthenticateHeader(ServerRequestInterface $request, Author
105103
$parts[] = 'error_description="'.$this->escapeHeaderValue($result->getErrorDescription()).'"';
106104
}
107105

108-
if ([] === $parts) {
109-
return 'Bearer';
110-
}
111-
112106
return 'Bearer '.implode(', ', $parts);
113107
}
114108

0 commit comments

Comments
 (0)