@adobe/helix-onedrive-support 11.4.0 → 11.5.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +14 -0
- package/package.json +6 -6
- package/src/OneDriveAuth.js +39 -14
package/CHANGELOG.md
CHANGED
|
@@ -1,3 +1,17 @@
|
|
|
1
|
+
# [11.5.0](https://github.com/adobe/helix-onedrive-support/compare/v11.4.1...v11.5.0) (2024-07-09)
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
### Features
|
|
5
|
+
|
|
6
|
+
* support custom client id (as appName) in metadata ([#553](https://github.com/adobe/helix-onedrive-support/issues/553)) ([eebff24](https://github.com/adobe/helix-onedrive-support/commit/eebff24e8d2160f0133bebde21b779b16bbe832e))
|
|
7
|
+
|
|
8
|
+
## [11.4.1](https://github.com/adobe/helix-onedrive-support/compare/v11.4.0...v11.4.1) (2024-07-06)
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
### Bug Fixes
|
|
12
|
+
|
|
13
|
+
* **deps:** update dependency @adobe/helix-shared-tokencache to v1.4.17 ([3b2249e](https://github.com/adobe/helix-onedrive-support/commit/3b2249ecce99084058fd073ae4e25260d6056d97))
|
|
14
|
+
|
|
1
15
|
# [11.4.0](https://github.com/adobe/helix-onedrive-support/compare/v11.3.38...v11.4.0) (2024-07-02)
|
|
2
16
|
|
|
3
17
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@adobe/helix-onedrive-support",
|
|
3
|
-
"version": "11.
|
|
3
|
+
"version": "11.5.0",
|
|
4
4
|
"description": "Helix OneDrive Support",
|
|
5
5
|
"main": "src/index.js",
|
|
6
6
|
"exports": {
|
|
@@ -29,13 +29,13 @@
|
|
|
29
29
|
"homepage": "https://github.com/adobe/helix-onedrive-support#readme",
|
|
30
30
|
"dependencies": {
|
|
31
31
|
"@adobe/fetch": "4.1.8",
|
|
32
|
-
"@adobe/helix-shared-tokencache": "1.4.
|
|
33
|
-
"@azure/msal-node": "2.
|
|
34
|
-
"jose": "5.6.
|
|
32
|
+
"@adobe/helix-shared-tokencache": "1.4.17",
|
|
33
|
+
"@azure/msal-node": "2.10.0",
|
|
34
|
+
"jose": "5.6.3"
|
|
35
35
|
},
|
|
36
36
|
"devDependencies": {
|
|
37
37
|
"@adobe/eslint-config-helix": "2.0.6",
|
|
38
|
-
"@aws-sdk/client-s3": "3.
|
|
38
|
+
"@aws-sdk/client-s3": "3.609.0",
|
|
39
39
|
"@semantic-release/changelog": "6.0.3",
|
|
40
40
|
"@semantic-release/git": "10.0.1",
|
|
41
41
|
"ajv": "8.16.0",
|
|
@@ -51,7 +51,7 @@
|
|
|
51
51
|
"jsdoc-tsimport-plugin": "1.0.5",
|
|
52
52
|
"junit-report-builder": "3.2.1",
|
|
53
53
|
"lint-staged": "15.2.7",
|
|
54
|
-
"mocha": "10.
|
|
54
|
+
"mocha": "10.6.0",
|
|
55
55
|
"mocha-multi-reporters": "1.5.1",
|
|
56
56
|
"mocha-suppress-logs": "0.5.1",
|
|
57
57
|
"nock": "13.5.4",
|
package/src/OneDriveAuth.js
CHANGED
|
@@ -46,11 +46,24 @@ export const AcquireMethod = {
|
|
|
46
46
|
*/
|
|
47
47
|
const globalTenantCache = new Map();
|
|
48
48
|
|
|
49
|
+
/**
|
|
50
|
+
* Return client id and secret stored in the process, matching an application name given.
|
|
51
|
+
* @param {String} appName application name, e.g. `HELIX_SERVICE`, or undefined
|
|
52
|
+
* @returns {Object} containing `clientId` and `clientSecret` or an empty object
|
|
53
|
+
*/
|
|
54
|
+
function getClientIdAndSecret(appName) {
|
|
55
|
+
if (appName) {
|
|
56
|
+
const clientId = process.env[`AZURE_${appName.toUpperCase()}_CLIENT_ID`];
|
|
57
|
+
const clientSecret = process.env[`AZURE_${appName.toUpperCase()}_CLIENT_SECRET`];
|
|
58
|
+
if (clientId && clientSecret) {
|
|
59
|
+
return { clientId, clientSecret };
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
return {};
|
|
63
|
+
}
|
|
64
|
+
|
|
49
65
|
/**
|
|
50
66
|
* Helper class that facilitates accessing one drive.
|
|
51
|
-
*
|
|
52
|
-
* @class
|
|
53
|
-
* @field {ConfidentialClientApplication|PublicClientApplication} app
|
|
54
67
|
*/
|
|
55
68
|
export class OneDriveAuth {
|
|
56
69
|
/**
|
|
@@ -73,6 +86,8 @@ export class OneDriveAuth {
|
|
|
73
86
|
this.clientSecret = opts.clientSecret || '';
|
|
74
87
|
this._log = opts.log || console;
|
|
75
88
|
this.tenant = opts.tenant;
|
|
89
|
+
|
|
90
|
+
/** @type {import('@adobe/helix-shared-tokencache/src/CachePlugin.js').CachePlugin} */
|
|
76
91
|
this.cachePlugin = opts.cachePlugin;
|
|
77
92
|
this.scopes = opts.scopes || DEFAULT_SCOPES;
|
|
78
93
|
this.onCode = opts.onCode;
|
|
@@ -110,16 +125,25 @@ export class OneDriveAuth {
|
|
|
110
125
|
}
|
|
111
126
|
}
|
|
112
127
|
|
|
113
|
-
|
|
128
|
+
/**
|
|
129
|
+
* Gets the client application, creating it if necessary.
|
|
130
|
+
*
|
|
131
|
+
* @returns {import("@azure/msal-node").ClientApplication} client application
|
|
132
|
+
*/
|
|
133
|
+
async getApp() {
|
|
114
134
|
if (!this._app) {
|
|
115
|
-
const {
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
135
|
+
const { log, cachePlugin } = this;
|
|
136
|
+
|
|
137
|
+
const metadata = await cachePlugin.getPluginMetadata();
|
|
138
|
+
if (metadata?.useClientCredentials) {
|
|
139
|
+
this.pluginUseClientCredentials = true;
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
const { clientId, clientSecret } = getClientIdAndSecret(metadata?.appName);
|
|
119
143
|
const msalConfig = {
|
|
120
144
|
auth: {
|
|
121
|
-
clientId: this.clientId,
|
|
122
|
-
clientSecret: this.clientSecret,
|
|
145
|
+
clientId: clientId ?? this.clientId,
|
|
146
|
+
clientSecret: clientSecret ?? this.clientSecret,
|
|
123
147
|
authority: this.getAuthorityUrl(),
|
|
124
148
|
},
|
|
125
149
|
system: {
|
|
@@ -241,7 +265,8 @@ export class OneDriveAuth {
|
|
|
241
265
|
* @returns {boolean}
|
|
242
266
|
*/
|
|
243
267
|
async isAuthenticated() {
|
|
244
|
-
const
|
|
268
|
+
const app = await this.getApp();
|
|
269
|
+
const accounts = await app.getTokenCache().getAllAccounts();
|
|
245
270
|
return accounts.length > 0;
|
|
246
271
|
}
|
|
247
272
|
|
|
@@ -286,8 +311,9 @@ export class OneDriveAuth {
|
|
|
286
311
|
* @returns {Promise<null|AuthenticationResult>}
|
|
287
312
|
*/
|
|
288
313
|
async doAuthenticate(silentOnly) {
|
|
289
|
-
const { log
|
|
314
|
+
const { log } = this;
|
|
290
315
|
|
|
316
|
+
const app = await this.getApp();
|
|
291
317
|
let accounts = await app.getTokenCache().getAllAccounts();
|
|
292
318
|
if (accounts.length > 0) {
|
|
293
319
|
let account = accounts[0];
|
|
@@ -334,8 +360,7 @@ export class OneDriveAuth {
|
|
|
334
360
|
});
|
|
335
361
|
}
|
|
336
362
|
if (this.acquireMethod === AcquireMethod.BY_CLIENT_CREDENTIAL
|
|
337
|
-
|
|
338
|
-
|| (await this.cachePlugin.getPluginMetadata() || {}).useClientCredentials) {
|
|
363
|
+
|| this.pluginUseClientCredentials) {
|
|
339
364
|
log.debug('acquire token with client credentials.');
|
|
340
365
|
return await app.acquireTokenByClientCredential({
|
|
341
366
|
scopes: this.scopes,
|