-
Notifications
You must be signed in to change notification settings - Fork 133
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
SNOW-334890: External browser SSO authentication with proxy
- Loading branch information
1 parent
39abad3
commit afe40b3
Showing
6 changed files
with
138 additions
and
125 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
/* | ||
* Copyright (c) 2015-2023 Snowflake Computing Inc. All rights reserved. | ||
*/ | ||
|
||
const Util = require('../util'); | ||
const Errors = require('../errors'); | ||
const HttpClient = require("../http/node"); | ||
const axios = require("axios"); | ||
const {rest} = require("../global_config"); | ||
|
||
/** | ||
* Creates a new instance of an LargeResultSetService. | ||
* | ||
* @param {Object} connectionConfig | ||
* @param {Object} httpClient | ||
* @constructor | ||
*/ | ||
function SsoUrlProvider(connectionConfig, httpClient) { | ||
// validate input | ||
Errors.assertInternal(Util.isObject(connectionConfig)); | ||
Errors.assertInternal(Util.isObject(httpClient)); | ||
|
||
const port = rest.HTTPS_PORT; | ||
const protocol = rest.HTTPS_PROTOCOL; | ||
|
||
/** | ||
* Get SSO URL through POST request. | ||
* | ||
* @param {String} authenticator | ||
* @param {String} serviceName | ||
* @param {String} account | ||
* @param {Number} callback_port | ||
* @param {String} user | ||
* @param {String} host | ||
* | ||
* @returns {String} the SSO URL. | ||
*/ | ||
this.getSSOURL = function (authenticator, serviceName, account, callback_port, user, host) { | ||
// Create URL to send POST request to | ||
const url = protocol + '://' + host + "/session/authenticator-request"; | ||
|
||
let header; | ||
if (serviceName) { | ||
header = { | ||
'HTTP_HEADER_SERVICE_NAME': serviceName | ||
} | ||
} | ||
const body = { | ||
"data": { | ||
"ACCOUNT_NAME": account, | ||
"LOGIN_NAME": user, | ||
"PORT": port, | ||
"PROTOCOL": protocol, | ||
"AUTHENTICATOR": authenticator, | ||
"BROWSER_MODE_REDIRECT_PORT": callback_port.toString() | ||
} | ||
}; | ||
|
||
const httpsClient = new HttpClient(connectionConfig) | ||
const agent = httpsClient.getAgent(url, connectionConfig.getProxy()); | ||
|
||
const requestOptions = | ||
{ | ||
method: 'post', | ||
url: url, | ||
headers: header, | ||
data: body, | ||
requestOCSP: false, | ||
rejectUnauthorized: true, | ||
httpsAgent: agent | ||
}; | ||
|
||
// Post request to get the SSO URL | ||
return axios.request(requestOptions) | ||
.then((response) => { | ||
const data = response['data']['data']; | ||
return data; | ||
}) | ||
.catch(requestErr => { | ||
throw requestErr; | ||
}); | ||
}; | ||
} | ||
|
||
module.exports = SsoUrlProvider; |
Oops, something went wrong.