@microsoft/mgt-msal2-provider
Advanced tools
Comparing version 2.2.0 to 2.2.1-preview.10e98e4
@@ -5,10 +5,10 @@ import { IProvider, LoginType, IProviderAccount } from '@microsoft/mgt-element'; | ||
/** | ||
* Config for MSAL2.0 Authentication | ||
* base config for MSAL 2.0 authentication | ||
* | ||
* @export | ||
* @interface Msal2Config | ||
* @interface Msal2ConfigBase | ||
*/ | ||
export interface Msal2Config { | ||
interface Msal2ConfigBase { | ||
/** | ||
* Client ID of app registration | ||
* Redirect URI | ||
* | ||
@@ -18,47 +18,54 @@ * @type {string} | ||
*/ | ||
clientId: string; | ||
redirectUri?: string; | ||
/** | ||
* LoginType | ||
* Authority URL | ||
* | ||
* @type {LoginType} | ||
* @type {string} | ||
* @memberof Msal2Config | ||
*/ | ||
loginType?: LoginType; | ||
authority?: string; | ||
/** | ||
* Other options | ||
* | ||
* @type {Configuration} | ||
* @memberof Msal2Config | ||
*/ | ||
options?: Configuration; | ||
/** | ||
* List of scopes required | ||
* | ||
* @type {string[]} | ||
* @memberof Msal2Config | ||
* @memberof Msal2ConfigBase | ||
*/ | ||
scopes?: string[]; | ||
/** | ||
* LoginHint | ||
* loginType if login uses popup | ||
* | ||
* @type {string} | ||
* @memberof Msal2Config | ||
* @type {LoginType} | ||
* @memberof Msal2ConfigBase | ||
*/ | ||
loginHint?: string; | ||
loginType?: LoginType; | ||
/** | ||
* Session ID | ||
* login hint value | ||
* | ||
* @type {string} | ||
* @memberof Msal2Config | ||
* @memberof Msal2ConfigBase | ||
*/ | ||
sid?: string; | ||
loginHint?: string; | ||
/** | ||
* Domain hint | ||
* Domain hint value | ||
* | ||
* @type {string} | ||
* @memberof Msal2Config | ||
* @memberof Msal2ConfigBase | ||
*/ | ||
domainHint?: string; | ||
/** | ||
* Prompt type | ||
* prompt value | ||
* | ||
* @type {Prompt} | ||
* @memberof Msal2Config | ||
* @type {string} | ||
* @memberof Msal2ConfigBase | ||
*/ | ||
prompt?: PromptType; | ||
/** | ||
* Redirect URI | ||
* Session ID | ||
* | ||
@@ -68,5 +75,13 @@ * @type {string} | ||
*/ | ||
redirectUri?: string; | ||
sid?: string; | ||
} | ||
/** | ||
* Config for MSAL2.0 Authentication | ||
* | ||
* @export | ||
* @interface Msal2Config | ||
*/ | ||
export interface Msal2Config extends Msal2ConfigBase { | ||
/** | ||
* Authority URL | ||
* Client ID of app registration | ||
* | ||
@@ -76,10 +91,18 @@ * @type {string} | ||
*/ | ||
authority?: string; | ||
clientId: string; | ||
} | ||
/** | ||
* Config for MSAL 2.0 Authentication where a PublicClientApplication already exists | ||
* | ||
* @export | ||
* @interface Msal2PublicClientApplicationConfig | ||
*/ | ||
export interface Msal2PublicClientApplicationConfig extends Msal2ConfigBase { | ||
/** | ||
* Other options | ||
* Existing PublicClientApplication instance to use | ||
* | ||
* @type {Configuration} | ||
* @memberof Msal2Config | ||
* @type {PublicClientApplication} | ||
* @memberof Msal2PublicClientApplicationConfig | ||
*/ | ||
options?: Configuration; | ||
publicClientApplication: PublicClientApplication; | ||
} | ||
@@ -176,3 +199,3 @@ /** | ||
private homeAccountKey; | ||
constructor(config: Msal2Config); | ||
constructor(config: Msal2Config | Msal2PublicClientApplicationConfig); | ||
/** | ||
@@ -305,2 +328,3 @@ * Initialize provider with configuration details | ||
} | ||
export {}; | ||
//# sourceMappingURL=Msal2Provider.d.ts.map |
@@ -67,46 +67,56 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
if (config.clientId) { | ||
const msalConfig = config.options || { auth: { clientId: config.clientId } }; | ||
this.ms_config = msalConfig; | ||
this.ms_config.auth.clientId = config.clientId; | ||
if (config.authority) { | ||
this.ms_config.auth.authority = config.authority; | ||
const msalConfig = config.options || { auth: { clientId: '' } }; | ||
this.ms_config = msalConfig; | ||
this.ms_config.cache = msalConfig.cache || {}; | ||
this.ms_config.cache.cacheLocation = msalConfig.cache.cacheLocation || 'localStorage'; | ||
if (typeof this.ms_config.cache.storeAuthStateInCookie === 'undefined' || | ||
this.ms_config.cache.storeAuthStateInCookie === null) { | ||
this.ms_config.cache.storeAuthStateInCookie = true; | ||
} | ||
this.ms_config.system = msalConfig.system || {}; | ||
this.ms_config.system.iframeHashTimeout = msalConfig.system.iframeHashTimeout || 10000; | ||
if (config.authority) { | ||
this.ms_config.auth.authority = config.authority; | ||
} | ||
if (config.redirectUri) { | ||
this.ms_config.auth.redirectUri = config.redirectUri; | ||
} | ||
if ('clientId' in config) { | ||
if (config.clientId) { | ||
this.ms_config.auth.clientId = config.clientId; | ||
this._publicClientApplication = new PublicClientApplication(this.ms_config); | ||
} | ||
if (config.redirectUri) { | ||
this.ms_config.auth.redirectUri = config.redirectUri; | ||
else { | ||
throw new Error('clientId must be provided'); | ||
} | ||
this.ms_config.cache = msalConfig.cache || {}; | ||
this.ms_config.cache.cacheLocation = msalConfig.cache.cacheLocation || 'localStorage'; | ||
if (typeof this.ms_config.cache.storeAuthStateInCookie === 'undefined' || | ||
this.ms_config.cache.storeAuthStateInCookie === null) { | ||
this.ms_config.cache.storeAuthStateInCookie = true; | ||
} | ||
else if ('publicClientApplication' in config) { | ||
if (config.publicClientApplication) { | ||
this._publicClientApplication = config.publicClientApplication; | ||
} | ||
if (config.redirectUri) { | ||
this.ms_config.auth.redirectUri = config.redirectUri; | ||
else { | ||
throw new Error('publicClientApplication must be provided'); | ||
} | ||
this.ms_config.system = msalConfig.system || {}; | ||
this.ms_config.system.iframeHashTimeout = msalConfig.system.iframeHashTimeout || 10000; | ||
this._loginType = typeof config.loginType !== 'undefined' ? config.loginType : LoginType.Redirect; | ||
this._loginHint = typeof config.loginHint !== 'undefined' ? config.loginHint : null; | ||
this._sid = typeof config.sid !== 'undefined' ? config.sid : null; | ||
this._domainHint = typeof config.domainHint !== 'undefined' ? config.domainHint : null; | ||
this.scopes = typeof config.scopes !== 'undefined' ? config.scopes : ['user.read']; | ||
this._publicClientApplication = new PublicClientApplication(this.ms_config); | ||
this._prompt = typeof config.prompt !== 'undefined' ? config.prompt : PromptType.SELECT_ACCOUNT; | ||
this.graph = createFromProvider(this); | ||
try { | ||
const tokenResponse = yield this._publicClientApplication.handleRedirectPromise(); | ||
if (tokenResponse !== null) { | ||
this.handleResponse(tokenResponse === null || tokenResponse === void 0 ? void 0 : tokenResponse.account); | ||
} | ||
else { | ||
this.trySilentSignIn(); | ||
} | ||
} | ||
else { | ||
throw new Error('either clientId or publicClientApplication must be provided'); | ||
} | ||
this._loginType = typeof config.loginType !== 'undefined' ? config.loginType : LoginType.Redirect; | ||
this._loginHint = typeof config.loginHint !== 'undefined' ? config.loginHint : null; | ||
this._sid = typeof config.sid !== 'undefined' ? config.sid : null; | ||
this._domainHint = typeof config.domainHint !== 'undefined' ? config.domainHint : null; | ||
this.scopes = typeof config.scopes !== 'undefined' ? config.scopes : ['user.read']; | ||
this._prompt = typeof config.prompt !== 'undefined' ? config.prompt : PromptType.SELECT_ACCOUNT; | ||
this.graph = createFromProvider(this); | ||
try { | ||
const tokenResponse = yield this._publicClientApplication.handleRedirectPromise(); | ||
if (tokenResponse !== null) { | ||
this.handleResponse(tokenResponse === null || tokenResponse === void 0 ? void 0 : tokenResponse.account); | ||
} | ||
catch (e) { | ||
throw e; | ||
else { | ||
this.trySilentSignIn(); | ||
} | ||
} | ||
else { | ||
throw new Error('clientId must be provided'); | ||
catch (e) { | ||
throw e; | ||
} | ||
@@ -113,0 +123,0 @@ }); |
{ | ||
"name": "@microsoft/mgt-msal2-provider", | ||
"version": "2.2.0", | ||
"version": "2.2.1-preview.10e98e4", | ||
"description": "The Microsoft Graph Toolkit Msal 2.0 Provider", | ||
@@ -42,3 +42,3 @@ "keywords": [ | ||
"dependencies": { | ||
"@microsoft/mgt-element": "2.2.0", | ||
"@microsoft/mgt-element": "2.2.1-preview.10e98e4", | ||
"@microsoft/microsoft-graph-client": "^2.2.1", | ||
@@ -45,0 +45,0 @@ "@azure/msal-browser": "^2.14.1" |
@@ -18,3 +18,3 @@ # Microsoft Graph Toolkit MSAL 2.0 Provider | ||
2. Initialize the provider in code | ||
2. Initialize the provider in code with `Msal2Config` | ||
@@ -40,4 +40,26 @@ ```ts | ||
3. Alternatively, initialize the provider in html (only `client-id` is required): | ||
3. Initialize the provider in code with `Msal2PublicClientApplicationConfig` if a `PublicClientApplication` is already instantiated. For example, `msal-angular` instantiates `PublicClientApplication` on startup. | ||
```ts | ||
import {Providers, LoginType} from '@microsoft/mgt-element'; | ||
import {Msal2Provider, PromptType} from '@microsoft/mgt-msal2-provider'; | ||
import {PublicClientApplication} from '@azure/msal-browser'; | ||
// initialize the auth provider globally | ||
Providers.globalProvider = new Msal2Provider({ | ||
publicClientApplication: PublicClientApplication, | ||
scopes?: string[], | ||
authority?: string, | ||
redirectUri?: string, | ||
loginType?: LoginType, // LoginType.Popup or LoginType.Redirect (redirect is default) | ||
prompt?: PromptType, // PromptType.CONSENT, PromptType.LOGIN or PromptType.SELECT_ACCOUNT | ||
sid?: string, // Session ID | ||
loginHint?: string, | ||
domainHint?: string, | ||
options?: Configuration // msal js Configuration object | ||
}); | ||
``` | ||
4. Alternatively, initialize the provider in html (only `client-id` is required): | ||
```html | ||
@@ -44,0 +66,0 @@ <script type="module" src="../node_modules/@microsoft/mgt-msal2-provider/dist/es6/index.js" /> |
@@ -23,10 +23,10 @@ import { | ||
/** | ||
* Config for MSAL2.0 Authentication | ||
* base config for MSAL 2.0 authentication | ||
* | ||
* @export | ||
* @interface Msal2Config | ||
* @interface Msal2ConfigBase | ||
*/ | ||
export interface Msal2Config { | ||
interface Msal2ConfigBase { | ||
/** | ||
* Client ID of app registration | ||
* Redirect URI | ||
* | ||
@@ -36,49 +36,53 @@ * @type {string} | ||
*/ | ||
clientId: string; | ||
redirectUri?: string; | ||
/** | ||
* LoginType | ||
* Authority URL | ||
* | ||
* @type {LoginType} | ||
* @type {string} | ||
* @memberof Msal2Config | ||
*/ | ||
loginType?: LoginType; | ||
authority?: string; | ||
/** | ||
* Other options | ||
* | ||
* @type {Configuration} | ||
* @memberof Msal2Config | ||
*/ | ||
options?: Configuration; | ||
/** | ||
* List of scopes required | ||
* | ||
* @type {string[]} | ||
* @memberof Msal2Config | ||
* @memberof Msal2ConfigBase | ||
*/ | ||
scopes?: string[]; | ||
/** | ||
* LoginHint | ||
* loginType if login uses popup | ||
* | ||
* @type {string} | ||
* @memberof Msal2Config | ||
* @type {LoginType} | ||
* @memberof Msal2ConfigBase | ||
*/ | ||
loginHint?: string; | ||
loginType?: LoginType; | ||
/** | ||
* Session ID | ||
* login hint value | ||
* | ||
* @type {string} | ||
* @memberof Msal2Config | ||
* @memberof Msal2ConfigBase | ||
*/ | ||
sid?: string; | ||
loginHint?: string; | ||
/** | ||
* Domain hint | ||
* Domain hint value | ||
* | ||
* @type {string} | ||
* @memberof Msal2Config | ||
* @memberof Msal2ConfigBase | ||
*/ | ||
domainHint?: string; | ||
/** | ||
* Prompt type | ||
* prompt value | ||
* | ||
* @type {Prompt} | ||
* @memberof Msal2Config | ||
* @type {string} | ||
* @memberof Msal2ConfigBase | ||
*/ | ||
@@ -88,3 +92,3 @@ prompt?: PromptType; | ||
/** | ||
* Redirect URI | ||
* Session ID | ||
* | ||
@@ -94,6 +98,14 @@ * @type {string} | ||
*/ | ||
redirectUri?: string; | ||
sid?: string; | ||
} | ||
/** | ||
* Config for MSAL2.0 Authentication | ||
* | ||
* @export | ||
* @interface Msal2Config | ||
*/ | ||
export interface Msal2Config extends Msal2ConfigBase { | ||
/** | ||
* Authority URL | ||
* Client ID of app registration | ||
* | ||
@@ -103,11 +115,19 @@ * @type {string} | ||
*/ | ||
authority?: string; | ||
clientId: string; | ||
} | ||
/** | ||
* Config for MSAL 2.0 Authentication where a PublicClientApplication already exists | ||
* | ||
* @export | ||
* @interface Msal2PublicClientApplicationConfig | ||
*/ | ||
export interface Msal2PublicClientApplicationConfig extends Msal2ConfigBase { | ||
/** | ||
* Other options | ||
* Existing PublicClientApplication instance to use | ||
* | ||
* @type {Configuration} | ||
* @memberof Msal2Config | ||
* @type {PublicClientApplication} | ||
* @memberof Msal2PublicClientApplicationConfig | ||
*/ | ||
options?: Configuration; | ||
publicClientApplication: PublicClientApplication; | ||
} | ||
@@ -221,3 +241,3 @@ | ||
public constructor(config: Msal2Config) { | ||
public constructor(config: Msal2Config | Msal2PublicClientApplicationConfig) { | ||
super(); | ||
@@ -234,49 +254,58 @@ this.initProvider(config); | ||
*/ | ||
private async initProvider(config: Msal2Config) { | ||
if (config.clientId) { | ||
const msalConfig: Configuration = config.options || { auth: { clientId: config.clientId } }; | ||
this.ms_config = msalConfig; | ||
this.ms_config.auth.clientId = config.clientId; | ||
if (config.authority) { | ||
this.ms_config.auth.authority = config.authority; | ||
} | ||
if (config.redirectUri) { | ||
this.ms_config.auth.redirectUri = config.redirectUri; | ||
} | ||
private async initProvider(config: Msal2Config | Msal2PublicClientApplicationConfig) { | ||
const msalConfig: Configuration = config.options || { auth: { clientId: '' } }; | ||
this.ms_config = msalConfig; | ||
this.ms_config.cache = msalConfig.cache || {}; | ||
this.ms_config.cache.cacheLocation = msalConfig.cache.cacheLocation || 'localStorage'; | ||
if ( | ||
typeof this.ms_config.cache.storeAuthStateInCookie === 'undefined' || | ||
this.ms_config.cache.storeAuthStateInCookie === null | ||
) { | ||
this.ms_config.cache.storeAuthStateInCookie = true; | ||
} | ||
this.ms_config.cache = msalConfig.cache || {}; | ||
this.ms_config.cache.cacheLocation = msalConfig.cache.cacheLocation || 'localStorage'; | ||
if ( | ||
typeof this.ms_config.cache.storeAuthStateInCookie === 'undefined' || | ||
this.ms_config.cache.storeAuthStateInCookie === null | ||
) { | ||
this.ms_config.cache.storeAuthStateInCookie = true; | ||
} | ||
this.ms_config.system = msalConfig.system || {}; | ||
this.ms_config.system.iframeHashTimeout = msalConfig.system.iframeHashTimeout || 10000; | ||
if (config.redirectUri) { | ||
this.ms_config.auth.redirectUri = config.redirectUri; | ||
if (config.authority) { | ||
this.ms_config.auth.authority = config.authority; | ||
} | ||
if (config.redirectUri) { | ||
this.ms_config.auth.redirectUri = config.redirectUri; | ||
} | ||
if ('clientId' in config) { | ||
if (config.clientId) { | ||
this.ms_config.auth.clientId = config.clientId; | ||
this._publicClientApplication = new PublicClientApplication(this.ms_config); | ||
} else { | ||
throw new Error('clientId must be provided'); | ||
} | ||
this.ms_config.system = msalConfig.system || {}; | ||
this.ms_config.system.iframeHashTimeout = msalConfig.system.iframeHashTimeout || 10000; | ||
this._loginType = typeof config.loginType !== 'undefined' ? config.loginType : LoginType.Redirect; | ||
this._loginHint = typeof config.loginHint !== 'undefined' ? config.loginHint : null; | ||
this._sid = typeof config.sid !== 'undefined' ? config.sid : null; | ||
this._domainHint = typeof config.domainHint !== 'undefined' ? config.domainHint : null; | ||
this.scopes = typeof config.scopes !== 'undefined' ? config.scopes : ['user.read']; | ||
this._publicClientApplication = new PublicClientApplication(this.ms_config); | ||
this._prompt = typeof config.prompt !== 'undefined' ? config.prompt : PromptType.SELECT_ACCOUNT; | ||
this.graph = createFromProvider(this); | ||
try { | ||
const tokenResponse = await this._publicClientApplication.handleRedirectPromise(); | ||
if (tokenResponse !== null) { | ||
this.handleResponse(tokenResponse?.account); | ||
} else { | ||
this.trySilentSignIn(); | ||
} | ||
} catch (e) { | ||
throw e; | ||
} else if ('publicClientApplication' in config) { | ||
if (config.publicClientApplication) { | ||
this._publicClientApplication = config.publicClientApplication; | ||
} else { | ||
throw new Error('publicClientApplication must be provided'); | ||
} | ||
} else { | ||
throw new Error('clientId must be provided'); | ||
throw new Error('either clientId or publicClientApplication must be provided'); | ||
} | ||
this._loginType = typeof config.loginType !== 'undefined' ? config.loginType : LoginType.Redirect; | ||
this._loginHint = typeof config.loginHint !== 'undefined' ? config.loginHint : null; | ||
this._sid = typeof config.sid !== 'undefined' ? config.sid : null; | ||
this._domainHint = typeof config.domainHint !== 'undefined' ? config.domainHint : null; | ||
this.scopes = typeof config.scopes !== 'undefined' ? config.scopes : ['user.read']; | ||
this._prompt = typeof config.prompt !== 'undefined' ? config.prompt : PromptType.SELECT_ACCOUNT; | ||
this.graph = createFromProvider(this); | ||
try { | ||
const tokenResponse = await this._publicClientApplication.handleRedirectPromise(); | ||
if (tokenResponse !== null) { | ||
this.handleResponse(tokenResponse?.account); | ||
} else { | ||
this.trySilentSignIn(); | ||
} | ||
} catch (e) { | ||
throw e; | ||
} | ||
} | ||
@@ -283,0 +312,0 @@ |
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
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
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
929790
1634
80
1
+ Added@microsoft/mgt-element@2.2.1-preview.10e98e4(transitive)
- Removed@microsoft/mgt-element@2.2.0(transitive)