@microsoft/mgt-element
Advanced tools
Comparing version 3.1.3-preview.ebf5ed3 to 3.1.3-preview.f2547d1
@@ -85,3 +85,3 @@ /** | ||
request.middlewareOptions = (options) => { | ||
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment, @typescript-eslint/no-unsafe-member-access, @typescript-eslint/no-unsafe-call, @typescript-eslint/dot-notation | ||
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment, @typescript-eslint/dot-notation | ||
request['_middlewareOptions'] = request['_middlewareOptions'].concat(options); | ||
@@ -88,0 +88,0 @@ return request; |
@@ -46,3 +46,15 @@ /** | ||
private _baseURL; | ||
private _approvedScopes; | ||
get approvedScopes(): string[]; | ||
set approvedScopes(value: string[]); | ||
hasAtLeastOneApprovedScope(requiredScopeSet: string[]): boolean; | ||
hasAllOneApprovedScope(requiredScopeSet: string[]): boolean; | ||
/** | ||
* Examines the currently consented scopes for any match in the requiredScopeSet to determine what, if any, scopes need to be consented to | ||
* | ||
* @param {string[]} requiredScopeSet an array of scopes to be checked | ||
* @returns {string[]} if any matches in requiredScopeSet exist then an empty array is returns, otherwise an array containing the first element in the requiredScopeSet is returned | ||
*/ | ||
needsAdditionalScopes(requiredScopeSet: string[]): string[]; | ||
/** | ||
* The base URL to be used in the graph client config. | ||
@@ -49,0 +61,0 @@ */ |
@@ -29,3 +29,28 @@ /** | ||
} | ||
get approvedScopes() { | ||
return this._approvedScopes; | ||
} | ||
set approvedScopes(value) { | ||
this._approvedScopes = value.map(v => v.toLowerCase()); | ||
} | ||
hasAtLeastOneApprovedScope(requiredScopeSet) { | ||
return requiredScopeSet.some(s => this.approvedScopes.includes(s.toLowerCase().trim())); | ||
} | ||
hasAllOneApprovedScope(requiredScopeSet) { | ||
return requiredScopeSet.some(s => !this.approvedScopes.includes(s.toLowerCase().trim())); | ||
} | ||
/** | ||
* Examines the currently consented scopes for any match in the requiredScopeSet to determine what, if any, scopes need to be consented to | ||
* | ||
* @param {string[]} requiredScopeSet an array of scopes to be checked | ||
* @returns {string[]} if any matches in requiredScopeSet exist then an empty array is returns, otherwise an array containing the first element in the requiredScopeSet is returned | ||
*/ | ||
needsAdditionalScopes(requiredScopeSet) { | ||
const reqScopes = []; | ||
if (requiredScopeSet.length && !this.hasAtLeastOneApprovedScope(requiredScopeSet)) { | ||
reqScopes.push(requiredScopeSet[0].trim()); | ||
} | ||
return reqScopes; | ||
} | ||
/** | ||
* The base URL to be used in the graph client config. | ||
@@ -113,2 +138,3 @@ */ | ||
this._baseURL = MICROSOFT_GRAPH_DEFAULT_ENDPOINT; | ||
this._approvedScopes = []; | ||
this._customHosts = undefined; | ||
@@ -115,0 +141,0 @@ /** |
@@ -36,3 +36,5 @@ /** | ||
* @param {string} resource | ||
* @param {string[]} [scopes] | ||
* @param {string[]} [scopes] any additional scopes that should be requested | ||
* Note: use `IProvider.needsAdditionalScopes(scopes)` to calculate which | ||
* scopes, if any, need to be requested before calling `Batch.get()` | ||
* @memberof Batch | ||
@@ -39,0 +41,0 @@ */ |
@@ -55,3 +55,5 @@ /** | ||
* @param {string} resource | ||
* @param {string[]} [scopes] | ||
* @param {string[]} [scopes] any additional scopes that should be requested | ||
* Note: use `IProvider.needsAdditionalScopes(scopes)` to calculate which | ||
* scopes, if any, need to be requested before calling `Batch.get()` | ||
* @memberof Batch | ||
@@ -98,3 +100,3 @@ */ | ||
} | ||
const middlewareOptions = this.scopes.length ? prepScopes(...this.scopes) : []; | ||
const middlewareOptions = this.scopes.length ? prepScopes(this.scopes) : []; | ||
const batchRequest = this.graph.api('$batch').middlewareOptions(middlewareOptions); | ||
@@ -101,0 +103,0 @@ const batchRequestBody = yield batchRequestContent.getContent(); |
@@ -31,9 +31,9 @@ /* eslint-disable @typescript-eslint/no-unused-expressions */ | ||
// eql for loose equality | ||
yield expect(prepScopes(...scopes)).to.eql([]); | ||
yield expect(prepScopes(scopes)).to.eql([]); | ||
})); | ||
it('should return an array of AuthenticationHandlerOptions when incremental consent is enabled', () => __awaiter(void 0, void 0, void 0, function* () { | ||
it('should return an array of AuthenticationHandlerOptions when incremental consent is enabled with only the first scope in the list', () => __awaiter(void 0, void 0, void 0, function* () { | ||
const scopes = ['scope1', 'scope2']; | ||
Providers.globalProvider = new MockProvider(true); | ||
Providers.globalProvider.isIncrementalConsentDisabled = false; | ||
yield expect(prepScopes(...scopes)).to.eql([new AuthenticationHandlerOptions(undefined, { scopes })]); | ||
yield expect(prepScopes(scopes)).to.eql([new AuthenticationHandlerOptions(undefined, { scopes: ['scope1'] })]); | ||
})); | ||
@@ -40,0 +40,0 @@ }); |
@@ -16,3 +16,3 @@ /** | ||
*/ | ||
export declare const prepScopes: (...scopes: string[]) => AuthenticationHandlerOptions[]; | ||
export declare const prepScopes: (scopes: string[], provider?: import("..").IProvider) => AuthenticationHandlerOptions[]; | ||
//# sourceMappingURL=prepScopes.d.ts.map |
@@ -17,7 +17,8 @@ /** | ||
*/ | ||
export const prepScopes = (...scopes) => { | ||
export const prepScopes = (scopes, provider = Providers.globalProvider) => { | ||
const additionalScopes = provider.needsAdditionalScopes(scopes); | ||
const authProviderOptions = { | ||
scopes | ||
scopes: additionalScopes | ||
}; | ||
if (!Providers.globalProvider.isIncrementalConsentDisabled) { | ||
if (!provider.isIncrementalConsentDisabled) { | ||
return [new AuthenticationHandlerOptions(undefined, authProviderOptions)]; | ||
@@ -24,0 +25,0 @@ } |
@@ -7,3 +7,3 @@ /** | ||
*/ | ||
export declare const PACKAGE_VERSION = "3.1.3-preview.ebf5ed3"; | ||
export declare const PACKAGE_VERSION = "3.1.3-preview.f2547d1"; | ||
//# sourceMappingURL=version.d.ts.map |
@@ -9,3 +9,3 @@ /** | ||
// ANY CHANGES WILL BE LOST DURING BUILD | ||
export const PACKAGE_VERSION = '3.1.3-preview.ebf5ed3'; | ||
export const PACKAGE_VERSION = '3.1.3-preview.f2547d1'; | ||
//# sourceMappingURL=version.js.map |
{ | ||
"name": "@microsoft/mgt-element", | ||
"version": "3.1.3-preview.ebf5ed3", | ||
"version": "3.1.3-preview.f2547d1", | ||
"description": "Microsoft Graph Toolkit base classes", | ||
@@ -5,0 +5,0 @@ "homepage": "https://github.com/microsoftgraph/microsoft-graph-toolkit", |
@@ -110,4 +110,4 @@ /** | ||
request.middlewareOptions = (options: MiddlewareOptions[]): GraphRequest => { | ||
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment, @typescript-eslint/no-unsafe-member-access, @typescript-eslint/no-unsafe-call, @typescript-eslint/dot-notation | ||
request['_middlewareOptions'] = request['_middlewareOptions'].concat(options); | ||
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment, @typescript-eslint/dot-notation | ||
request['_middlewareOptions'] = (request['_middlewareOptions'] as MiddlewareOptions[]).concat(options); | ||
return request; | ||
@@ -114,0 +114,0 @@ }; |
@@ -49,2 +49,3 @@ /** | ||
} | ||
private _state: ProviderState; | ||
@@ -55,3 +56,34 @@ private readonly _loginChangedDispatcher = new EventDispatcher<LoginChangedEvent>(); | ||
private _approvedScopes: string[] = []; | ||
public get approvedScopes(): string[] { | ||
return this._approvedScopes; | ||
} | ||
public set approvedScopes(value: string[]) { | ||
this._approvedScopes = value.map(v => v.toLowerCase()); | ||
} | ||
public hasAtLeastOneApprovedScope(requiredScopeSet: string[]): boolean { | ||
return requiredScopeSet.some(s => this.approvedScopes.includes(s.toLowerCase().trim())); | ||
} | ||
public hasAllOneApprovedScope(requiredScopeSet: string[]): boolean { | ||
return requiredScopeSet.some(s => !this.approvedScopes.includes(s.toLowerCase().trim())); | ||
} | ||
/** | ||
* Examines the currently consented scopes for any match in the requiredScopeSet to determine what, if any, scopes need to be consented to | ||
* | ||
* @param {string[]} requiredScopeSet an array of scopes to be checked | ||
* @returns {string[]} if any matches in requiredScopeSet exist then an empty array is returns, otherwise an array containing the first element in the requiredScopeSet is returned | ||
*/ | ||
public needsAdditionalScopes(requiredScopeSet: string[]): string[] { | ||
const reqScopes: string[] = []; | ||
if (requiredScopeSet.length && !this.hasAtLeastOneApprovedScope(requiredScopeSet)) { | ||
reqScopes.push(requiredScopeSet[0].trim()); | ||
} | ||
return reqScopes; | ||
} | ||
/** | ||
* The base URL to be used in the graph client config. | ||
@@ -58,0 +90,0 @@ */ |
@@ -61,3 +61,5 @@ /** | ||
* @param {string} resource | ||
* @param {string[]} [scopes] | ||
* @param {string[]} [scopes] any additional scopes that should be requested | ||
* Note: use `IProvider.needsAdditionalScopes(scopes)` to calculate which | ||
* scopes, if any, need to be requested before calling `Batch.get()` | ||
* @memberof Batch | ||
@@ -110,3 +112,3 @@ */ | ||
const middlewareOptions: MiddlewareOptions[] = this.scopes.length ? prepScopes(...this.scopes) : []; | ||
const middlewareOptions: MiddlewareOptions[] = this.scopes.length ? prepScopes(this.scopes) : []; | ||
const batchRequest = this.graph.api('$batch').middlewareOptions(middlewareOptions); | ||
@@ -113,0 +115,0 @@ |
@@ -24,9 +24,9 @@ /* eslint-disable @typescript-eslint/no-unused-expressions */ | ||
// eql for loose equality | ||
await expect(prepScopes(...scopes)).to.eql([]); | ||
await expect(prepScopes(scopes)).to.eql([]); | ||
}); | ||
it('should return an array of AuthenticationHandlerOptions when incremental consent is enabled', async () => { | ||
it('should return an array of AuthenticationHandlerOptions when incremental consent is enabled with only the first scope in the list', async () => { | ||
const scopes = ['scope1', 'scope2']; | ||
Providers.globalProvider = new MockProvider(true); | ||
Providers.globalProvider.isIncrementalConsentDisabled = false; | ||
await expect(prepScopes(...scopes)).to.eql([new AuthenticationHandlerOptions(undefined, { scopes })]); | ||
await expect(prepScopes(scopes)).to.eql([new AuthenticationHandlerOptions(undefined, { scopes: ['scope1'] })]); | ||
}); | ||
@@ -33,0 +33,0 @@ }); |
@@ -20,8 +20,9 @@ /** | ||
export const prepScopes = (...scopes: string[]) => { | ||
export const prepScopes = (scopes: string[], provider = Providers.globalProvider) => { | ||
const additionalScopes = provider.needsAdditionalScopes(scopes); | ||
const authProviderOptions = { | ||
scopes | ||
scopes: additionalScopes | ||
}; | ||
if (!Providers.globalProvider.isIncrementalConsentDisabled) { | ||
if (!provider.isIncrementalConsentDisabled) { | ||
return [new AuthenticationHandlerOptions(undefined, authProviderOptions)]; | ||
@@ -28,0 +29,0 @@ } else { |
@@ -11,2 +11,2 @@ /** | ||
export const PACKAGE_VERSION = '3.1.3-preview.ebf5ed3'; | ||
export const PACKAGE_VERSION = '3.1.3-preview.f2547d1'; |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
666903
233
10117