Skip to content
Merged
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
11 changes: 11 additions & 0 deletions src/auth/backchannel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -88,8 +88,13 @@ export type AuthorizeOptions = {
audience?: string;
/**
* Custom expiry time in seconds for this request.
* @deprecated Use {@link AuthorizeOptions.requested_expiry} instead.
*/
request_expiry?: string;
/**
* Custom expiry time in seconds for this request.
*/
requested_expiry?: string;
/**
* The user ID.
*/
Expand Down Expand Up @@ -191,6 +196,12 @@ export class Backchannel extends BaseAuthAPI implements IBackchannel {
client_id: this.clientId,
};

// The correct parameter is `requested_expiry`, but we also accept the deprecated `request_expiry` for backwards compatibility
const requestedExpiry = options.requested_expiry || options.request_expiry;
if (requestedExpiry) {
body.requested_expiry = requestedExpiry;
}

await this.addClientAuthentication(body);

const response = await this.request.bind(this)(
Expand Down
55 changes: 55 additions & 0 deletions test/auth/backchannel.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,61 @@ describe('Backchannel', () => {
interval: 5,
});
});

it('should pass requested_expiry to /bc-authorize', async () => {
let receivedRequestedExpiry = 0;
nock(`https://${opts.domain}`)
.post('/bc-authorize')
.reply(201, (uri, requestBody, cb) => {
receivedRequestedExpiry = JSON.parse(
querystring.parse(requestBody as any)['requested_expiry'] as string
);
cb(null, {
auth_req_id: 'test-auth-req-id',
expires_in: 300,
interval: 5,
});
});

await backchannel.authorize({
userId: 'auth0|test-user-id',
binding_message: 'Test binding message',
scope: 'openid',
requested_expiry: '999',
});

expect(receivedRequestedExpiry).toBe(999);
});

it('should pass request_expiry as requested_expiry and retain the request_expiry param for backwards compatibility', async () => {
let receivedRequestedExpiry = 0;
let receivedRequestExpiry = 0;
nock(`https://${opts.domain}`)
.post('/bc-authorize')
.reply(201, (uri, requestBody, cb) => {
receivedRequestedExpiry = JSON.parse(
querystring.parse(requestBody as any)['requested_expiry'] as string
);
receivedRequestExpiry = JSON.parse(
querystring.parse(requestBody as any)['request_expiry'] as string
);
cb(null, {
auth_req_id: 'test-auth-req-id',
expires_in: 300,
interval: 5,
});
});

await backchannel.authorize({
userId: 'auth0|test-user-id',
binding_message: 'Test binding message',
scope: 'openid',
request_expiry: '999',
});

expect(receivedRequestedExpiry).toBe(999);
expect(receivedRequestExpiry).toBe(999);
});
});

describe('#backchannelGrant', () => {
Expand Down