From de25f106ec0462a68ea2abd7f4adbe8a4e71a022 Mon Sep 17 00:00:00 2001 From: Saad Jutt Date: Tue, 26 Jan 2021 17:17:46 +0500 Subject: [PATCH 1/4] 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 ) } From 39924ff07808593f43e66926be8138aa10f0618b Mon Sep 17 00:00:00 2001 From: Saad Jutt Date: Tue, 26 Jan 2021 18:45:21 +0500 Subject: [PATCH 2/4] chore: added 'https' --- package-lock.json | 5 +++++ package.json | 1 + webpack.config.js | 3 ++- 3 files changed, 8 insertions(+), 1 deletion(-) diff --git a/package-lock.json b/package-lock.json index fbd1a3f..595dcf3 100644 --- a/package-lock.json +++ b/package-lock.json @@ -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", diff --git a/package.json b/package.json index 68e505d..f4459ee 100644 --- a/package.json +++ b/package.json @@ -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" } } diff --git a/webpack.config.js b/webpack.config.js index 9801b10..22b13f9 100644 --- a/webpack.config.js +++ b/webpack.config.js @@ -26,7 +26,8 @@ const browserConfig = { ] }, resolve: { - extensions: ['.ts', '.js'] + extensions: ['.ts', '.js'], + fallback: { https: false } }, output: { filename: 'index.js', From 8d203b8df4912257fdfa7ed013599808a0910bf7 Mon Sep 17 00:00:00 2001 From: Saad Jutt Date: Wed, 27 Jan 2021 15:47:15 +0500 Subject: [PATCH 3/4] chore: annotation added --- src/SASjs.ts | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/SASjs.ts b/src/SASjs.ts index e93473d..c57c870 100644 --- a/src/SASjs.ts +++ b/src/SASjs.ts @@ -386,6 +386,13 @@ 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, From 1fc6db114dfce5d83535038ccfe915600aae3f1a Mon Sep 17 00:00:00 2001 From: Saad Jutt Date: Wed, 27 Jan 2021 15:57:21 +0500 Subject: [PATCH 4/4] chore: docs updated --- docs/classes/root.contextmanager.html | 2 +- docs/classes/root.fileuploader.html | 2 +- docs/classes/root.sas9apiclient.html | 2 +- docs/classes/root.sasjs.html | 100 +++++++++++------- docs/classes/root.sasviyaapiclient.html | 54 +++++----- docs/classes/root.sessionmanager.html | 22 ++-- docs/classes/types.errorresponse.html | 2 +- docs/classes/types.sasjsconfig.html | 2 +- docs/enums/types.servertype.html | 2 +- docs/globals.html | 2 +- docs/index.html | 5 +- docs/interfaces/types.context.html | 2 +- .../types.contextallattributes.html | 2 +- docs/interfaces/types.csrftoken.html | 2 +- docs/interfaces/types.editcontextinput.html | 2 +- docs/interfaces/types.folder.html | 2 +- docs/interfaces/types.job.html | 2 +- docs/interfaces/types.jobdefinition.html | 2 +- docs/interfaces/types.jobresult.html | 2 +- docs/interfaces/types.link.html | 2 +- docs/interfaces/types.polloptions.html | 2 +- docs/interfaces/types.sasjsrequest.html | 2 +- .../interfaces/types.sasjswaitingrequest.html | 2 +- docs/interfaces/types.session.html | 2 +- docs/interfaces/types.sessionvariable.html | 2 +- docs/interfaces/types.uploadfile.html | 2 +- docs/modules/root.html | 2 +- docs/modules/types.html | 2 +- docs/modules/utils.html | 2 +- 29 files changed, 129 insertions(+), 102 deletions(-) diff --git a/docs/classes/root.contextmanager.html b/docs/classes/root.contextmanager.html index abc4946..b96c06a 100644 --- a/docs/classes/root.contextmanager.html +++ b/docs/classes/root.contextmanager.html @@ -538,7 +538,7 @@ - +
+
  • +
    Default value insecure: boolean = false
    +
    +

    this boolean tells adapter to ignore SSL errors. [Not Recommended]

    +
    +
  • Returns Promise<any>

    @@ -1012,8 +1018,8 @@ - +
    - +
    - +
    - +