Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

adds nonce param to idx.interact #1307

Merged
merged 4 commits into from
Sep 21, 2022
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
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# Changelog

## 6.9

- [#1307](https://github.com/okta/okta-auth-js/pull/1307) Adds `nonce` param to `idx.interact` (and `idx.start`)

## 6.8.1

### Fixes
Expand Down
7 changes: 5 additions & 2 deletions lib/idx/interact.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ export interface InteractParams {
recovery_token?: string;
client_secret?: string;
max_age?: string | number;
nonce?: string;
}
/* eslint-enable camelcase */

Expand Down Expand Up @@ -68,7 +69,8 @@ export async function interact (
codeChallengeMethod,
activationToken,
recoveryToken,
maxAge
maxAge,
nonce
} = meta as IdxTransactionMeta;
const clientSecret = options.clientSecret || authClient.options.clientSecret;
withCredentials = withCredentials ?? true;
Expand All @@ -88,7 +90,8 @@ export async function interact (
// eslint-disable-next-line max-len
// https://oktawiki.atlassian.net/wiki/spaces/eng/pages/2445902453/Support+Device+Binding+in+interact#Scenario-1%3A-Non-User-Agent-with-Confidential-Client-(top-priority)
...(clientSecret && { client_secret: clientSecret }),
...(maxAge && { max_age: maxAge })
...(maxAge && { max_age: maxAge }),
...(nonce && { nonce }),
} as InteractParams;
/* eslint-enable camelcase */

Expand Down
2 changes: 2 additions & 0 deletions lib/idx/run.ts
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,7 @@ async function getDataFromIntrospect(authClient, data: RunData): Promise<RunData
recoveryToken,
activationToken,
maxAge,
nonce,
} = options;

let idxResponse;
Expand All @@ -140,6 +141,7 @@ async function getDataFromIntrospect(authClient, data: RunData): Promise<RunData
activationToken,
recoveryToken,
maxAge,
nonce,
});
interactionHandle = interactResponse.interactionHandle;
meta = interactResponse.meta;
Expand Down
1 change: 1 addition & 0 deletions lib/idx/types/options.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ export interface InteractOptions extends IdxOptions {
recoveryToken?: string;
clientSecret?: string;
maxAge?: string | number;
nonce?: string;
}

export interface IntrospectOptions extends IdxOptions {
Expand Down
44 changes: 44 additions & 0 deletions test/spec/idx/interact.ts
Original file line number Diff line number Diff line change
Expand Up @@ -774,6 +774,50 @@ describe('idx/interact', () => {
});
});

describe('nonce', () => {
it('passes `nonce` to /interact', async () => {
const { authClient, transactionMeta } = testContext;
jest.spyOn(mocked.transactionMeta, 'getSavedTransactionMeta').mockReturnValue(transactionMeta);
const res = await interact(authClient, { nonce: 'nonce-upon-a-time' });
expect(mocked.http.httpRequest).toHaveBeenCalledWith(authClient, {
url: 'https://auth-js-test.okta.com/oauth2/v1/interact',
method: 'POST',
headers: {
'Content-Type': 'application/x-www-form-urlencoded',
},
args: ({
client_id: 'authClient-clientId',
scope: 'meta',
redirect_uri: 'authClient-redirectUri',
code_challenge: 'meta-codeChallenge',
code_challenge_method: 'meta-codeChallengeMethod',
state: 'meta-state',
nonce: 'nonce-upon-a-time'
}),
withCredentials: true
});
expect(res).toEqual({
'interactionHandle': 'idx-interactionHandle',
'meta': {
'clientId': 'authClient-clientId',
'issuer': 'https://auth-js-test.okta.com',
'redirectUri': 'authClient-redirectUri',
'codeChallenge': 'meta-codeChallenge',
'codeChallengeMethod': 'meta-codeChallengeMethod',
'codeVerifier': 'meta-codeVerifier',
'interactionHandle': 'idx-interactionHandle',
'responseType': 'tp-responseType',
'scopes': [
'meta',
],
'state': 'meta-state',
'withCredentials': true,
'nonce': 'nonce-upon-a-time',
},
'state': 'meta-state',
});
});
});
});

describe('with saved interactionHandle', () => {
Expand Down