Skip to content

Commit 7a5f91e

Browse files
committed
fix(auth): fix the requested_expiry param
1 parent 125c178 commit 7a5f91e

File tree

2 files changed

+66
-0
lines changed

2 files changed

+66
-0
lines changed

src/auth/backchannel.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,8 +88,13 @@ export type AuthorizeOptions = {
8888
audience?: string;
8989
/**
9090
* Custom expiry time in seconds for this request.
91+
* @deprecated Use {@link AuthorizeOptions.requested_expiry} instead.
9192
*/
9293
request_expiry?: string;
94+
/**
95+
* Custom expiry time in seconds for this request.
96+
*/
97+
requested_expiry?: string;
9398
/**
9499
* The user ID.
95100
*/
@@ -191,6 +196,12 @@ export class Backchannel extends BaseAuthAPI implements IBackchannel {
191196
client_id: this.clientId,
192197
};
193198

199+
// The correct parameter is `requested_expiry`, but we also accept the deprecated `request_expiry` for backwards compatibility
200+
const requestedExpiry = options.requested_expiry || options.request_expiry;
201+
if (requestedExpiry) {
202+
body.requested_expiry = requestedExpiry;
203+
}
204+
194205
await this.addClientAuthentication(body);
195206

196207
const response = await this.request.bind(this)(

test/auth/backchannel.test.ts

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,61 @@ describe('Backchannel', () => {
9191
});
9292
});
9393

94+
it('should pass requested_expiry to /bc-authorize', async () => {
95+
let receivedRequestedExpiry = 0;
96+
nock(`https://${opts.domain}`)
97+
.post('/bc-authorize')
98+
.reply(201, (uri, requestBody, cb) => {
99+
receivedRequestedExpiry = JSON.parse(
100+
querystring.parse(requestBody as any)['requested_expiry'] as string
101+
);
102+
cb(null, {
103+
auth_req_id: 'test-auth-req-id',
104+
expires_in: 300,
105+
interval: 5,
106+
});
107+
});
108+
109+
await backchannel.authorize({
110+
userId: 'auth0|test-user-id',
111+
binding_message: 'Test binding message',
112+
scope: 'openid',
113+
requested_expiry: '999',
114+
});
115+
116+
expect(receivedRequestedExpiry).toBe(999);
117+
});
118+
119+
it('should pass request_expiry as requested_expiry and retain the request_expiry param for backwards compatibility', async () => {
120+
let receivedRequestedExpiry = 0;
121+
let receivedRequestExpiry = 0;
122+
nock(`https://${opts.domain}`)
123+
.post('/bc-authorize')
124+
.reply(201, (uri, requestBody, cb) => {
125+
receivedRequestedExpiry = JSON.parse(
126+
querystring.parse(requestBody as any)['requested_expiry'] as string
127+
);
128+
receivedRequestExpiry = JSON.parse(
129+
querystring.parse(requestBody as any)['request_expiry'] as string
130+
);
131+
cb(null, {
132+
auth_req_id: 'test-auth-req-id',
133+
expires_in: 300,
134+
interval: 5,
135+
});
136+
});
137+
138+
await backchannel.authorize({
139+
userId: 'auth0|test-user-id',
140+
binding_message: 'Test binding message',
141+
scope: 'openid',
142+
request_expiry: '999',
143+
});
144+
145+
expect(receivedRequestedExpiry).toBe(999);
146+
expect(receivedRequestExpiry).toBe(999);
147+
});
148+
94149
it('should pass authorization_details to /bc-authorize', async () => {
95150
let receivedAuthorizationDetails: { type: string }[] = [];
96151
nock(`https://${opts.domain}`)

0 commit comments

Comments
 (0)