-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #12 from polarityio/develop
Add proxy support and improved msal-node logging
- Loading branch information
Showing
5 changed files
with
157 additions
and
20 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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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 |
---|---|---|
@@ -1,15 +1,15 @@ | ||
{ | ||
"name": "sharepoint", | ||
"version": "3.5.1", | ||
"version": "3.5.2", | ||
"main": "./integration.js", | ||
"private": true, | ||
"license": "MIT", | ||
"author": "Polarity", | ||
"dependencies": { | ||
"async": "^3.2.4", | ||
"async": "^3.2.5", | ||
"node-cache": "^5.1.2", | ||
"postman-request": "^2.88.1-postman.33", | ||
"xbytes": "^1.8.0", | ||
"@azure/msal-node": "1.18.3" | ||
"@azure/msal-node": "1.18.4" | ||
} | ||
} |
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,60 @@ | ||
/* | ||
* Copyright (c) 2023, Polarity.io, Inc. | ||
*/ | ||
|
||
/** | ||
* Implements the msal-node `networkClient` interface using `postman-request` as the underlying HTTP client so that | ||
* proxy support is available. | ||
* See: https://github.com/AzureAD/microsoft-authentication-library-for-js/issues/2600#issuecomment-831299149 | ||
* | ||
* The msal-node library originally used gaxios which does not have proper proxy support. To work around this | ||
* msal-node implemented their own `networkClient` interface which should support proxies but it does not always | ||
* work. | ||
*/ | ||
class SharepointHttpAuthClient { | ||
constructor(requestWithDefaults, Logger) { | ||
this.requestWithDefaults = requestWithDefaults; | ||
this.logger = Logger; | ||
} | ||
|
||
getClient() { | ||
return { | ||
sendGetRequestAsync: this.sendGetRequestAsync.bind(this), | ||
sendPostRequestAsync: this.sendPostRequestAsync.bind(this) | ||
}; | ||
} | ||
|
||
async sendGetRequestAsync(uri, options) { | ||
this.logger.trace({ uri, options }, 'sendGetRequestAsync'); | ||
return this.sendAsyncRequest(uri, 'GET', options); | ||
} | ||
|
||
async sendPostRequestAsync(uri, options) { | ||
this.logger.trace({ uri, options }, 'sendPostRequestAsync'); | ||
return this.sendAsyncRequest(uri, 'POST', options); | ||
} | ||
|
||
async sendAsyncRequest(uri, method, options) { | ||
return new Promise((resolve, reject) => { | ||
const requestOptions = { | ||
uri, | ||
method, | ||
json: true, | ||
...options | ||
}; | ||
this.requestWithDefaults(requestOptions, (err, response, body) => { | ||
if (err) { | ||
return reject(err); | ||
} | ||
|
||
resolve({ | ||
headers: response.headers, | ||
body, | ||
status: response.status | ||
}); | ||
}); | ||
}); | ||
} | ||
} | ||
|
||
module.exports = SharepointHttpAuthClient; |