mirror of
https://github.com/sasjs/adapter.git
synced 2026-01-15 16:10:06 +00:00
Merge branch 'master' into axios-fetch
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
@@ -3490,6 +3490,11 @@
|
|||||||
"sshpk": "^1.7.0"
|
"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": {
|
"https-proxy-agent": {
|
||||||
"version": "5.0.0",
|
"version": "5.0.0",
|
||||||
"resolved": "https://registry.npmjs.org/https-proxy-agent/-/https-proxy-agent-5.0.0.tgz",
|
"resolved": "https://registry.npmjs.org/https-proxy-agent/-/https-proxy-agent-5.0.0.tgz",
|
||||||
|
|||||||
@@ -59,5 +59,6 @@
|
|||||||
"@sasjs/utils": "^2.0.2",
|
"@sasjs/utils": "^2.0.2",
|
||||||
"axios": "^0.21.1",
|
"axios": "^0.21.1",
|
||||||
"form-data": "^3.0.0"
|
"form-data": "^3.0.0"
|
||||||
|
"https": "^1.0.0"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -664,11 +664,13 @@ export class SASViyaApiClient {
|
|||||||
* @param clientId - the client ID to authenticate with.
|
* @param clientId - the client ID to authenticate with.
|
||||||
* @param clientSecret - the client secret to authenticate with.
|
* @param clientSecret - the client secret to authenticate with.
|
||||||
* @param authCode - the auth code received from the server.
|
* @param authCode - the auth code received from the server.
|
||||||
|
* @param insecure - this boolean tells adapter to ignore SSL errors. [Not Recommended]
|
||||||
*/
|
*/
|
||||||
public async getAccessToken(
|
public async getAccessToken(
|
||||||
clientId: string,
|
clientId: string,
|
||||||
clientSecret: string,
|
clientSecret: string,
|
||||||
authCode: string
|
authCode: string,
|
||||||
|
insecure: boolean = false
|
||||||
) {
|
) {
|
||||||
const url = this.serverUrl + '/SASLogon/oauth/token'
|
const url = this.serverUrl + '/SASLogon/oauth/token'
|
||||||
let token
|
let token
|
||||||
@@ -692,12 +694,23 @@ export class SASViyaApiClient {
|
|||||||
formData.append('code', authCode)
|
formData.append('code', authCode)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
let moreOptions = {}
|
||||||
|
if (insecure) {
|
||||||
|
const https = require('https')
|
||||||
|
moreOptions = {
|
||||||
|
agent: new https.Agent({
|
||||||
|
rejectUnauthorized: false
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
const authResponse = await fetch(url, {
|
const authResponse = await fetch(url, {
|
||||||
method: 'POST',
|
method: 'POST',
|
||||||
credentials: 'include',
|
credentials: 'include',
|
||||||
headers,
|
headers,
|
||||||
body: formData as any,
|
body: formData as any,
|
||||||
referrerPolicy: 'same-origin'
|
referrerPolicy: 'same-origin',
|
||||||
|
...moreOptions
|
||||||
}).then((res) => res.json())
|
}).then((res) => res.json())
|
||||||
|
|
||||||
return authResponse
|
return authResponse
|
||||||
|
|||||||
13
src/SASjs.ts
13
src/SASjs.ts
@@ -358,17 +358,26 @@ export default class SASjs {
|
|||||||
return await this.sasViyaApiClient!.getAuthCode(clientId)
|
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(
|
public async getAccessToken(
|
||||||
clientId: string,
|
clientId: string,
|
||||||
clientSecret: string,
|
clientSecret: string,
|
||||||
authCode: string
|
authCode: string,
|
||||||
|
insecure: boolean = false
|
||||||
) {
|
) {
|
||||||
this.isMethodSupported('getAccessToken', ServerType.SasViya)
|
this.isMethodSupported('getAccessToken', ServerType.SasViya)
|
||||||
|
|
||||||
return await this.sasViyaApiClient!.getAccessToken(
|
return await this.sasViyaApiClient!.getAccessToken(
|
||||||
clientId,
|
clientId,
|
||||||
clientSecret,
|
clientSecret,
|
||||||
authCode
|
authCode,
|
||||||
|
insecure
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -26,7 +26,8 @@ const browserConfig = {
|
|||||||
]
|
]
|
||||||
},
|
},
|
||||||
resolve: {
|
resolve: {
|
||||||
extensions: ['.ts', '.js']
|
extensions: ['.ts', '.js'],
|
||||||
|
fallback: { https: false }
|
||||||
},
|
},
|
||||||
output: {
|
output: {
|
||||||
filename: 'index.js',
|
filename: 'index.js',
|
||||||
|
|||||||
Reference in New Issue
Block a user