Skip to content

Commit e0a11f8

Browse files
committed
check resource parameter
1 parent 8a8f0fd commit e0a11f8

File tree

4 files changed

+20
-57
lines changed

4 files changed

+20
-57
lines changed

auth-compat/src/__tests__/basic-compliance.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,8 +63,8 @@ describe('Basic Compliance', () => {
6363
// Verify resource parameter matches PRM exactly
6464
// The PRM always returns http://localhost:{port} as the resource
6565
const expectedResource = `http://localhost:${serverPort}/`;
66-
expect(behavior.resourceParameterUsed).toBe(true);
67-
expect(behavior.resourceParameterValue).toBe(expectedResource);
66+
expect(behavior.authResourceParameter).toBe(expectedResource);
67+
expect(behavior.tokenResourceParameter).toBe(expectedResource);
6868
});
6969
});
7070
});

auth-compat/src/server/auth/index.ts

Lines changed: 12 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,9 @@ export class MockAuthServer implements HttpTraceCollector {
3131
public httpTrace: HttpTrace[] = [];
3232
private verbose: boolean;
3333
public issuerPath: string;
34-
public resourceParameterReceived: boolean = false;
35-
public resourceParameterValue: string | null = null;
34+
public authResourceParameter: string | null = null;
35+
public tokenResourceParameter: string | null = null;
36+
3637

3738
// Store authorization requests for PKCE validation
3839
private authorizationRequests: Map<string, AuthorizationRequest> = new Map();
@@ -43,16 +44,16 @@ export class MockAuthServer implements HttpTraceCollector {
4344
this.app = express();
4445
this.app.use(express.json());
4546
this.app.use(express.urlencoded({ extended: true }));
46-
47+
4748
// Extract issuer path from metadata location
4849
// For /.well-known/oauth-authorization-server/tenant1 -> /tenant1
4950
// For /.well-known/openid-configuration -> ''
5051
// For /tenant1/.well-known/openid-configuration -> /tenant1
5152
this.issuerPath = this.extractIssuerPath(metadataLocation);
52-
53+
5354
this.setupRoutes();
5455
}
55-
56+
5657
private extractIssuerPath(metadataLocation: string): string {
5758
// Handle different metadata location patterns
5859
if (metadataLocation.includes('/.well-known/oauth-authorization-server/')) {
@@ -87,7 +88,7 @@ export class MockAuthServer implements HttpTraceCollector {
8788
this.app.get(this.metadataLocation, (req: Request, res: Response) => {
8889
const baseUrl = this.getUrl();
8990
const issuer = baseUrl + this.issuerPath;
90-
91+
9192
// Base metadata for both OAuth 2.0 and OIDC
9293
const metadata: any = {
9394
issuer: issuer,
@@ -99,7 +100,7 @@ export class MockAuthServer implements HttpTraceCollector {
99100
code_challenge_methods_supported: ['S256'],
100101
token_endpoint_auth_methods_supported: ['none', 'client_secret_post']
101102
};
102-
103+
103104
// Add OIDC-specific fields if this is an OpenID Connect metadata endpoint
104105
if (this.metadataLocation.includes('openid-configuration')) {
105106
metadata.jwks_uri = `${baseUrl}/jwks`;
@@ -109,7 +110,7 @@ export class MockAuthServer implements HttpTraceCollector {
109110
metadata.scopes_supported = ['openid', 'profile', 'email'];
110111
metadata.claims_supported = ['sub', 'name', 'email', 'email_verified'];
111112
}
112-
113+
113114
res.json(metadata);
114115
});
115116

@@ -127,9 +128,7 @@ export class MockAuthServer implements HttpTraceCollector {
127128

128129
// Track resource parameter
129130
if (resource) {
130-
this.resourceParameterReceived = true;
131-
this.resourceParameterValue = resource;
132-
this.log('Received resource parameter:', resource);
131+
this.authResourceParameter = resource;
133132
}
134133

135134
// Basic validation
@@ -178,15 +177,10 @@ export class MockAuthServer implements HttpTraceCollector {
178177
refresh_token,
179178
resource
180179
} = req.body;
181-
180+
182181
// Track resource parameter in token request
183182
if (resource) {
184-
this.resourceParameterReceived = true;
185-
// Update value if not already set or if different
186-
if (!this.resourceParameterValue) {
187-
this.resourceParameterValue = resource;
188-
}
189-
this.log('Received resource parameter in token request:', resource);
183+
this.tokenResourceParameter = resource;
190184
}
191185

192186
if (grant_type === 'authorization_code') {

auth-compat/src/server/validation/index.ts

Lines changed: 4 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ export class ValidationServer {
105105
// Get the actual port at request time
106106
const serverPort = this.getPort();
107107
const authServerUrl = this.authServer ? this.authServer.getUrl() : '';
108-
108+
109109
// Add issuer path if needed
110110
const issuerPath = this.authServer ? this.authServer.issuerPath : '';
111111
const fullAuthServerUrl = authServerUrl + issuerPath;
@@ -302,27 +302,6 @@ export class ValidationServer {
302302
},
303303
errors: this.clientBehavior.authMetadataRequested ? undefined : ['Client did not request auth metadata']
304304
});
305-
306-
// Test: Resource parameter (RFC 8707)
307-
const serverPort = this.getPort();
308-
const expectedResource = `http://localhost:${serverPort}`;
309-
const resourceCorrect = this.authServer?.resourceParameterValue === expectedResource;
310-
311-
results.push({
312-
name: 'resource_parameter_rfc8707',
313-
result: (this.authServer?.resourceParameterReceived && resourceCorrect) ? 'PASS' : 'FAIL',
314-
details: {
315-
resource_parameter_sent: this.authServer?.resourceParameterReceived || false,
316-
resource_parameter_value: this.authServer?.resourceParameterValue || null,
317-
expected_resource: expectedResource,
318-
matches_prm: resourceCorrect
319-
},
320-
errors: !this.authServer?.resourceParameterReceived
321-
? ['Client did not send resource parameter (required by RFC 8707)']
322-
: !resourceCorrect
323-
? [`Resource parameter '${this.authServer?.resourceParameterValue}' does not match PRM value '${expectedResource}'`]
324-
: undefined
325-
});
326305
}
327306

328307
// Test: Basic functionality
@@ -342,20 +321,10 @@ export class ValidationServer {
342321
getClientBehavior(): ClientBehavior {
343322
// Add auth server tracking if available
344323
if (this.authServer) {
345-
this.clientBehavior.resourceParameterUsed = this.authServer.resourceParameterReceived;
346-
this.clientBehavior.resourceParameterValue = this.authServer.resourceParameterValue || undefined;
347-
348-
// Check if the resource parameter EXACTLY matches what's in the PRM
349-
const serverPort = this.getPort();
350-
const expectedResource = `http://localhost:${serverPort}`; // This is what we return in PRM
351-
if (this.authServer.resourceParameterValue) {
352-
const receivedResource = this.authServer.resourceParameterValue;
353-
if (receivedResource !== expectedResource) {
354-
this.clientBehavior.errors.push(`Incorrect resource parameter: expected exactly '${expectedResource}' (from PRM), got '${receivedResource}'`);
355-
}
356-
}
324+
this.clientBehavior.authResourceParameter = this.authServer.authResourceParameter || undefined;
325+
this.clientBehavior.tokenResourceParameter = this.authServer.tokenResourceParameter || undefined;
357326
}
358-
327+
359328
return this.clientBehavior;
360329
}
361330
}

auth-compat/src/types.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,8 @@ export interface ClientBehavior {
3636
requestsMade: string[];
3737
authMetadataRequested: boolean;
3838
authFlowCompleted?: boolean;
39-
resourceParameterUsed?: boolean;
40-
resourceParameterValue?: string;
39+
authResourceParameter?: string;
40+
tokenResourceParameter?: string;
4141
errors: string[];
4242
httpTrace: HttpTrace[];
4343
}

0 commit comments

Comments
 (0)