-
Notifications
You must be signed in to change notification settings - Fork 9
Expand file tree
/
Copy pathssoHelper.js
More file actions
32 lines (26 loc) · 1.02 KB
/
ssoHelper.js
File metadata and controls
32 lines (26 loc) · 1.02 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
const _ = require('lodash');
const axios = require('axios');
const snowflakeHelper = require('./snowflakeHelper');
const ssoAuthenticatorError = { message: "Can't get SSO URL. Please, check the SAML settings" };
const getSsoUrlData = async (logger, { host, redirectPort = 8080 }) => {
logger.log('info', `Starting SSO connection...`, 'Connection');
logger.log('info', `Redirect port: ${redirectPort}`, 'Connection');
const account = snowflakeHelper.getAccount(host);
const accessUrl = snowflakeHelper.getAccessUrl(account);
const ssoUrlsData = await axios.post(`${accessUrl}/session/authenticator-request`, {
data: {
AUTHENTICATOR: 'EXTERNALBROWSER',
BROWSER_MODE_REDIRECT_PORT: redirectPort,
},
});
const ssoUrl = _.get(ssoUrlsData, 'data.data.ssoUrl', '');
const proofKey = _.get(ssoUrlsData, 'data.data.proofKey', '');
logger.log('info', `SSO URL: ${ssoUrl}`, 'Connection');
if (!ssoUrl) {
return Promise.reject(ssoAuthenticatorError);
}
return { url: ssoUrl, proofKey };
};
module.exports = {
getSsoUrlData,
};