Skip to content

Commit 7c52609

Browse files
nodejs support OIE login, issue 178 (#471)
* support oie * fix okta didn't pass client app id and client app version * revert back package json * fix mock test for okta * Remove test on linux azure --------- Co-authored-by: ilesh garish <[email protected]>
1 parent bc8bdd9 commit 7c52609

File tree

6 files changed

+36
-12
lines changed

6 files changed

+36
-12
lines changed

.github/workflows/build-test.yml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -191,7 +191,9 @@ jobs:
191191
max-parallel: 1
192192
matrix:
193193
image: [ 'nodejs-centos6-default', 'nodejs-centos7-node12' ]
194-
cloud: [ 'AZURE', 'GCP' ]
194+
#REMOVE AZURE for now
195+
#cloud: [ 'AZURE', 'GCP' ]
196+
cloud: [ 'GCP' ]
195197
steps:
196198
- uses: actions/checkout@v1
197199
- uses: actions/setup-node@v1

lib/authentication/auth_okta.js

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,14 @@ var rest = require('../global_config').rest;
1111
* @param {String} password
1212
* @param {String} region
1313
* @param {String} account
14+
* @param {String} clientType
15+
* @param {String} clientVersion
1416
* @param {module} httpclient
1517
*
1618
* @returns {Object}
1719
* @constructor
1820
*/
19-
function auth_okta(password, region, account, httpclient)
21+
function auth_okta(password, region, account, clientType, clientVersion, httpclient)
2022
{
2123
var axios = typeof httpclient !== "undefined" ? httpclient : require('axios');
2224
var password = password;
@@ -25,6 +27,8 @@ function auth_okta(password, region, account, httpclient)
2527
var port = rest.HTTPS_PORT;
2628
var protocol = rest.HTTPS_PROTOCOL;
2729

30+
var clientAppId = clientType;
31+
var clientAppVersion = clientVersion;
2832
var samlResponse;
2933

3034
/**
@@ -53,7 +57,6 @@ function auth_okta(password, region, account, httpclient)
5357
{
5458
var ssoUrl;
5559
var tokenUrl;
56-
5760
await step1(authenticator, serviceName, account, username).then((response) =>
5861
{
5962
var data = response['data']['data'];
@@ -66,8 +69,14 @@ function auth_okta(password, region, account, httpclient)
6669
var oneTimeToken;
6770
await step3(tokenUrl, username, password).then((response) =>
6871
{
69-
var data = response['data'];
70-
oneTimeToken = data['cookieToken'];
72+
var data = response['data'];
73+
74+
if (data['sessionToken']) {
75+
oneTimeToken = data['sessionToken'];
76+
}
77+
else {
78+
oneTimeToken = data['cookieToken'];
79+
}
7180
});
7281

7382
var responseHtml;
@@ -109,7 +118,9 @@ function auth_okta(password, region, account, httpclient)
109118
"LOGIN_NAME": username,
110119
"PORT": port,
111120
"PROTOCOL": protocol,
112-
"AUTHENTICATOR": authenticator
121+
"AUTHENTICATOR": authenticator,
122+
"CLIENT_APP_ID": clientAppId,
123+
"CLIENT_APP_VERSION": clientAppVersion
113124
}
114125
};
115126

lib/authentication/authentication.js

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ exports.authenticationTypes = authenticationTypes;
2424
* @param {String} authenticator
2525
* @param {String} account
2626
* @param {String} username
27-
* @param {String} clientName
27+
* @param {String} clientType
2828
* @param {String} clientVersion
2929
* @param {Object} clientEnv
3030
*
@@ -34,7 +34,7 @@ exports.formAuthJSON = function formAuthJSON(
3434
authenticator,
3535
account,
3636
username,
37-
clientName,
37+
clientType,
3838
clientVersion,
3939
clientEnv
4040
)
@@ -46,7 +46,7 @@ exports.formAuthJSON = function formAuthJSON(
4646
AUTHENTICATOR: authenticator,
4747
ACCOUNT_NAME: account,
4848
LOGIN_NAME: username,
49-
CLIENT_APP_ID: clientName,
49+
CLIENT_APP_ID: clientType,
5050
CLIENT_APP_VERSION: clientVersion,
5151
CLIENT_ENVIRONMENT:
5252
{
@@ -93,7 +93,10 @@ exports.getAuthenticator = function getAuthenticator(connectionConfig)
9393
{
9494
return new auth_okta(connectionConfig.password,
9595
connectionConfig.region,
96-
connectionConfig.account);
96+
connectionConfig.account,
97+
connectionConfig.getClientType(),
98+
connectionConfig.getClientVersion()
99+
);
97100
}
98101
else
99102
{

lib/connection/connection.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -228,7 +228,7 @@ function Connection(context)
228228
var body = Authenticator.formAuthJSON(connectionConfig.getAuthenticator(),
229229
connectionConfig.account,
230230
connectionConfig.username,
231-
connectionConfig.getClientName(),
231+
connectionConfig.getClientType(),
232232
connectionConfig.getClientVersion(),
233233
connectionConfig.getClientEnvironment());
234234

@@ -290,7 +290,7 @@ function Connection(context)
290290
var body = Authenticator.formAuthJSON(connectionConfig.getAuthenticator(),
291291
connectionConfig.account,
292292
connectionConfig.username,
293-
connectionConfig.getClientName(),
293+
connectionConfig.getClientType(),
294294
connectionConfig.getClientVersion(),
295295
connectionConfig.getClientEnvironment());
296296

test/unit/authentication/authentication_test.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -393,6 +393,8 @@ describe('okta authentication', function ()
393393
var auth = new auth_okta(connectionOptionsOkta.password,
394394
connectionOptionsOkta.region,
395395
connectionOptionsOkta.account,
396+
connectionOptionsOkta.clientAppid,
397+
connectionOptionsOkta.clientAppVersion,
396398
httpclient);
397399

398400
await auth.authenticate(connectionOptionsOkta.authenticator, '', connectionOptionsOkta.account, connectionOptionsOkta.username);
@@ -432,6 +434,8 @@ describe('okta authentication', function ()
432434
var auth = new auth_okta(connectionOptionsOkta.password,
433435
connectionOptionsOkta.region,
434436
connectionOptionsOkta.account,
437+
connectionOptionsOkta.clientAppid,
438+
connectionOptionsOkta.clientAppVersion,
435439
httpclient);
436440

437441
try
@@ -487,6 +491,8 @@ describe('okta authentication', function ()
487491
var auth = new auth_okta(connectionOptionsOkta.password,
488492
connectionOptionsOkta.region,
489493
connectionOptionsOkta.account,
494+
connectionOptionsOkta.clientAppid,
495+
connectionOptionsOkta.clientAppVersion,
490496
httpclient);
491497

492498
try

test/unit/mock/mock_test_util.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,8 @@ var connectionOptionsOkta =
130130
username: 'fakeusername',
131131
account: 'fakeaccount',
132132
token: 'faketoken',
133+
clientAppid: 'JavaScript',
134+
clientAppVersion: '1.6.21',
133135
rawSamlResponse: '<form action="https://fakeaccount.snowflakecomputing.com/fed/login">',
134136
authenticator: 'https://dev-12345678.okta.com/'
135137
};

0 commit comments

Comments
 (0)