UNPKG

@mattbillfred/mgt-msal2-provider

Version:
172 lines 6.08 kB
/** * ------------------------------------------------------------------------------------------- * Copyright (c) Microsoft Corporation. All Rights Reserved. Licensed under the MIT License. * See License in the project root for license information. * ------------------------------------------------------------------------------------------- */ var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) { var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d; if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc); else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r; return c > 3 && r && Object.defineProperty(target, key, r), r; }; var __metadata = (this && this.__metadata) || function (k, v) { if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v); }; import { property } from 'lit/decorators.js'; import { Providers, LoginType, MgtBaseProvider, registerComponent } from '@microsoft/mgt-element'; import { Msal2Provider, PromptType } from './Msal2Provider'; export const registerMgtMsal2Provider = () => { registerComponent('msal2-provider', MgtMsal2Provider); }; /** * Authentication Library Provider for Microsoft personal accounts * * @export * @class MgtMsalProvider * @extends {MgtBaseProvider} */ class MgtMsal2Provider extends MgtBaseProvider { constructor() { super(...arguments); /** * String alphanumerical value relation to a specific user * * @memberof MgtMsalProvider */ this.clientId = ''; } /** * Gets whether this provider can be used in this environment * * @readonly * @memberof MgtMsal2Provider */ get isAvailable() { return true; } /** * method called to initialize the provider. Each derived class should provide their own implementation. * * @protected * @memberof MgtMsal2Provider */ initializeProvider() { if (this.clientId) { const config = { clientId: this.clientId }; if (this.loginType && this.loginType.length > 1) { let loginType = this.loginType.toLowerCase(); loginType = loginType[0].toUpperCase() + loginType.slice(1); const loginTypeEnum = LoginType[loginType]; config.loginType = loginTypeEnum; } if (this.authority) { config.authority = this.authority; } if (this.scopes) { const scope = this.scopes.split(','); if (scope && scope.length > 0) { config.scopes = scope; } } if (this.redirectUri) { config.redirectUri = this.redirectUri; } if (this.loginHint) { config.loginHint = this.loginHint; } if (this.domainHint) { config.domainHint = this.domainHint; } if (this.prompt) { const prompt = this.prompt.toUpperCase(); const promptEnum = PromptType[prompt]; config.prompt = promptEnum; } if (this.isIncrementalConsentDisabled) { config.isIncrementalConsentDisabled = true; } if (this.isMultiAccountDisabled) { config.isMultiAccountEnabled = false; } if (this.baseUrl) { config.baseURL = this.baseUrl; } if (this.customHosts) { config.customHosts = this.customHosts; } this.provider = new Msal2Provider(config); Providers.globalProvider = this.provider; } } } __decorate([ property({ attribute: 'client-id', type: String }), __metadata("design:type", Object) ], MgtMsal2Provider.prototype, "clientId", void 0); __decorate([ property({ attribute: 'login-hint', type: String }), __metadata("design:type", String) ], MgtMsal2Provider.prototype, "loginHint", void 0); __decorate([ property({ attribute: 'domain-hint', type: String }), __metadata("design:type", String) ], MgtMsal2Provider.prototype, "domainHint", void 0); __decorate([ property({ attribute: 'login-type', type: String }), __metadata("design:type", String) ], MgtMsal2Provider.prototype, "loginType", void 0); __decorate([ property(), __metadata("design:type", String) ], MgtMsal2Provider.prototype, "authority", void 0); __decorate([ property({ attribute: 'scopes', type: String }), __metadata("design:type", String) ], MgtMsal2Provider.prototype, "scopes", void 0); __decorate([ property({ attribute: 'redirect-uri', type: String }), __metadata("design:type", String) ], MgtMsal2Provider.prototype, "redirectUri", void 0); __decorate([ property({ attribute: 'prompt', type: String }), __metadata("design:type", String) ], MgtMsal2Provider.prototype, "prompt", void 0); __decorate([ property({ attribute: 'incremental-consent-disabled', type: Boolean }), __metadata("design:type", Boolean) ], MgtMsal2Provider.prototype, "isIncrementalConsentDisabled", void 0); __decorate([ property({ attribute: 'multi-account-disabled', type: Boolean }), __metadata("design:type", Object) ], MgtMsal2Provider.prototype, "isMultiAccountDisabled", void 0); //# sourceMappingURL=mgt-msal2-provider.js.map