@adobe/helix-onedrive-support 6.1.5 → 6.2.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/.nycrc.json +3 -3
- package/CHANGELOG.md +7 -0
- package/package.json +1 -1
- package/src/OneDrive.js +11 -9
package/.nycrc.json
CHANGED
package/CHANGELOG.md
CHANGED
|
@@ -1,3 +1,10 @@
|
|
|
1
|
+
# [6.2.0](https://github.com/adobe/helix-onedrive-support/compare/v6.1.5...v6.2.0) (2022-03-01)
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
### Features
|
|
5
|
+
|
|
6
|
+
* allow to set authentication resource ([#246](https://github.com/adobe/helix-onedrive-support/issues/246)) ([21d7445](https://github.com/adobe/helix-onedrive-support/commit/21d7445736bfe7452b710187cc81e71b37df8542))
|
|
7
|
+
|
|
1
8
|
## [6.1.5](https://github.com/adobe/helix-onedrive-support/compare/v6.1.4...v6.1.5) (2022-02-28)
|
|
2
9
|
|
|
3
10
|
|
package/package.json
CHANGED
package/src/OneDrive.js
CHANGED
|
@@ -31,7 +31,7 @@ const { fetch, reset } = process.env.HELIX_FETCH_FORCE_HTTP1
|
|
|
31
31
|
: fetchAPI;
|
|
32
32
|
|
|
33
33
|
const AZ_AUTHORITY_HOST_URL = 'https://login.windows.net';
|
|
34
|
-
const
|
|
34
|
+
const AZ_DEFAULT_RESOURCE = 'https://graph.microsoft.com'; // '00000002-0000-0000-c000-000000000000'; ??
|
|
35
35
|
const AZ_DEFAULT_TENANT = 'common';
|
|
36
36
|
|
|
37
37
|
/**
|
|
@@ -65,6 +65,7 @@ class OneDrive extends EventEmitter {
|
|
|
65
65
|
* @param {number} [opts.expiresOn] Expiration time.
|
|
66
66
|
* @param {Logger} [opts.log] A logger.
|
|
67
67
|
* @param {boolean} [opts.localAuthCache] Whether to use local auth cache
|
|
68
|
+
* @param {string} [opts.resource] Azure resource to authenticate against. defaults to MS Graph.
|
|
68
69
|
*/
|
|
69
70
|
constructor(opts) {
|
|
70
71
|
super(opts);
|
|
@@ -75,6 +76,7 @@ class OneDrive extends EventEmitter {
|
|
|
75
76
|
this.password = opts.password || '';
|
|
76
77
|
this._log = opts.log || console;
|
|
77
78
|
this.tenant = opts.tenant || AZ_DEFAULT_TENANT;
|
|
79
|
+
this.resource = opts.resource || AZ_DEFAULT_RESOURCE;
|
|
78
80
|
|
|
79
81
|
if (!opts.noShareLinkCache && !process.env.HELIX_ONEDRIVE_NO_SHARE_LINK_CACHE) {
|
|
80
82
|
this.shareLinkCache = opts.shareLinkCache || globalShareLinkCache;
|
|
@@ -168,7 +170,7 @@ class OneDrive extends EventEmitter {
|
|
|
168
170
|
|
|
169
171
|
let code;
|
|
170
172
|
try {
|
|
171
|
-
code = await context.acquireUserCode(
|
|
173
|
+
code = await context.acquireUserCode(this.resource, this.clientId, 'en');
|
|
172
174
|
} catch (e) {
|
|
173
175
|
log.error('Error while requesting user code', e);
|
|
174
176
|
throw e;
|
|
@@ -180,7 +182,7 @@ class OneDrive extends EventEmitter {
|
|
|
180
182
|
}
|
|
181
183
|
|
|
182
184
|
try {
|
|
183
|
-
return await context.acquireTokenWithDeviceCode(
|
|
185
|
+
return await context.acquireTokenWithDeviceCode(this.resource, this.clientId, code);
|
|
184
186
|
} catch (e) {
|
|
185
187
|
log.error('Error while requesting access token with device code', e);
|
|
186
188
|
throw e;
|
|
@@ -192,7 +194,7 @@ class OneDrive extends EventEmitter {
|
|
|
192
194
|
async getAccessToken() {
|
|
193
195
|
const { log, authContext: context } = this;
|
|
194
196
|
try {
|
|
195
|
-
return await context.acquireToken(
|
|
197
|
+
return await context.acquireToken(this.resource, this.username, this.clientId);
|
|
196
198
|
} catch (e) {
|
|
197
199
|
if (e.message !== 'Entry not found in cache.') {
|
|
198
200
|
log.warn(`Unable to acquire token from cache: ${e}`);
|
|
@@ -208,13 +210,13 @@ class OneDrive extends EventEmitter {
|
|
|
208
210
|
this.refreshToken,
|
|
209
211
|
this.clientId,
|
|
210
212
|
this.clientSecret,
|
|
211
|
-
|
|
213
|
+
this.resource,
|
|
212
214
|
);
|
|
213
215
|
return await this.augmentAndCacheResponse(resp);
|
|
214
216
|
} else if (this.username && this.password) {
|
|
215
217
|
log.debug('acquire token with ROPC.');
|
|
216
218
|
return await context.acquireTokenWithUsernamePassword(
|
|
217
|
-
|
|
219
|
+
this.resource,
|
|
218
220
|
this.username,
|
|
219
221
|
this.password,
|
|
220
222
|
this.clientId,
|
|
@@ -222,7 +224,7 @@ class OneDrive extends EventEmitter {
|
|
|
222
224
|
} else if (this.clientSecret) {
|
|
223
225
|
log.debug('acquire token with client credentials.');
|
|
224
226
|
return await context.acquireTokenWithClientCredentials(
|
|
225
|
-
|
|
227
|
+
this.resource,
|
|
226
228
|
this.clientId,
|
|
227
229
|
this.clientSecret,
|
|
228
230
|
);
|
|
@@ -240,7 +242,7 @@ class OneDrive extends EventEmitter {
|
|
|
240
242
|
/**
|
|
241
243
|
*/
|
|
242
244
|
createLoginUrl(redirectUri, state) {
|
|
243
|
-
return `${this.authorityUrl}/oauth2/authorize?response_type=code&scope=/.default&client_id=${this.clientId}&redirect_uri=${redirectUri}&state=${state}&resource=${
|
|
245
|
+
return `${this.authorityUrl}/oauth2/authorize?response_type=code&scope=/.default&client_id=${this.clientId}&redirect_uri=${redirectUri}&state=${state}&resource=${this.resource}`;
|
|
244
246
|
}
|
|
245
247
|
|
|
246
248
|
async augmentAndCacheResponse(response) {
|
|
@@ -270,7 +272,7 @@ class OneDrive extends EventEmitter {
|
|
|
270
272
|
const resp = await context.acquireTokenWithAuthorizationCode(
|
|
271
273
|
code,
|
|
272
274
|
redirectUri,
|
|
273
|
-
|
|
275
|
+
this.resource,
|
|
274
276
|
this.clientId,
|
|
275
277
|
this.clientSecret,
|
|
276
278
|
);
|