Skip to content

Commit 2b9eba1

Browse files
author
Paul Wheeler
committed
Merge branch 'idp-token-support' into invio-release-5.1401
2 parents e91975d + f5cb6e3 commit 2b9eba1

File tree

2 files changed

+23
-59
lines changed

2 files changed

+23
-59
lines changed

src/models/IDPDiscovery.js

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
import PrimaryAuthModel from 'models/PrimaryAuth';
1414
import CookieUtil from 'util/CookieUtil';
1515
import Enums from 'util/Enums';
16-
import Util from 'util/Util';
16+
1717
export default PrimaryAuthModel.extend({
1818
props: function() {
1919
const cookieUsername = CookieUtil.getCookieUsername();
@@ -57,13 +57,15 @@ export default PrimaryAuthModel.extend({
5757
if (res.links[0].properties['okta:idp:type'] === 'OKTA') {
5858
this.trigger('goToPrimaryAuth');
5959
} else if (res.links[0].href) {
60-
const redirectFn = res.links[0].href.includes('OKTA_INVALID_SESSION_REPOST%3Dtrue')
61-
? Util.redirectWithFormGet.bind(Util)
62-
: this.settings.get('redirectUtilFn');
63-
//override redirectFn to only use Util.redirectWithFormGet if OKTA_INVALID_SESSION_REPOST is included
64-
//it will be encoded since it will be included in the encoded fromURI
60+
// Redirecting straight to the IDP URL is good for nothing because
61+
// it doesn't transmit tokens back the the client.
6562

66-
redirectFn(res.links[0].href);
63+
return authClient.token.getWithRedirect({
64+
...this.settings.options,
65+
// Unpack authParams
66+
...this.settings.options.authParams,
67+
loginHint: username
68+
});
6769
}
6870
}
6971
})

test/unit/spec/IDPDiscovery_spec.js

Lines changed: 14 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ import Util from 'helpers/mocks/Util';
99
import Expect from 'helpers/util/Expect';
1010
import resError from 'helpers/xhr/ERROR_webfinger';
1111
import resSuccess from 'helpers/xhr/SUCCESS';
12-
import resSuccessRepostIWA from 'helpers/xhr/IDPDiscoverySuccessRepost_IWA';
1312
import resSuccessIWA from 'helpers/xhr/IDPDiscoverySuccess_IWA';
1413
import resSuccessOktaIDP from 'helpers/xhr/IDPDiscoverySuccess_OktaIDP';
1514
import resSuccessSAML from 'helpers/xhr/IDPDiscoverySuccess_SAML';
@@ -960,6 +959,7 @@ Expect.describe('IDPDiscovery', function() {
960959
})
961960
.then(function(test) {
962961
spyOn(test.securityBeacon, 'toggleClass').and.callThrough();
962+
spyOn(test.ac.token, 'getWithRedirect');
963963
test.setNextWebfingerResponse(resSuccessSAML);
964964
test.form.submit();
965965
return Expect.waitForSpyCall(test.securityBeacon.toggleClass, test);
@@ -970,7 +970,9 @@ Expect.describe('IDPDiscovery', function() {
970970
return waitForWebfingerCall(test);
971971
})
972972
.then(function(test) {
973-
expect(test.securityBeacon.toggleClass).toHaveBeenCalledWith(BEACON_LOADING_CLS, false);
973+
expect(test.ac.token.getWithRedirect).toHaveBeenCalledWith(jasmine.objectContaining({
974+
loginHint: test.form.usernameField().val()
975+
}));
974976
});
975977
});
976978
itp('does not show beacon-loading animation when authClient webfinger fails', function() {
@@ -1503,72 +1505,32 @@ Expect.describe('IDPDiscovery', function() {
15031505
spyOn(SharedUtil, 'redirect');
15041506
return setup()
15051507
.then(function(test) {
1508+
spyOn(test.ac.token, 'getWithRedirect');
15061509
test.setNextWebfingerResponse(resSuccessSAML);
15071510
test.form.setUsername(' testuser@clouditude.net ');
15081511
test.form.submit();
1509-
return Expect.waitForSpyCall(SharedUtil.redirect);
1512+
return Expect.waitForSpyCall(test.ac.token.getWithRedirect, test);
15101513
})
1511-
.then(function() {
1512-
expect(SharedUtil.redirect).toHaveBeenCalledWith('http://demo.okta1.com:1802/sso/saml2/0oa2hhcwIc78OGP1W0g4');
1513-
});
1514-
});
1515-
itp('redirects using form Get to idp for SAML idps when features.redirectByFormSubmit is on', function() {
1516-
spyOn(WidgetUtil, 'redirectWithFormGet');
1517-
return setup({ 'features.redirectByFormSubmit': true })
15181514
.then(function(test) {
1519-
test.setNextWebfingerResponse(resSuccessSAML);
1520-
test.form.setUsername(' testuser@clouditude.net ');
1521-
test.form.submit();
1522-
return Expect.waitForSpyCall(WidgetUtil.redirectWithFormGet);
1523-
})
1524-
.then(function() {
1525-
expect(WidgetUtil.redirectWithFormGet).toHaveBeenCalledWith(
1526-
'http://demo.okta1.com:1802/sso/saml2/0oa2hhcwIc78OGP1W0g4'
1527-
);
1515+
expect(test.ac.token.getWithRedirect).toHaveBeenCalledWith(jasmine.objectContaining({
1516+
loginHint: test.form.usernameField().val().trim()
1517+
}));
15281518
});
15291519
});
15301520
itp('redirects to idp for idps other than okta/saml', function() {
15311521
spyOn(SharedUtil, 'redirect');
15321522
return setup()
15331523
.then(function(test) {
1524+
spyOn(test.ac.token, 'getWithRedirect');
15341525
test.setNextWebfingerResponse(resSuccessIWA);
15351526
test.form.setUsername('testuser@clouditude.net');
15361527
test.form.submit();
1537-
return Expect.waitForSpyCall(SharedUtil.redirect);
1528+
return Expect.waitForSpyCall(test.ac.token.getWithRedirect, test);
15381529
})
1539-
.then(function() {
1540-
expect(SharedUtil.redirect).toHaveBeenCalledWith('http://demo.okta1.com:1802/login/sso_iwa');
1541-
});
1542-
});
1543-
itp(
1544-
'redirects using form GET to idp for idps other than okta/saml when features.redirectByFormSubmit is on',
1545-
function() {
1546-
spyOn(WidgetUtil, 'redirectWithFormGet');
1547-
return setup({ 'features.redirectByFormSubmit': true })
1548-
.then(function(test) {
1549-
test.setNextWebfingerResponse(resSuccessIWA);
1550-
test.form.setUsername('testuser@clouditude.net');
1551-
test.form.submit();
1552-
return Expect.waitForSpyCall(WidgetUtil.redirectWithFormGet);
1553-
})
1554-
.then(function() {
1555-
expect(WidgetUtil.redirectWithFormGet).toHaveBeenCalledWith('http://demo.okta1.com:1802/login/sso_iwa');
1556-
});
1557-
}
1558-
);
1559-
itp('redirects using form GET to idp when OKTA_INVALID_SESSION_REPOST=true', function() {
1560-
spyOn(WidgetUtil, 'redirectWithFormGet');
1561-
return setup()
15621530
.then(function(test) {
1563-
test.setNextWebfingerResponse(resSuccessRepostIWA);
1564-
test.form.setUsername('testuser@clouditude.net');
1565-
test.form.submit();
1566-
return Expect.waitForSpyCall(WidgetUtil.redirectWithFormGet);
1567-
})
1568-
.then(function() {
1569-
expect(WidgetUtil.redirectWithFormGet).toHaveBeenCalledWith(
1570-
'http://demo.okta1.com:1802/login/sso_iwa?fromURI=%2Fapp%2Finstance%2Fkey%3FSAMLRequest%3Dencoded%26RelayState%3DrelayState%26OKTA_INVALID_SESSION_REPOST%3Dtrue'
1571-
);
1531+
expect(test.ac.token.getWithRedirect).toHaveBeenCalledWith(jasmine.objectContaining({
1532+
loginHint: test.form.usernameField().val()
1533+
}));
15721534
});
15731535
});
15741536
});

0 commit comments

Comments
 (0)