Skip to content

Commit

Permalink
refactored
Browse files Browse the repository at this point in the history
  • Loading branch information
sfc-gh-ext-simba-jy committed Nov 21, 2023
1 parent 8f4d261 commit d4b8337
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 34 deletions.
11 changes: 3 additions & 8 deletions lib/authentication/auth_mfatoken.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ const auth_okta = require('./auth_okta');
* @returns {Object}
* @constructor
*/
function auth_mfaToken(connectionConfig, httpClient) {
function auth_mfaToken(connectionConfig) {

this.passord = connectionConfig.passord;
this.mfaToken = connectionConfig.mfaToken;
Expand All @@ -35,13 +35,8 @@ function auth_mfaToken(connectionConfig, httpClient) {
};

this.reauthenticate = async function (body) {
const auth = new auth_okta(connectionConfig, httpClient);
await auth.authenticate(connectionConfig.getAuthenticator(),
connectionConfig.getServiceName(),
connectionConfig.account,
connectionConfig.username);
auth.updateBody(body);
};
return;
}
}

module.exports = auth_mfaToken;
Expand Down
12 changes: 2 additions & 10 deletions lib/authentication/auth_okta.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,20 +18,12 @@ var rest = require('../global_config').rest;
* @returns {Object}
* @constructor
*/
// function auth_okta(password, region, account, clientType, clientVersion, httpClient)
function auth_okta(connectionConfig, httpClient)

function auth_okta(password, region, account, clientType, clientVersion, httpClient)
{
const password = connectionConfig.password;
const region = connectionConfig.region;
const account = connectionConfig.account;
const clientType = connectionConfig.getClientType() || connectionConfig.clientAppId;
const clientVersion = connectionConfig.getClientVersion() || connectionConfig.clientAppVersion;

var host = util.construct_hostname(region, account);
var port = rest.HTTPS_PORT;
var protocol = rest.HTTPS_PROTOCOL;

var clientAppId = clientType;
var clientAppVersion = clientVersion;
var samlResponse;
Expand Down
24 changes: 10 additions & 14 deletions lib/authentication/authentication.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ const authenticationTypes =
KEY_PAIR_AUTHENTICATOR: 'SNOWFLAKE_JWT',
OAUTH_AUTHENTICATOR: 'OAUTH',
ID_TOKEN_AUTHENTICATOR: 'ID_TOKEN',
MFA_TOKEN_AUTHENTICATOR: 'MFA_TOKEN',
MFA_TOKEN_AUTHENTICATOR: 'USERNAME_PASSWORD_MFA',
};

exports.authenticationTypes = authenticationTypes;
Expand Down Expand Up @@ -74,7 +74,9 @@ exports.formAuthJSON = function formAuthJSON(
exports.getAuthenticator = function getAuthenticator(connectionConfig, httpClient) {
const auth = connectionConfig.getAuthenticator();

if (auth === authenticationTypes.DEFAULT_AUTHENTICATOR) {
if (auth == authenticationTypes.MFA_TOKEN_AUTHENTICATOR) {
return new auth_mfaToken(connectionConfig);
} else if (auth === authenticationTypes.DEFAULT_AUTHENTICATOR) {
return new auth_default(connectionConfig.password);
} else if (auth === authenticationTypes.EXTERNAL_BROWSER_AUTHENTICATOR) {
if(connectionConfig.getClientStoreTemporaryCredential() && connectionConfig.idToken !== null) {
Expand All @@ -90,18 +92,12 @@ exports.getAuthenticator = function getAuthenticator(connectionConfig, httpClien
} else if (auth === authenticationTypes.OAUTH_AUTHENTICATOR) {
return new auth_oauth(connectionConfig.getToken());
} else if (this.isOktaAuth(auth)) {
if(connectionConfig.getClientRequestMFAToken() && connectionConfig.mfaToken !== null) {
return new auth_mfaToken(connectionConfig,httpClient);
}
// return new auth_okta(connectionConfig.password,
// connectionConfig.region,
// connectionConfig.account,
// connectionConfig.getClientType(),
// connectionConfig.getClientVersion(),
// httpClient
// );

return new auth_okta(connectionConfig, httpClient);
return new auth_okta( connectionConfig.password,
connectionConfig.region,
connectionConfig.account,
connectionConfig.getClientType(),
connectionConfig.getClientVersion(),
httpClient);
} else {
// Authenticator specified does not exist
return new auth_default(connectionConfig.password);
Expand Down
6 changes: 4 additions & 2 deletions lib/services/sf.js
Original file line number Diff line number Diff line change
Expand Up @@ -1249,14 +1249,16 @@ StateConnecting.prototype.continue = function ()
Logger.getInstance().info("Id_token is saved");
});
}
}

if(body.data.mfaToken){
if (connectionConfig.getClientRequestMFAToken()) {
if(body.data.mfaToken) {
SecureStorage.writeCredential(connectionConfig.account, connectionConfig.username,
authenticationTypes.MFA_TOEKN_AUTHENTICATOR, body.data.mfaToken).then(() =>
{
Logger.getInstance().info("MFA_token is saved");
});
}
}
}

// we're now connected
Expand Down

0 comments on commit d4b8337

Please sign in to comment.