mirror of
https://github.com/sasjs/adapter.git
synced 2025-12-11 09:24:35 +00:00
Merge pull request #231 from sasjs/insecure-connection
feat: enable insecure connection for accessToken
This commit is contained in:
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
5
package-lock.json
generated
5
package-lock.json
generated
@@ -3837,6 +3837,11 @@
|
||||
"sshpk": "^1.7.0"
|
||||
}
|
||||
},
|
||||
"https": {
|
||||
"version": "1.0.0",
|
||||
"resolved": "https://registry.npmjs.org/https/-/https-1.0.0.tgz",
|
||||
"integrity": "sha1-PDfHrhqO65ZpBKKtHpdaGUt+06Q="
|
||||
},
|
||||
"https-proxy-agent": {
|
||||
"version": "5.0.0",
|
||||
"resolved": "https://registry.npmjs.org/https-proxy-agent/-/https-proxy-agent-5.0.0.tgz",
|
||||
|
||||
@@ -61,6 +61,7 @@
|
||||
"@sasjs/utils": "^2.0.2",
|
||||
"es6-promise": "^4.2.8",
|
||||
"form-data": "^3.0.0",
|
||||
"https": "^1.0.0",
|
||||
"isomorphic-fetch": "^2.2.1"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -701,11 +701,13 @@ export class SASViyaApiClient {
|
||||
* @param clientId - the client ID to authenticate with.
|
||||
* @param clientSecret - the client secret to authenticate with.
|
||||
* @param authCode - the auth code received from the server.
|
||||
* @param insecure - this boolean tells adapter to ignore SSL errors. [Not Recommended]
|
||||
*/
|
||||
public async getAccessToken(
|
||||
clientId: string,
|
||||
clientSecret: string,
|
||||
authCode: string
|
||||
authCode: string,
|
||||
insecure: boolean = false
|
||||
) {
|
||||
const url = this.serverUrl + '/SASLogon/oauth/token'
|
||||
let token
|
||||
@@ -729,12 +731,23 @@ export class SASViyaApiClient {
|
||||
formData.append('code', authCode)
|
||||
}
|
||||
|
||||
let moreOptions = {}
|
||||
if (insecure) {
|
||||
const https = require('https')
|
||||
moreOptions = {
|
||||
agent: new https.Agent({
|
||||
rejectUnauthorized: false
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
const authResponse = await fetch(url, {
|
||||
method: 'POST',
|
||||
credentials: 'include',
|
||||
headers,
|
||||
body: formData as any,
|
||||
referrerPolicy: 'same-origin'
|
||||
referrerPolicy: 'same-origin',
|
||||
...moreOptions
|
||||
}).then((res) => res.json())
|
||||
|
||||
return authResponse
|
||||
|
||||
13
src/SASjs.ts
13
src/SASjs.ts
@@ -386,17 +386,26 @@ export default class SASjs {
|
||||
return await this.sasViyaApiClient!.getAuthCode(clientId)
|
||||
}
|
||||
|
||||
/**
|
||||
* Exchanges the auth code for an access token for the given client.
|
||||
* @param clientId - the client ID to authenticate with.
|
||||
* @param clientSecret - the client secret to authenticate with.
|
||||
* @param authCode - the auth code received from the server.
|
||||
* @param insecure - this boolean tells adapter to ignore SSL errors. [Not Recommended]
|
||||
*/
|
||||
public async getAccessToken(
|
||||
clientId: string,
|
||||
clientSecret: string,
|
||||
authCode: string
|
||||
authCode: string,
|
||||
insecure: boolean = false
|
||||
) {
|
||||
this.isMethodSupported('getAccessToken', ServerType.SASViya)
|
||||
|
||||
return await this.sasViyaApiClient!.getAccessToken(
|
||||
clientId,
|
||||
clientSecret,
|
||||
authCode
|
||||
authCode,
|
||||
insecure
|
||||
)
|
||||
}
|
||||
|
||||
|
||||
@@ -26,7 +26,8 @@ const browserConfig = {
|
||||
]
|
||||
},
|
||||
resolve: {
|
||||
extensions: ['.ts', '.js']
|
||||
extensions: ['.ts', '.js'],
|
||||
fallback: { https: false }
|
||||
},
|
||||
output: {
|
||||
filename: 'index.js',
|
||||
|
||||
Reference in New Issue
Block a user