Skip to content

Commit 448db9a

Browse files
amrutha95Amrutha Srinivasannmetulev
authored
added incremental consent disable option (#1384)
Co-authored-by: Amrutha Srinivasan <[email protected]> Co-authored-by: Nikola Metulev <[email protected]>
1 parent 8f6b77e commit 448db9a

File tree

3 files changed

+39
-0
lines changed

3 files changed

+39
-0
lines changed

packages/providers/mgt-msal2-provider/README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ The `@microsoft/mgt-msal2-provider` package exposes the `Msal2Provider` class wh
3232
sid?: string, // Session ID
3333
loginHint?: string,
3434
domainHint?: string,
35+
isIncrementalConsentDisabled?: boolean, //Disable incremental consent, true by default
3536
options?: Configuration // msal js Configuration object
3637
});
3738
```
@@ -54,6 +55,7 @@ The `@microsoft/mgt-msal2-provider` package exposes the `Msal2Provider` class wh
5455
sid?: string, // Session ID
5556
loginHint?: string,
5657
domainHint?: string,
58+
isIncrementalConsentDisabled?: boolean, //Disable incremental consent, true by default
5759
options?: Configuration // msal js Configuration object
5860
});
5961
```
@@ -70,6 +72,7 @@ The `@microsoft/mgt-msal2-provider` package exposes the `Msal2Provider` class wh
7072
authority="">
7173
</mgt-msal2-provider>
7274
```
75+
Add the `incremental-consent-disabled` boolean attribute if you wish to disable incremental consent.
7376

7477
See [provider usage documentation](https://docs.microsoft.com/graph/toolkit/providers) to learn about how to use the providers with the mgt components, to sign in/sign out, get access tokens, call Microsoft Graph, and more.
7578

packages/providers/mgt-msal2-provider/src/Msal2Provider.ts

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,14 @@ interface Msal2ConfigBase {
9393
* @memberof Msal2Config
9494
*/
9595
sid?: string;
96+
97+
/**
98+
* Specifies if incremental consent is disabled
99+
*
100+
* @type {boolean}
101+
* @memberof Msal2ConfigBase
102+
*/
103+
isIncrementalConsentDisabled?: boolean;
96104
}
97105

98106
/**
@@ -191,6 +199,14 @@ export class Msal2Provider extends IProvider {
191199
*/
192200
private _sid;
193201

202+
/**
203+
* Specifies if incremental consent is disabled
204+
*
205+
* @type {boolean}
206+
* @memberof Msal2ConfigBase
207+
*/
208+
private _isIncrementalConsentDisabled: boolean = false;
209+
194210
/**
195211
* Configuration settings for authentication
196212
*
@@ -287,6 +303,8 @@ export class Msal2Provider extends IProvider {
287303
this._loginType = typeof config.loginType !== 'undefined' ? config.loginType : LoginType.Redirect;
288304
this._loginHint = typeof config.loginHint !== 'undefined' ? config.loginHint : null;
289305
this._sid = typeof config.sid !== 'undefined' ? config.sid : null;
306+
this._isIncrementalConsentDisabled =
307+
typeof config.isIncrementalConsentDisabled !== 'undefined' ? config.isIncrementalConsentDisabled : false;
290308
this._domainHint = typeof config.domainHint !== 'undefined' ? config.domainHint : null;
291309
this.scopes = typeof config.scopes !== 'undefined' ? config.scopes : ['user.read'];
292310
this._prompt = typeof config.prompt !== 'undefined' ? config.prompt : PromptType.SELECT_ACCOUNT;
@@ -577,6 +595,9 @@ export class Msal2Provider extends IProvider {
577595
return response.accessToken;
578596
} catch (e) {
579597
if (e instanceof InteractionRequiredAuthError) {
598+
if (this._isIncrementalConsentDisabled) {
599+
return null;
600+
}
580601
if (this._loginType === LoginType.Redirect) {
581602
if (!this.areScopesDenied(scopes)) {
582603
this.setRequestedScopes(scopes);

packages/providers/mgt-msal2-provider/src/mgt-msal2-provider.ts

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,17 @@ export class MgtMsal2Provider extends MgtBaseProvider {
7979
})
8080
public prompt: string;
8181

82+
/**
83+
* Disables incremental consent
84+
*
85+
* @memberof MgtMsal2Provider
86+
*/
87+
@property({
88+
attribute: 'incremental-consent-disabled',
89+
type: Boolean
90+
})
91+
public isIncrementalConsentDisabled: boolean;
92+
8293
/**
8394
* Gets whether this provider can be used in this environment
8495
*
@@ -129,6 +140,10 @@ export class MgtMsal2Provider extends MgtBaseProvider {
129140
config.prompt = promptEnum;
130141
}
131142

143+
if (this.isIncrementalConsentDisabled) {
144+
config.isIncrementalConsentDisabled = true;
145+
}
146+
132147
this.provider = new Msal2Provider(config);
133148
Providers.globalProvider = this.provider;
134149
}

0 commit comments

Comments
 (0)