Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions src/scenarios/authorization-server/auth/spec-references.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,22 @@ export const SpecReferences: { [key: string]: SpecReference } = {
id: 'OAUTH-2.1-authorization-code-grant',
url: 'https://www.ietf.org/archive/id/draft-ietf-oauth-v2-1-13.html#section-4.1'
},
RFC_7636_AUTHORIZATION_REQUEST_ERROR: {
id: 'RFC-7636-authorization-request-error',
url: 'https://www.rfc-editor.org/rfc/rfc7636.html#section-4.4.1'
},
RFC_9700_PKCE: {
id: 'RFC-9700-pkce',
url: 'https://www.rfc-editor.org/rfc/rfc9700.html#section-2.1.1'
},
RFC_6749_AUTHORIZATION_ERROR_RESPONSE: {
id: 'RFC-6749-authorization-error-response',
url: 'https://www.rfc-editor.org/rfc/rfc6749.html#section-4.1.2.1'
},
RFC_9700_REDIRECT_URI_MATCHING: {
id: 'RFC-9700-redirect-uri-matching',
url: 'https://www.rfc-editor.org/rfc/rfc9700.html#section-2.1'
},
// DPoP (SEP-1932 / RFC 9449) — authorization-server concerns.
SEP_1932_DPOP: {
id: 'SEP-1932-DPoP',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,12 @@ vi.mock('../authorization-server/auth/helpers/createCallbackServer', () => ({
startCallbackServer: vi.fn()
}));

// The authorization endpoint probes have their own tests
// (authorization-endpoint-probes*.test.ts); here they add no checks.
vi.mock('./authorization-endpoint-probes', () => ({
runAuthorizationEndpointProbes: vi.fn().mockResolvedValue([])
}));

const mockedRequest = vi.mocked(request);
const mockedStartCallbackServer = vi.mocked(startCallbackServer);

Expand Down
29 changes: 25 additions & 4 deletions src/scenarios/authorization-server/authorization-code-grant.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import { request } from 'undici';
import { createHash, randomBytes } from 'crypto';
import { AuthorizationServerOptions } from '../../schemas';
import { SpecReferences } from '../authorization-server/auth/spec-references';
import { runAuthorizationEndpointProbes } from './authorization-endpoint-probes';

const REDIRECT_URI_ORIGIN = 'http://127.0.0.1';
const REDIRECT_URI_PATH = '/callback';
Expand Down Expand Up @@ -58,12 +59,18 @@ export class AuthorizationCodeGrantScenario implements ClientScenarioForAuthoriz
- HTTP response status code of token response MUST be 200 OK
- Content-Type header of token response MUST be application/json
- Cache-Control header of token response MUST be no-store
- Token response MUST return a JSON response including access_token and token_type`;
- Token response MUST return a JSON response including access_token and token_type
- An authorization request without a code_challenge MUST be answered with the invalid_request authorization error response, an error redirect to the redirect URI (RFC 7636 §4.4.1, RFC 6749 §4.1.2.1); a code_verifier is accepted only if a code_challenge was sent (RFC 9700 §2.1.1)
- An error redirect to the redirect URI MUST carry the state of the request (RFC 6749 §4.1.2.1)
- The server MUST NOT redirect to a redirect URI that is not an exact match of a registered one (RFC 9700 §2.1; RFC 6749 §4.1.2.1)

The last three requirements are checked without a login, by reading the authorization endpoint's answer to requests next to a valid control request. A server that answers every anonymous request with a login page, or refuses the control request, gets those checks reported as failed with a 'Not testable' reason (#248), not as passed.`;

async run(
options: AuthorizationServerOptions,
details: Record<string, unknown>
): Promise<ConformanceCheck[]> {
let probeChecks: ConformanceCheck[] = [];
try {
if (!options.clientId) {
return [
Expand All @@ -88,8 +95,18 @@ export class AuthorizationCodeGrantScenario implements ClientScenarioForAuthoriz
// Decide how we'll authenticate to the token endpoint *before*
// binding a port and asking the user to open a browser.
const authMethod = this.selectTokenAuthMethod(metadata, options);

// Negative checks that need no login: sent before the interactive
// login, so they are reported even if the login fails or is skipped.
probeChecks = await runAuthorizationEndpointProbes(
metadata,
options,
`${REDIRECT_URI_ORIGIN}:${options.port}${REDIRECT_URI_PATH}`,
authMethod
);
if (authMethod === null) {
return [
...probeChecks,
this.skippedCheck(
'Server does not support client_secret_post, client_secret_basic, or none auth methods'
)
Expand Down Expand Up @@ -134,10 +151,11 @@ export class AuthorizationCodeGrantScenario implements ClientScenarioForAuthoriz
this.validateTokenResponse(tokenResponse, errors);

if (errors.length > 0) {
return [this.failureCheck(errors.join(', '))];
return [...probeChecks, this.failureCheck(errors.join(', '))];
}

return [
...probeChecks,
this.successCheck({
authorizationRequest,
authorizationResponseUrl,
Expand All @@ -148,7 +166,7 @@ export class AuthorizationCodeGrantScenario implements ClientScenarioForAuthoriz
callback.close();
}
} catch (error) {
return [this.failureCheck(error)];
return [...probeChecks, this.failureCheck(error)];
}
}

Expand All @@ -172,7 +190,10 @@ export class AuthorizationCodeGrantScenario implements ClientScenarioForAuthoriz
params.set('resource', options.resource);
}

return `${metadata.authorization_endpoint}?${params.toString()}`;
// The endpoint may already have a query (RFC 6749 3.1): keep it.
const url = new URL(metadata.authorization_endpoint);
for (const [key, value] of params) url.searchParams.set(key, value);
return url.toString();
}

private validateAuthorizationResponse(
Expand Down
Loading