Skip to content

Commit 457e7b8

Browse files
feat: adds initialPath param to getWithPopup (#1594)
OKTA-972681 feat: adds initialPath param to getWithPopup
1 parent 0edf8ba commit 457e7b8

File tree

4 files changed

+26
-8
lines changed

4 files changed

+26
-8
lines changed

CHANGELOG.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,13 @@
11
# Changelog
22

3+
# 7.13.0
4+
5+
### Features
6+
7+
- [#1594](https://github.com/okta/okta-auth-js/pull/1594) feat: adds `initialPath` configuration to `token.getWithPopup`
8+
9+
- [#1593](https://github.com/okta/okta-auth-js/pull/1593) feat: adds `multiOptionalFactorEnroll` support to `authn.verifyRecoveryToken`
10+
311
# 7.12.1
412

513
### Fixes

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1633,6 +1633,8 @@ authClient.token.getWithoutPrompt({
16331633
Create token with a popup.
16341634

16351635
* `options` - See [Authorize options](#authorize-options)
1636+
* `options.initialPath` - `string` _(optional)_
1637+
To reduce the likelihood of the popup being blocked, the popup window first loads the web app before redirecting to the authorization server. Customize the path which is loaded by setting this value. (This must be an unauthenticated path). Defaults to `'/'`
16361638

16371639
```javascript
16381640
authClient.token.getWithPopup(options)

lib/oidc/getWithPopup.ts

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,22 +16,27 @@ import { clone } from '../util';
1616
import { getToken } from './getToken';
1717
import { loadPopup, generateState } from './util';
1818

19-
export function getWithPopup(sdk: OktaAuthOAuthInterface, options: TokenParams): Promise<TokenResponse> {
19+
export function getWithPopup(
20+
sdk: OktaAuthOAuthInterface,
21+
options: TokenParams & { initialPath?: string }
22+
): Promise<TokenResponse> {
2023
if (arguments.length > 2) {
2124
return Promise.reject(new AuthSdkError('As of version 3.0, "getWithPopup" takes only a single set of options'));
2225
}
2326

27+
const { initialPath, ...params } = options;
28+
2429
// some browsers (safari, firefox) block popup if it's initialed from an async process
2530
// here we create the popup window immediately after user interaction
2631
// then redirect to the /authorize endpoint when the requestUrl is available
27-
const popupWindow = loadPopup('/', options);
28-
options = clone(options) || {};
29-
Object.assign(options, {
32+
const popupWindow = loadPopup(initialPath ?? '/', params);
33+
options = clone(params) || {};
34+
Object.assign(params, {
3035
display: 'popup',
3136
responseMode: 'okta_post_message',
3237
popupWindow
3338
});
34-
return getToken(sdk, options);
39+
return getToken(sdk, params);
3540
}
3641

3742
export function getWithIDPPopup(

test/spec/oidc/getWithPopup.ts

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -170,16 +170,17 @@ describe('token.getWithPopup', function() {
170170
});
171171
});
172172

173-
it('returns tokens using idp with authorization server', function() {
174-
return oauthUtil.setupPopup({
173+
it('returns tokens using idp with authorization server', async function() {
174+
await oauthUtil.setupPopup({
175175
oktaAuthArgs: {
176176
pkce: false,
177177
issuer: 'https://auth-js-test.okta.com/oauth2/aus8aus76q8iphupD0h7',
178178
clientId: 'NPSfOkH5eZrTy8PMDlvx',
179179
redirectUri: 'https://example.com/redirect'
180180
},
181181
getWithPopupArgs: {
182-
idp: 'testIdp'
182+
idp: 'testIdp',
183+
initialPath: '?foo=1'
183184
},
184185
postMessageSrc: {
185186
baseUri: 'https://auth-js-test.okta.com/oauth2/aus8aus76q8iphupD0h7/v1/authorize',
@@ -207,6 +208,8 @@ describe('token.getWithPopup', function() {
207208
}
208209
}
209210
});
211+
expect(window.open).toHaveBeenCalled();
212+
expect(window.open).toHaveBeenCalledWith('?foo=1', expect.any(String), expect.any(String));
210213
});
211214

212215
it('allows passing issuer through getWithPopup, which takes precedence', function() {

0 commit comments

Comments
 (0)