Skip to content

Commit e2088dc

Browse files
committed
avoid fallbacks
1 parent bae0426 commit e2088dc

File tree

2 files changed

+20
-8
lines changed

2 files changed

+20
-8
lines changed

src/scenarios/client/auth/helpers/createAuthServer.ts

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ export interface AuthServerOptions {
66
metadataPath?: string;
77
isOpenIdConfiguration?: boolean;
88
loggingEnabled?: boolean;
9+
routePrefix?: string;
910
}
1011

1112
export function createAuthServer(
@@ -16,8 +17,16 @@ export function createAuthServer(
1617
const {
1718
metadataPath = '/.well-known/oauth-authorization-server',
1819
isOpenIdConfiguration = false,
19-
loggingEnabled = true
20+
loggingEnabled = true,
21+
routePrefix = ''
2022
} = options;
23+
24+
const authRoutes = {
25+
authorization_endpoint: `${routePrefix}/authorize`,
26+
token_endpoint: `${routePrefix}/token`,
27+
registration_endpoint: `${routePrefix}/register`
28+
};
29+
2130
const app = express();
2231
app.use(express.json());
2332
app.use(express.urlencoded({ extended: true }));
@@ -52,9 +61,9 @@ export function createAuthServer(
5261

5362
const metadata: any = {
5463
issuer: getAuthBaseUrl(),
55-
authorization_endpoint: `${getAuthBaseUrl()}/authorize`,
56-
token_endpoint: `${getAuthBaseUrl()}/token`,
57-
registration_endpoint: `${getAuthBaseUrl()}/register`,
64+
authorization_endpoint: `${getAuthBaseUrl()}${authRoutes.authorization_endpoint}`,
65+
token_endpoint: `${getAuthBaseUrl()}${authRoutes.token_endpoint}`,
66+
registration_endpoint: `${getAuthBaseUrl()}${authRoutes.registration_endpoint}`,
5867
response_types_supported: ['code'],
5968
grant_types_supported: ['authorization_code', 'refresh_token'],
6069
code_challenge_methods_supported: ['S256'],
@@ -71,7 +80,7 @@ export function createAuthServer(
7180
res.json(metadata);
7281
});
7382

74-
app.get('/authorize', (req: Request, res: Response) => {
83+
app.get(authRoutes.authorization_endpoint, (req: Request, res: Response) => {
7584
checks.push({
7685
id: 'authorization-request',
7786
name: 'AuthorizationRequest',
@@ -105,7 +114,7 @@ export function createAuthServer(
105114
res.redirect(redirectUrl.toString());
106115
});
107116

108-
app.post('/token', (req: Request, res: Response) => {
117+
app.post(authRoutes.token_endpoint, (req: Request, res: Response) => {
109118
checks.push({
110119
id: 'token-request',
111120
name: 'TokenRequest',
@@ -131,7 +140,7 @@ export function createAuthServer(
131140
});
132141
});
133142

134-
app.post('/register', (req: Request, res: Response) => {
143+
app.post(authRoutes.registration_endpoint, (req: Request, res: Response) => {
135144
checks.push({
136145
id: 'client-registration',
137146
name: 'ClientRegistration',

src/scenarios/client/auth/march-spec-backcompat.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,15 @@ export class AuthMarchSpecBackcompatScenario implements Scenario {
1414

1515
async start(): Promise<ScenarioUrls> {
1616
this.checks = [];
17+
// TODO: I want to move the Auth URL's below a path.
1718

1819
// Legacy server, so we create the auth server endpoints on the
1920
// same URL as the main server (rather than separating AS / RS).
2021
const authApp = createAuthServer(this.checks, this.server.getUrl, {
2122
// Disable logging since the main server will already have logging enabled
22-
loggingEnabled: false
23+
loggingEnabled: false,
24+
// Add a prefix to auth endpoints to avoid being caught by auth fallbacks
25+
routePrefix: '/oauth'
2326
});
2427
const app = createServer(
2528
this.checks,

0 commit comments

Comments
 (0)