From de25f106ec0462a68ea2abd7f4adbe8a4e71a022 Mon Sep 17 00:00:00 2001 From: Saad Jutt Date: Tue, 26 Jan 2021 17:17:46 +0500 Subject: [PATCH] feat: enable insecure connection for accessToken --- src/SASViyaApiClient.ts | 17 +++++++++++++++-- src/SASjs.ts | 6 ++++-- 2 files changed, 19 insertions(+), 4 deletions(-) diff --git a/src/SASViyaApiClient.ts b/src/SASViyaApiClient.ts index bac2d8e..c44decd 100644 --- a/src/SASViyaApiClient.ts +++ b/src/SASViyaApiClient.ts @@ -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 diff --git a/src/SASjs.ts b/src/SASjs.ts index 1d3281a..e93473d 100644 --- a/src/SASjs.ts +++ b/src/SASjs.ts @@ -389,14 +389,16 @@ export default class SASjs { 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 ) }