Skip to content

Commit 068222c

Browse files
authored
fix(auth): fix the requested_expiry param (v4) (#1174)
1 parent 4c24b3f commit 068222c

2 files changed

Lines changed: 66 additions & 0 deletions

File tree

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
@@ -201,6 +201,61 @@ describe('Backchannel', () => {
201201
interval: 5,
202202
});
203203
});
204+
205+
it('should pass requested_expiry to /bc-authorize', async () => {
206+
let receivedRequestedExpiry = 0;
207+
nock(`https://${opts.domain}`)
208+
.post('/bc-authorize')
209+
.reply(201, (uri, requestBody, cb) => {
210+
receivedRequestedExpiry = JSON.parse(
211+
querystring.parse(requestBody as any)['requested_expiry'] as string
212+
);
213+
cb(null, {
214+
auth_req_id: 'test-auth-req-id',
215+
expires_in: 300,
216+
interval: 5,
217+
});
218+
});
219+
220+
await backchannel.authorize({
221+
userId: 'auth0|test-user-id',
222+
binding_message: 'Test binding message',
223+
scope: 'openid',
224+
requested_expiry: '999',
225+
});
226+
227+
expect(receivedRequestedExpiry).toBe(999);
228+
});
229+
230+
it('should pass request_expiry as requested_expiry and retain the request_expiry param for backwards compatibility', async () => {
231+
let receivedRequestedExpiry = 0;
232+
let receivedRequestExpiry = 0;
233+
nock(`https://${opts.domain}`)
234+
.post('/bc-authorize')
235+
.reply(201, (uri, requestBody, cb) => {
236+
receivedRequestedExpiry = JSON.parse(
237+
querystring.parse(requestBody as any)['requested_expiry'] as string
238+
);
239+
receivedRequestExpiry = JSON.parse(
240+
querystring.parse(requestBody as any)['request_expiry'] as string
241+
);
242+
cb(null, {
243+
auth_req_id: 'test-auth-req-id',
244+
expires_in: 300,
245+
interval: 5,
246+
});
247+
});
248+
249+
await backchannel.authorize({
250+
userId: 'auth0|test-user-id',
251+
binding_message: 'Test binding message',
252+
scope: 'openid',
253+
request_expiry: '999',
254+
});
255+
256+
expect(receivedRequestedExpiry).toBe(999);
257+
expect(receivedRequestExpiry).toBe(999);
258+
});
204259
});
205260

206261
describe('#backchannelGrant', () => {

0 commit comments

Comments
 (0)