@memberjunction/ng-auth-services 2.90.0 → 2.92.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/dist/lib/AngularAuthProviderFactory.d.ts +46 -0
- package/dist/lib/AngularAuthProviderFactory.d.ts.map +1 -0
- package/dist/lib/AngularAuthProviderFactory.js +123 -0
- package/dist/lib/AngularAuthProviderFactory.js.map +1 -0
- package/dist/lib/IAuthProvider.d.ts +55 -0
- package/dist/lib/IAuthProvider.d.ts.map +1 -0
- package/dist/lib/IAuthProvider.js +2 -0
- package/dist/lib/IAuthProvider.js.map +1 -0
- package/dist/lib/auth-services.module.d.ts +10 -12
- package/dist/lib/auth-services.module.d.ts.map +1 -1
- package/dist/lib/auth-services.module.js +57 -74
- package/dist/lib/auth-services.module.js.map +1 -1
- package/dist/lib/mjexplorer-auth-base.service.d.ts +97 -12
- package/dist/lib/mjexplorer-auth-base.service.d.ts.map +1 -1
- package/dist/lib/mjexplorer-auth-base.service.js +112 -11
- package/dist/lib/mjexplorer-auth-base.service.js.map +1 -1
- package/dist/lib/providers/mjexplorer-auth0-provider.service.d.ts +49 -0
- package/dist/lib/providers/mjexplorer-auth0-provider.service.d.ts.map +1 -0
- package/dist/lib/providers/mjexplorer-auth0-provider.service.js +131 -0
- package/dist/lib/providers/mjexplorer-auth0-provider.service.js.map +1 -0
- package/dist/lib/providers/mjexplorer-msal-provider.service.d.ts +58 -0
- package/dist/lib/providers/mjexplorer-msal-provider.service.d.ts.map +1 -0
- package/dist/lib/providers/mjexplorer-msal-provider.service.js +267 -0
- package/dist/lib/providers/mjexplorer-msal-provider.service.js.map +1 -0
- package/dist/lib/providers/mjexplorer-okta-provider.service.d.ts +61 -0
- package/dist/lib/providers/mjexplorer-okta-provider.service.d.ts.map +1 -0
- package/dist/lib/providers/mjexplorer-okta-provider.service.js +379 -0
- package/dist/lib/providers/mjexplorer-okta-provider.service.js.map +1 -0
- package/dist/lib/redirect.component.d.ts +16 -0
- package/dist/lib/redirect.component.d.ts.map +1 -0
- package/dist/lib/redirect.component.js +67 -0
- package/dist/lib/redirect.component.js.map +1 -0
- package/dist/public-api.d.ts +6 -2
- package/dist/public-api.d.ts.map +1 -1
- package/dist/public-api.js +9 -2
- package/dist/public-api.js.map +1 -1
- package/package.json +5 -3
- package/dist/lib/mjexplorer-auth0-provider.service.d.ts +0 -18
- package/dist/lib/mjexplorer-auth0-provider.service.d.ts.map +0 -1
- package/dist/lib/mjexplorer-auth0-provider.service.js +0 -45
- package/dist/lib/mjexplorer-auth0-provider.service.js.map +0 -1
- package/dist/lib/mjexplorer-msal-provider.service.d.ts +0 -24
- package/dist/lib/mjexplorer-msal-provider.service.d.ts.map +0 -1
- package/dist/lib/mjexplorer-msal-provider.service.js +0 -108
- package/dist/lib/mjexplorer-msal-provider.service.js.map +0 -1
|
@@ -1,18 +1,119 @@
|
|
|
1
1
|
import { Injectable } from '@angular/core';
|
|
2
|
+
import { BehaviorSubject, from } from 'rxjs';
|
|
2
3
|
import * as i0 from "@angular/core";
|
|
4
|
+
/**
|
|
5
|
+
* Base class for Angular authentication providers
|
|
6
|
+
* Provides common functionality and enforces the provider interface
|
|
7
|
+
*/
|
|
3
8
|
export class MJAuthBase {
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
9
|
+
config;
|
|
10
|
+
isAuthenticated$ = new BehaviorSubject(false);
|
|
11
|
+
userProfile$ = new BehaviorSubject(null);
|
|
12
|
+
userEmail$ = new BehaviorSubject('');
|
|
13
|
+
constructor(config) {
|
|
14
|
+
this.config = config;
|
|
8
15
|
}
|
|
9
|
-
|
|
10
|
-
|
|
16
|
+
/**
|
|
17
|
+
* Login the user - public API that returns Observable for backward compatibility
|
|
18
|
+
*/
|
|
19
|
+
login(options) {
|
|
20
|
+
return from(this.loginInternal(options));
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* Check if user is authenticated
|
|
24
|
+
*/
|
|
25
|
+
isAuthenticated() {
|
|
26
|
+
return this.isAuthenticated$.asObservable();
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* Get user profile information
|
|
30
|
+
*/
|
|
31
|
+
getUserProfile() {
|
|
32
|
+
return this.userProfile$.asObservable();
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* Get user email
|
|
36
|
+
*/
|
|
37
|
+
getUserEmail() {
|
|
38
|
+
return this.userEmail$.asObservable();
|
|
39
|
+
}
|
|
40
|
+
/**
|
|
41
|
+
* Get provider-specific configuration requirements
|
|
42
|
+
* Override to specify required config fields
|
|
43
|
+
*/
|
|
44
|
+
getRequiredConfig() {
|
|
45
|
+
return ['clientId'];
|
|
46
|
+
}
|
|
47
|
+
/**
|
|
48
|
+
* Validate provider configuration
|
|
49
|
+
* Override to add provider-specific validation
|
|
50
|
+
*/
|
|
51
|
+
validateConfig(config) {
|
|
52
|
+
const requiredFields = this.getRequiredConfig();
|
|
53
|
+
return requiredFields.every(field => config[field] !== undefined && config[field] !== '');
|
|
54
|
+
}
|
|
55
|
+
/**
|
|
56
|
+
* Helper method to update authentication state
|
|
57
|
+
*/
|
|
58
|
+
updateAuthState(isAuthenticated) {
|
|
59
|
+
this.isAuthenticated$.next(isAuthenticated);
|
|
60
|
+
}
|
|
61
|
+
/**
|
|
62
|
+
* Helper method to update user profile
|
|
63
|
+
*/
|
|
64
|
+
updateUserProfile(profile) {
|
|
65
|
+
this.userProfile$.next(profile);
|
|
66
|
+
if (profile?.email) {
|
|
67
|
+
this.userEmail$.next(profile.email);
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
// Backward compatibility methods for existing code
|
|
71
|
+
/**
|
|
72
|
+
* Legacy property for authentication state
|
|
73
|
+
*/
|
|
74
|
+
get authenticated() {
|
|
75
|
+
return this.isAuthenticated$.value;
|
|
76
|
+
}
|
|
77
|
+
/**
|
|
78
|
+
* Legacy setter for authentication state
|
|
79
|
+
* Used by MJExplorer for backward compatibility
|
|
80
|
+
*/
|
|
81
|
+
set authenticated(value) {
|
|
82
|
+
this.updateAuthState(value);
|
|
83
|
+
}
|
|
84
|
+
/**
|
|
85
|
+
* Legacy method to get user
|
|
86
|
+
*/
|
|
87
|
+
async getUser() {
|
|
88
|
+
return this.userProfile$.value;
|
|
89
|
+
}
|
|
90
|
+
/**
|
|
91
|
+
* Legacy method to get user claims
|
|
92
|
+
*/
|
|
93
|
+
async getUserClaims() {
|
|
94
|
+
return this.userProfile$.asObservable();
|
|
95
|
+
}
|
|
96
|
+
/**
|
|
97
|
+
* Legacy method to check expired token error
|
|
98
|
+
*/
|
|
99
|
+
checkExpiredTokenError(error) {
|
|
100
|
+
// Check for common token expiration error messages
|
|
101
|
+
return error?.toLowerCase().includes('expired') ||
|
|
102
|
+
error?.toLowerCase().includes('invalid token') ||
|
|
103
|
+
error?.toLowerCase().includes('unauthorized');
|
|
104
|
+
}
|
|
105
|
+
/**
|
|
106
|
+
* Legacy refresh method
|
|
107
|
+
*/
|
|
108
|
+
async refresh() {
|
|
109
|
+
// Try to get a new token
|
|
110
|
+
await this.getToken();
|
|
111
|
+
return this.userProfile$.asObservable();
|
|
112
|
+
}
|
|
113
|
+
static ɵfac = function MJAuthBase_Factory(t) { i0.ɵɵinvalidFactory(); };
|
|
114
|
+
static ɵprov = /*@__PURE__*/ i0.ɵɵdefineInjectable({ token: MJAuthBase, factory: MJAuthBase.ɵfac });
|
|
11
115
|
}
|
|
12
116
|
(() => { (typeof ngDevMode === "undefined" || ngDevMode) && i0.ɵsetClassMetadata(MJAuthBase, [{
|
|
13
|
-
type: Injectable
|
|
14
|
-
|
|
15
|
-
providedIn: 'root'
|
|
16
|
-
}]
|
|
17
|
-
}], () => [], null); })();
|
|
117
|
+
type: Injectable
|
|
118
|
+
}], () => [{ type: undefined }], null); })();
|
|
18
119
|
//# sourceMappingURL=mjexplorer-auth-base.service.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"mjexplorer-auth-base.service.js","sourceRoot":"","sources":["../../src/lib/mjexplorer-auth-base.service.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,eAAe,CAAC;;
|
|
1
|
+
{"version":3,"file":"mjexplorer-auth-base.service.js","sourceRoot":"","sources":["../../src/lib/mjexplorer-auth-base.service.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,eAAe,CAAC;AAC3C,OAAO,EAAc,eAAe,EAAE,IAAI,EAAE,MAAM,MAAM,CAAC;;AAGzD;;;GAGG;AAEH,MAAM,OAAgB,UAAU;IACpB,MAAM,CAA4B;IAClC,gBAAgB,GAAG,IAAI,eAAe,CAAU,KAAK,CAAC,CAAC;IACvD,YAAY,GAAG,IAAI,eAAe,CAAM,IAAI,CAAC,CAAC;IAC9C,UAAU,GAAG,IAAI,eAAe,CAAS,EAAE,CAAC,CAAC;IAIvD,YAAY,MAAiC;QAC3C,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC;IACvB,CAAC;IAcD;;OAEG;IACH,KAAK,CAAC,OAAa;QACjB,OAAO,IAAI,CAAC,IAAI,CAAC,aAAa,CAAC,OAAO,CAAC,CAAC,CAAC;IAC3C,CAAC;IAoBD;;OAEG;IACH,eAAe;QACb,OAAO,IAAI,CAAC,gBAAgB,CAAC,YAAY,EAAE,CAAC;IAC9C,CAAC;IAED;;OAEG;IACH,cAAc;QACZ,OAAO,IAAI,CAAC,YAAY,CAAC,YAAY,EAAE,CAAC;IAC1C,CAAC;IAED;;OAEG;IACH,YAAY;QACV,OAAO,IAAI,CAAC,UAAU,CAAC,YAAY,EAAE,CAAC;IACxC,CAAC;IAED;;;OAGG;IACH,iBAAiB;QACf,OAAO,CAAC,UAAU,CAAC,CAAC;IACtB,CAAC;IAED;;;OAGG;IACH,cAAc,CAAC,MAAW;QACxB,MAAM,cAAc,GAAG,IAAI,CAAC,iBAAiB,EAAE,CAAC;QAChD,OAAO,cAAc,CAAC,KAAK,CAAC,KAAK,CAAC,EAAE,C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CAAC,YAAY,CAAC,YAAY,EAAE,CAAC;IAC1C,CAAC;;gEAxJmB,UAAU,WAAV,UAAU;;iFAAV,UAAU;cAD/B,UAAU"}
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import { MJAuthBase } from '../mjexplorer-auth-base.service';
|
|
2
|
+
import { AuthService, User, AuthGuard, Auth0ClientFactory, AuthClientConfig } from '@auth0/auth0-angular';
|
|
3
|
+
import { Observable } from 'rxjs';
|
|
4
|
+
import * as i0 from "@angular/core";
|
|
5
|
+
export declare function LoadMJAuth0Provider(): typeof MJAuth0Provider;
|
|
6
|
+
export declare class MJAuth0Provider extends MJAuthBase {
|
|
7
|
+
auth: AuthService;
|
|
8
|
+
static readonly PROVIDER_TYPE = "auth0";
|
|
9
|
+
type: string;
|
|
10
|
+
/**
|
|
11
|
+
* Factory function to provide Angular dependencies required by Auth0
|
|
12
|
+
* Stored as a static property for the factory to access without instantiation
|
|
13
|
+
*/
|
|
14
|
+
static angularProviderFactory: (environment: any) => (typeof AuthService | typeof AuthGuard | {
|
|
15
|
+
provide: import("@angular/core").InjectionToken<import("@auth0/auth0-angular").AuthConfig>;
|
|
16
|
+
useValue: {
|
|
17
|
+
domain: any;
|
|
18
|
+
clientId: any;
|
|
19
|
+
authorizationParams: {
|
|
20
|
+
redirect_uri: string;
|
|
21
|
+
};
|
|
22
|
+
cacheLocation: string;
|
|
23
|
+
};
|
|
24
|
+
useFactory?: undefined;
|
|
25
|
+
deps?: undefined;
|
|
26
|
+
} | {
|
|
27
|
+
provide: import("@angular/core").InjectionToken<import("@auth0/auth0-spa-js").Auth0Client>;
|
|
28
|
+
useFactory: typeof Auth0ClientFactory.createClient;
|
|
29
|
+
deps: (typeof AuthClientConfig)[];
|
|
30
|
+
useValue?: undefined;
|
|
31
|
+
})[];
|
|
32
|
+
constructor(auth: AuthService);
|
|
33
|
+
login(options?: any): Observable<void>;
|
|
34
|
+
logout(): Promise<void>;
|
|
35
|
+
refresh(): Promise<Observable<any>>;
|
|
36
|
+
getUser(): Promise<Observable<User | null | undefined>>;
|
|
37
|
+
isAuthenticated(): Observable<boolean>;
|
|
38
|
+
getUserClaims(): Promise<Observable<any>>;
|
|
39
|
+
checkExpiredTokenError(error: string): boolean;
|
|
40
|
+
initialize(): Promise<void>;
|
|
41
|
+
protected loginInternal(options?: any): Promise<void>;
|
|
42
|
+
getToken(): Promise<string | null>;
|
|
43
|
+
handleCallback(): Promise<void>;
|
|
44
|
+
getRequiredConfig(): string[];
|
|
45
|
+
validateConfig(_config: any): boolean;
|
|
46
|
+
static ɵfac: i0.ɵɵFactoryDeclaration<MJAuth0Provider, never>;
|
|
47
|
+
static ɵprov: i0.ɵɵInjectableDeclaration<MJAuth0Provider>;
|
|
48
|
+
}
|
|
49
|
+
//# sourceMappingURL=mjexplorer-auth0-provider.service.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"mjexplorer-auth0-provider.service.d.ts","sourceRoot":"","sources":["../../../src/lib/providers/mjexplorer-auth0-provider.service.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,UAAU,EAAE,MAAM,iCAAiC,CAAC;AAC7D,OAAO,EAAE,WAAW,EAAW,IAAI,EAAE,SAAS,EAAyC,kBAAkB,EAAE,gBAAgB,EAAE,MAAM,sBAAsB,CAAC;AAC1J,OAAO,EAAE,UAAU,EAAM,MAAM,MAAM,CAAC;;AAItC,wBAAgB,mBAAmB,2BAGlC;AAED,qBAIa,eAAgB,SAAQ,UAAU;IA6B1B,IAAI,EAAE,WAAW;IA5BpC,MAAM,CAAC,QAAQ,CAAC,aAAa,WAAW;IACxC,IAAI,SAAiC;IAErC;;;OAGG;IACH,MAAM,CAAC,sBAAsB,gBAAiB,GAAG;;;;;;;;;;;;;;;;;SAmB/C;gBAEiB,IAAI,EAAE,WAAW;IAW3B,KAAK,CAAC,OAAO,CAAC,EAAE,GAAG,GAAG,UAAU,CAAC,IAAI,CAAC;IAOlC,MAAM,IAAI,OAAO,CAAC,IAAI,CAAC;IAIvB,OAAO,IAAI,OAAO,CAAC,UAAU,CAAC,GAAG,CAAC,CAAC;IAK1C,OAAO,IAAI,OAAO,CAAC,UAAU,CAAC,IAAI,GAAG,IAAI,GAAG,SAAS,CAAC,CAAC;IAIpD,eAAe,IAAI,UAAU,CAAC,OAAO,CAAC;IAIzC,aAAa,IAAI,OAAO,CAAC,UAAU,CAAC,GAAG,CAAC,CAAC;IAI/C,sBAAsB,CAAC,KAAK,EAAE,MAAM,GAAG,OAAO;IAKxC,UAAU,IAAI,OAAO,CAAC,IAAI,CAAC;cAQjB,aAAa,CAAC,OAAO,CAAC,EAAE,GAAG,GAAG,OAAO,CAAC,IAAI,CAAC;IAIrD,QAAQ,IAAI,OAAO,CAAC,MAAM,GAAG,IAAI,CAAC;IAUlC,cAAc,IAAI,OAAO,CAAC,IAAI,CAAC;IAKrC,iBAAiB,IAAI,MAAM,EAAE;IAI7B,cAAc,CAAC,OAAO,EAAE,GAAG,GAAG,OAAO;yCAxG1B,eAAe;6CAAf,eAAe;CA6G3B"}
|
|
@@ -0,0 +1,131 @@
|
|
|
1
|
+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
2
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
3
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
4
|
+
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;
|
|
5
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
6
|
+
};
|
|
7
|
+
var MJAuth0Provider_1;
|
|
8
|
+
import { Injectable } from '@angular/core';
|
|
9
|
+
import { RegisterClass } from '@memberjunction/global';
|
|
10
|
+
import { MJAuthBase } from '../mjexplorer-auth-base.service';
|
|
11
|
+
import { AuthService, AuthGuard, AuthConfigService, Auth0ClientService, Auth0ClientFactory, AuthClientConfig } from '@auth0/auth0-angular';
|
|
12
|
+
import { of } from 'rxjs';
|
|
13
|
+
import * as i0 from "@angular/core";
|
|
14
|
+
import * as i1 from "@auth0/auth0-angular";
|
|
15
|
+
// Prevent tree-shaking by explicitly referencing the class
|
|
16
|
+
export function LoadMJAuth0Provider() {
|
|
17
|
+
// This function ensures the class is included in the bundle
|
|
18
|
+
return MJAuth0Provider;
|
|
19
|
+
}
|
|
20
|
+
let MJAuth0Provider = class MJAuth0Provider extends MJAuthBase {
|
|
21
|
+
static { MJAuth0Provider_1 = this; }
|
|
22
|
+
auth;
|
|
23
|
+
static PROVIDER_TYPE = 'auth0';
|
|
24
|
+
type = MJAuth0Provider_1.PROVIDER_TYPE;
|
|
25
|
+
/**
|
|
26
|
+
* Factory function to provide Angular dependencies required by Auth0
|
|
27
|
+
* Stored as a static property for the factory to access without instantiation
|
|
28
|
+
*/
|
|
29
|
+
static angularProviderFactory = (environment) => [
|
|
30
|
+
AuthService,
|
|
31
|
+
AuthGuard,
|
|
32
|
+
{
|
|
33
|
+
provide: AuthConfigService,
|
|
34
|
+
useValue: {
|
|
35
|
+
domain: environment.AUTH0_DOMAIN,
|
|
36
|
+
clientId: environment.AUTH0_CLIENTID,
|
|
37
|
+
authorizationParams: {
|
|
38
|
+
redirect_uri: window.location.origin,
|
|
39
|
+
},
|
|
40
|
+
cacheLocation: 'localstorage',
|
|
41
|
+
},
|
|
42
|
+
},
|
|
43
|
+
{
|
|
44
|
+
provide: Auth0ClientService,
|
|
45
|
+
useFactory: Auth0ClientFactory.createClient,
|
|
46
|
+
deps: [AuthClientConfig],
|
|
47
|
+
}
|
|
48
|
+
];
|
|
49
|
+
constructor(auth) {
|
|
50
|
+
const config = {
|
|
51
|
+
name: MJAuth0Provider_1.PROVIDER_TYPE,
|
|
52
|
+
type: MJAuth0Provider_1.PROVIDER_TYPE
|
|
53
|
+
};
|
|
54
|
+
super(config);
|
|
55
|
+
this.auth = auth;
|
|
56
|
+
this.auth.isAuthenticated$.subscribe((loggedIn) => {
|
|
57
|
+
this.updateAuthState(loggedIn);
|
|
58
|
+
});
|
|
59
|
+
}
|
|
60
|
+
login(options) {
|
|
61
|
+
// Auth0's loginWithRedirect executes immediately
|
|
62
|
+
this.auth.loginWithRedirect(options);
|
|
63
|
+
// Return an observable for backward compatibility
|
|
64
|
+
return of(void 0);
|
|
65
|
+
}
|
|
66
|
+
async logout() {
|
|
67
|
+
this.auth.logout({ logoutParams: { returnTo: document.location.origin } });
|
|
68
|
+
}
|
|
69
|
+
async refresh() {
|
|
70
|
+
await this.auth.getAccessTokenSilently();
|
|
71
|
+
return this.auth.idTokenClaims$;
|
|
72
|
+
}
|
|
73
|
+
async getUser() {
|
|
74
|
+
return this.auth.user$;
|
|
75
|
+
}
|
|
76
|
+
isAuthenticated() {
|
|
77
|
+
return this.auth.isAuthenticated$;
|
|
78
|
+
}
|
|
79
|
+
async getUserClaims() {
|
|
80
|
+
return this.auth.idTokenClaims$;
|
|
81
|
+
}
|
|
82
|
+
checkExpiredTokenError(error) {
|
|
83
|
+
return error?.includes('jwt expired');
|
|
84
|
+
}
|
|
85
|
+
// Add required methods for the new interface
|
|
86
|
+
async initialize() {
|
|
87
|
+
// Auth0 Angular SDK handles initialization internally
|
|
88
|
+
// Just subscribe to authentication state
|
|
89
|
+
this.auth.isAuthenticated$.subscribe((loggedIn) => {
|
|
90
|
+
this.updateAuthState(loggedIn);
|
|
91
|
+
});
|
|
92
|
+
}
|
|
93
|
+
async loginInternal(options) {
|
|
94
|
+
this.auth.loginWithRedirect(options);
|
|
95
|
+
}
|
|
96
|
+
async getToken() {
|
|
97
|
+
try {
|
|
98
|
+
const token = await this.auth.getAccessTokenSilently().toPromise();
|
|
99
|
+
return token || null;
|
|
100
|
+
}
|
|
101
|
+
catch (error) {
|
|
102
|
+
console.error('Error getting Auth0 token:', error);
|
|
103
|
+
return null;
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
async handleCallback() {
|
|
107
|
+
// Auth0 Angular SDK handles callbacks internally
|
|
108
|
+
// This method is here for interface compatibility
|
|
109
|
+
}
|
|
110
|
+
getRequiredConfig() {
|
|
111
|
+
return ['clientId', 'domain'];
|
|
112
|
+
}
|
|
113
|
+
validateConfig(_config) {
|
|
114
|
+
// Auth0 configuration is handled by Angular module providers
|
|
115
|
+
// Prefix with underscore to indicate intentionally unused
|
|
116
|
+
return true;
|
|
117
|
+
}
|
|
118
|
+
static ɵfac = function MJAuth0Provider_Factory(t) { return new (t || MJAuth0Provider)(i0.ɵɵinject(i1.AuthService)); };
|
|
119
|
+
static ɵprov = /*@__PURE__*/ i0.ɵɵdefineInjectable({ token: MJAuth0Provider, factory: MJAuth0Provider.ɵfac, providedIn: 'root' });
|
|
120
|
+
};
|
|
121
|
+
MJAuth0Provider = MJAuth0Provider_1 = __decorate([
|
|
122
|
+
RegisterClass(MJAuthBase, 'auth0')
|
|
123
|
+
], MJAuth0Provider);
|
|
124
|
+
export { MJAuth0Provider };
|
|
125
|
+
(() => { (typeof ngDevMode === "undefined" || ngDevMode) && i0.ɵsetClassMetadata(MJAuth0Provider, [{
|
|
126
|
+
type: Injectable,
|
|
127
|
+
args: [{
|
|
128
|
+
providedIn: 'root'
|
|
129
|
+
}]
|
|
130
|
+
}], () => [{ type: i1.AuthService }], null); })();
|
|
131
|
+
//# sourceMappingURL=mjexplorer-auth0-provider.service.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"mjexplorer-auth0-provider.service.js","sourceRoot":"","sources":["../../../src/lib/providers/mjexplorer-auth0-provider.service.ts"],"names":[],"mappings":";;;;;;;AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,eAAe,CAAC;AAC3C,OAAO,EAAE,aAAa,EAAE,MAAM,wBAAwB,CAAC;AACvD,OAAO,EAAE,UAAU,EAAE,MAAM,iCAAiC,CAAC;AAC7D,OAAO,EAAE,WAAW,EAAiB,SAAS,EAAE,iBAAiB,EAAE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AE,CAAC,SAAS,EAAE,CAAC;YACnE,OAAO,KAAK,IAAI,IAAI,CAAC;QACvB,CAAC;QAAC,OAAO,KAAK,EAAE,CAAC;YACf,OAAO,CAAC,KAAK,CAAC,4BAA4B,EAAE,KAAK,CAAC,CAAC;YACnD,OAAO,IAAI,CAAC;QACd,CAAC;IACH,CAAC;IAED,KAAK,CAAC,cAAc;QAClB,iDAAiD;QACjD,kDAAkD;IACpD,CAAC;IAED,iBAAiB;QACf,OAAO,CAAC,UAAU,EAAE,QAAQ,CAAC,CAAC;IAChC,CAAC;IAED,cAAc,CAAC,OAAY;QACzB,6DAA6D;QAC7D,0DAA0D;QAC1D,OAAO,IAAI,CAAC;IACd,CAAC;yEA5GU,eAAe;gEAAf,eAAe,WAAf,eAAe,mBAHd,MAAM;;AAGP,eAAe;IAD3B,aAAa,CAAC,UAAU,EAAE,OAAO,CAAC;GACtB,eAAe,CA6G3B;;iFA7GY,eAAe;cAJ3B,UAAU;eAAC;gBACV,UAAU,EAAE,MAAM;aACnB"}
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
import { MJAuthBase } from '../mjexplorer-auth-base.service';
|
|
2
|
+
import { Observable } from 'rxjs';
|
|
3
|
+
import { MsalBroadcastService, MsalService, MsalGuard } from '@azure/msal-angular';
|
|
4
|
+
import { AccountInfo } from '@azure/msal-common';
|
|
5
|
+
import { PublicClientApplication, InteractionType } from '@azure/msal-browser';
|
|
6
|
+
import * as i0 from "@angular/core";
|
|
7
|
+
export declare function LoadMJMSALProvider(): typeof MJMSALProvider;
|
|
8
|
+
export declare class MJMSALProvider extends MJAuthBase {
|
|
9
|
+
auth: MsalService;
|
|
10
|
+
private msalBroadcastService;
|
|
11
|
+
static readonly PROVIDER_TYPE = "msal";
|
|
12
|
+
type: string;
|
|
13
|
+
private readonly _destroying$;
|
|
14
|
+
private readonly _initializationCompleted$;
|
|
15
|
+
/**
|
|
16
|
+
* Factory function to provide Angular dependencies required by MSAL
|
|
17
|
+
* Stored as a static property for the factory to access without instantiation
|
|
18
|
+
*/
|
|
19
|
+
static angularProviderFactory: (environment: any) => (typeof MsalService | typeof MsalBroadcastService | typeof MsalGuard | {
|
|
20
|
+
provide: import("@angular/core").InjectionToken<string>;
|
|
21
|
+
useValue: PublicClientApplication;
|
|
22
|
+
} | {
|
|
23
|
+
provide: import("@angular/core").InjectionToken<string>;
|
|
24
|
+
useValue: {
|
|
25
|
+
interactionType: InteractionType;
|
|
26
|
+
authRequest: {
|
|
27
|
+
scopes: string[];
|
|
28
|
+
};
|
|
29
|
+
protectedResourceMap?: undefined;
|
|
30
|
+
};
|
|
31
|
+
} | {
|
|
32
|
+
provide: import("@angular/core").InjectionToken<string>;
|
|
33
|
+
useValue: {
|
|
34
|
+
interactionType: InteractionType;
|
|
35
|
+
protectedResourceMap: Map<string, string[]>;
|
|
36
|
+
authRequest?: undefined;
|
|
37
|
+
};
|
|
38
|
+
})[];
|
|
39
|
+
constructor(auth: MsalService, msalBroadcastService: MsalBroadcastService);
|
|
40
|
+
private initializeMSAL;
|
|
41
|
+
private ensureInitialized;
|
|
42
|
+
login(options?: any): Observable<void>;
|
|
43
|
+
logout(): Promise<void>;
|
|
44
|
+
refresh(): Promise<Observable<any>>;
|
|
45
|
+
getUser(): Promise<AccountInfo | null>;
|
|
46
|
+
isAuthenticated(): Observable<boolean>;
|
|
47
|
+
getUserClaims(): Promise<Observable<any>>;
|
|
48
|
+
checkExpiredTokenError(error: string): boolean;
|
|
49
|
+
initialize(): Promise<void>;
|
|
50
|
+
protected loginInternal(options?: any): Promise<void>;
|
|
51
|
+
getToken(): Promise<string | null>;
|
|
52
|
+
handleCallback(): Promise<void>;
|
|
53
|
+
getRequiredConfig(): string[];
|
|
54
|
+
validateConfig(_config: any): boolean;
|
|
55
|
+
static ɵfac: i0.ɵɵFactoryDeclaration<MJMSALProvider, never>;
|
|
56
|
+
static ɵprov: i0.ɵɵInjectableDeclaration<MJMSALProvider>;
|
|
57
|
+
}
|
|
58
|
+
//# sourceMappingURL=mjexplorer-msal-provider.service.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"mjexplorer-msal-provider.service.d.ts","sourceRoot":"","sources":["../../../src/lib/providers/mjexplorer-msal-provider.service.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,UAAU,EAAE,MAAM,iCAAiC,CAAC;AAC7D,OAAO,EAAmB,UAAU,EAA2F,MAAM,MAAM,CAAC;AAC5I,OAAO,EAAE,oBAAoB,EAAE,WAAW,EAA6D,SAAS,EAAE,MAAM,qBAAqB,CAAC;AAC9I,OAAO,EAAE,WAAW,EAAwB,MAAM,oBAAoB,CAAC;AACvE,OAAO,EAAsE,uBAAuB,EAAE,eAAe,EAAE,MAAM,qBAAqB,CAAC;;AAKnJ,wBAAgB,kBAAkB,0BAGjC;AAED,qBAIa,cAAe,SAAQ,UAAU;IA+CzB,IAAI,EAAE,WAAW;IAAE,OAAO,CAAC,oBAAoB;IA9ClE,MAAM,CAAC,QAAQ,CAAC,aAAa,UAAU;IACvC,IAAI,SAAgC;IAEpC,OAAO,CAAC,QAAQ,CAAC,YAAY,CAAuB;IACpD,OAAO,CAAC,QAAQ,CAAC,yBAAyB,CAAuC;IAEjF;;;OAGG;IACH,MAAM,CAAC,sBAAsB,gBAAiB,GAAG;;;;;;;;;;;;;;;;;;;SAkC/C;gBAEiB,IAAI,EAAE,WAAW,EAAU,oBAAoB,EAAE,oBAAoB;YAS1E,cAAc;YA4Cd,iBAAiB;IAMtB,KAAK,CAAC,OAAO,CAAC,EAAE,GAAG,GAAG,UAAU,CAAC,IAAI,CAAC;IAmBlC,MAAM,IAAI,OAAO,CAAC,IAAI,CAAC;IAOvB,OAAO,IAAI,OAAO,CAAC,UAAU,CAAC,GAAG,CAAC,CAAC;IAS1C,OAAO,IAAI,OAAO,CAAC,WAAW,GAAG,IAAI,CAAC;IAKnC,eAAe,IAAI,UAAU,CAAC,OAAO,CAAC;IAKzC,aAAa,IAAI,OAAO,CAAC,UAAU,CAAC,GAAG,CAAC,CAAC;IA+B/C,sBAAsB,CAAC,KAAK,EAAE,MAAM,GAAG,OAAO;IAKxC,UAAU,IAAI,OAAO,CAAC,IAAI,CAAC;cAIjB,aAAa,CAAC,OAAO,CAAC,EAAE,GAAG,GAAG,OAAO,CAAC,IAAI,CAAC;IAoBrD,QAAQ,IAAI,OAAO,CAAC,MAAM,GAAG,IAAI,CAAC;IA8BlC,cAAc,IAAI,OAAO,CAAC,IAAI,CAAC;IAMrC,iBAAiB,IAAI,MAAM,EAAE;IAI7B,cAAc,CAAC,OAAO,EAAE,GAAG,GAAG,OAAO;yCA3P1B,cAAc;6CAAd,cAAc;CA+P1B"}
|
|
@@ -0,0 +1,267 @@
|
|
|
1
|
+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
2
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
3
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
4
|
+
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;
|
|
5
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
6
|
+
};
|
|
7
|
+
var MJMSALProvider_1;
|
|
8
|
+
import { Injectable } from '@angular/core';
|
|
9
|
+
import { RegisterClass } from '@memberjunction/global';
|
|
10
|
+
import { MJAuthBase } from '../mjexplorer-auth-base.service';
|
|
11
|
+
import { BehaviorSubject, Subject, catchError, filter, from, map, of, throwError, takeUntil, take, firstValueFrom } from 'rxjs';
|
|
12
|
+
import { MsalBroadcastService, MsalService, MSAL_INSTANCE, MSAL_GUARD_CONFIG, MSAL_INTERCEPTOR_CONFIG, MsalGuard } from '@azure/msal-angular';
|
|
13
|
+
import { CacheLookupPolicy, InteractionRequiredAuthError, InteractionStatus, PublicClientApplication, InteractionType } from '@azure/msal-browser';
|
|
14
|
+
import { LogError } from '@memberjunction/core';
|
|
15
|
+
import * as i0 from "@angular/core";
|
|
16
|
+
import * as i1 from "@azure/msal-angular";
|
|
17
|
+
// Prevent tree-shaking by explicitly referencing the class
|
|
18
|
+
export function LoadMJMSALProvider() {
|
|
19
|
+
// This function ensures the class is included in the bundle
|
|
20
|
+
return MJMSALProvider;
|
|
21
|
+
}
|
|
22
|
+
let MJMSALProvider = class MJMSALProvider extends MJAuthBase {
|
|
23
|
+
static { MJMSALProvider_1 = this; }
|
|
24
|
+
auth;
|
|
25
|
+
msalBroadcastService;
|
|
26
|
+
static PROVIDER_TYPE = 'msal';
|
|
27
|
+
type = MJMSALProvider_1.PROVIDER_TYPE;
|
|
28
|
+
_destroying$ = new Subject();
|
|
29
|
+
_initializationCompleted$ = new BehaviorSubject(false);
|
|
30
|
+
/**
|
|
31
|
+
* Factory function to provide Angular dependencies required by MSAL
|
|
32
|
+
* Stored as a static property for the factory to access without instantiation
|
|
33
|
+
*/
|
|
34
|
+
static angularProviderFactory = (environment) => [
|
|
35
|
+
{
|
|
36
|
+
provide: MSAL_INSTANCE,
|
|
37
|
+
useValue: new PublicClientApplication({
|
|
38
|
+
auth: {
|
|
39
|
+
clientId: environment.CLIENT_ID,
|
|
40
|
+
authority: environment.CLIENT_AUTHORITY,
|
|
41
|
+
redirectUri: window.location.origin,
|
|
42
|
+
},
|
|
43
|
+
cache: {
|
|
44
|
+
cacheLocation: 'localStorage',
|
|
45
|
+
storeAuthStateInCookie: false,
|
|
46
|
+
},
|
|
47
|
+
}),
|
|
48
|
+
},
|
|
49
|
+
{
|
|
50
|
+
provide: MSAL_GUARD_CONFIG,
|
|
51
|
+
useValue: {
|
|
52
|
+
interactionType: InteractionType.Redirect,
|
|
53
|
+
authRequest: {
|
|
54
|
+
scopes: ['User.Read'],
|
|
55
|
+
},
|
|
56
|
+
},
|
|
57
|
+
},
|
|
58
|
+
{
|
|
59
|
+
provide: MSAL_INTERCEPTOR_CONFIG,
|
|
60
|
+
useValue: {
|
|
61
|
+
interactionType: InteractionType.Redirect,
|
|
62
|
+
protectedResourceMap: new Map([['https://graph.microsoft.com/v1.0/me', ['user.read']]]),
|
|
63
|
+
},
|
|
64
|
+
},
|
|
65
|
+
MsalService,
|
|
66
|
+
MsalGuard,
|
|
67
|
+
MsalBroadcastService
|
|
68
|
+
];
|
|
69
|
+
constructor(auth, msalBroadcastService) {
|
|
70
|
+
const config = {
|
|
71
|
+
name: MJMSALProvider_1.PROVIDER_TYPE,
|
|
72
|
+
type: MJMSALProvider_1.PROVIDER_TYPE
|
|
73
|
+
};
|
|
74
|
+
super(config);
|
|
75
|
+
this.auth = auth;
|
|
76
|
+
this.msalBroadcastService = msalBroadcastService;
|
|
77
|
+
this.initializeMSAL();
|
|
78
|
+
}
|
|
79
|
+
async initializeMSAL() {
|
|
80
|
+
await this.auth.instance.initialize();
|
|
81
|
+
// Handle redirect immediately after initialization
|
|
82
|
+
const redirectResponse = await this.auth.instance.handleRedirectPromise();
|
|
83
|
+
if (redirectResponse && redirectResponse.account) {
|
|
84
|
+
// User just logged in via redirect
|
|
85
|
+
this.auth.instance.setActiveAccount(redirectResponse.account);
|
|
86
|
+
this.updateAuthState(true);
|
|
87
|
+
this.authenticated = true;
|
|
88
|
+
this._initializationCompleted$.next(true); // Signal initialization complete
|
|
89
|
+
// Do a controlled reload after successful login
|
|
90
|
+
// This ensures the app fully reinitializes with the authenticated state
|
|
91
|
+
setTimeout(() => {
|
|
92
|
+
window.location.href = window.location.origin;
|
|
93
|
+
}, 100);
|
|
94
|
+
return;
|
|
95
|
+
}
|
|
96
|
+
else {
|
|
97
|
+
// Set active account if we have one
|
|
98
|
+
const accounts = this.auth.instance.getAllAccounts();
|
|
99
|
+
if (accounts.length > 0) {
|
|
100
|
+
this.auth.instance.setActiveAccount(accounts[0]);
|
|
101
|
+
this.updateAuthState(true);
|
|
102
|
+
this.authenticated = true;
|
|
103
|
+
this._initializationCompleted$.next(true);
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
// Subscribe to broadcast service for ongoing auth state changes
|
|
107
|
+
this.msalBroadcastService.inProgress$
|
|
108
|
+
.pipe(filter((status) => status === InteractionStatus.None), takeUntil(this._destroying$))
|
|
109
|
+
.subscribe(() => {
|
|
110
|
+
const isAuth = this.auth.instance.getAllAccounts().length > 0;
|
|
111
|
+
this.updateAuthState(isAuth);
|
|
112
|
+
this.authenticated = isAuth;
|
|
113
|
+
if (isAuth) {
|
|
114
|
+
this.auth.instance.setActiveAccount(this.auth.instance.getAllAccounts()[0]);
|
|
115
|
+
}
|
|
116
|
+
this._initializationCompleted$.next(true);
|
|
117
|
+
});
|
|
118
|
+
}
|
|
119
|
+
// Ensure methods wait for initialization
|
|
120
|
+
async ensureInitialized() {
|
|
121
|
+
if (!this._initializationCompleted$.value) {
|
|
122
|
+
await firstValueFrom(this._initializationCompleted$.pipe(filter(done => done), take(1)));
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
login(options) {
|
|
126
|
+
const silentRequest = {
|
|
127
|
+
scopes: ['User.Read', 'email', 'profile'],
|
|
128
|
+
...options
|
|
129
|
+
};
|
|
130
|
+
this.auth.loginRedirect(silentRequest).subscribe({
|
|
131
|
+
next: () => {
|
|
132
|
+
this.auth.instance.setActiveAccount(this.auth.instance.getAllAccounts()[0] || null);
|
|
133
|
+
// Don't reload here - let the redirect handler manage the flow
|
|
134
|
+
},
|
|
135
|
+
error: (error) => {
|
|
136
|
+
LogError(error);
|
|
137
|
+
}
|
|
138
|
+
});
|
|
139
|
+
return of(void 0);
|
|
140
|
+
}
|
|
141
|
+
async logout() {
|
|
142
|
+
await this.ensureInitialized();
|
|
143
|
+
this.auth.logoutRedirect().subscribe(() => {
|
|
144
|
+
// Logout will trigger a redirect
|
|
145
|
+
});
|
|
146
|
+
}
|
|
147
|
+
async refresh() {
|
|
148
|
+
await this.ensureInitialized();
|
|
149
|
+
const silentRequest = {
|
|
150
|
+
scopes: ['User.Read', 'email', 'profile'],
|
|
151
|
+
cacheLookupPolicy: CacheLookupPolicy.RefreshTokenAndNetwork,
|
|
152
|
+
};
|
|
153
|
+
return from(this.auth.instance.acquireTokenSilent(silentRequest));
|
|
154
|
+
}
|
|
155
|
+
async getUser() {
|
|
156
|
+
await this.ensureInitialized();
|
|
157
|
+
return this.auth.instance.getActiveAccount();
|
|
158
|
+
}
|
|
159
|
+
isAuthenticated() {
|
|
160
|
+
// Return the base class observable which is being updated in initializeMSAL
|
|
161
|
+
return this.isAuthenticated$.asObservable();
|
|
162
|
+
}
|
|
163
|
+
async getUserClaims() {
|
|
164
|
+
await this.ensureInitialized();
|
|
165
|
+
const account = this.auth.instance.getActiveAccount();
|
|
166
|
+
if (!account) {
|
|
167
|
+
// No account, return null observable
|
|
168
|
+
return of(null);
|
|
169
|
+
}
|
|
170
|
+
const silentRequest = {
|
|
171
|
+
scopes: ['User.Read', 'email', 'profile'],
|
|
172
|
+
account: account,
|
|
173
|
+
cacheLookupPolicy: CacheLookupPolicy.RefreshTokenAndNetwork
|
|
174
|
+
};
|
|
175
|
+
return from(this.auth.instance.acquireTokenSilent(silentRequest)).pipe(map((response) => response), catchError((error) => {
|
|
176
|
+
LogError(error);
|
|
177
|
+
if (error instanceof InteractionRequiredAuthError) {
|
|
178
|
+
// Try popup as fallback
|
|
179
|
+
return from(this.auth.instance.acquireTokenPopup({
|
|
180
|
+
scopes: ['User.Read', 'email', 'profile']
|
|
181
|
+
}));
|
|
182
|
+
}
|
|
183
|
+
this.authenticated = false;
|
|
184
|
+
return throwError(() => error);
|
|
185
|
+
}));
|
|
186
|
+
}
|
|
187
|
+
checkExpiredTokenError(error) {
|
|
188
|
+
return error?.trim().toLowerCase().includes('you need to be authorized to perform');
|
|
189
|
+
}
|
|
190
|
+
// Required methods for the new interface
|
|
191
|
+
async initialize() {
|
|
192
|
+
await this.ensureInitialized();
|
|
193
|
+
}
|
|
194
|
+
async loginInternal(options) {
|
|
195
|
+
await this.ensureInitialized();
|
|
196
|
+
const silentRequest = {
|
|
197
|
+
scopes: ['User.Read', 'email', 'profile'],
|
|
198
|
+
...options
|
|
199
|
+
};
|
|
200
|
+
return new Promise((resolve, reject) => {
|
|
201
|
+
this.auth.loginRedirect(silentRequest).subscribe({
|
|
202
|
+
next: () => {
|
|
203
|
+
resolve();
|
|
204
|
+
},
|
|
205
|
+
error: (error) => {
|
|
206
|
+
LogError(error);
|
|
207
|
+
reject(error);
|
|
208
|
+
}
|
|
209
|
+
});
|
|
210
|
+
});
|
|
211
|
+
}
|
|
212
|
+
async getToken() {
|
|
213
|
+
await this.ensureInitialized();
|
|
214
|
+
try {
|
|
215
|
+
const account = this.auth.instance.getActiveAccount();
|
|
216
|
+
if (!account) {
|
|
217
|
+
return null;
|
|
218
|
+
}
|
|
219
|
+
const response = await this.auth.instance.acquireTokenSilent({
|
|
220
|
+
scopes: ['User.Read'],
|
|
221
|
+
account: account,
|
|
222
|
+
forceRefresh: false
|
|
223
|
+
});
|
|
224
|
+
return response.accessToken;
|
|
225
|
+
}
|
|
226
|
+
catch (error) {
|
|
227
|
+
if (error instanceof InteractionRequiredAuthError) {
|
|
228
|
+
// Try interactive login if silent acquisition fails
|
|
229
|
+
try {
|
|
230
|
+
const response = await this.auth.instance.acquireTokenPopup({
|
|
231
|
+
scopes: ['User.Read']
|
|
232
|
+
});
|
|
233
|
+
return response.accessToken;
|
|
234
|
+
}
|
|
235
|
+
catch (popupError) {
|
|
236
|
+
console.error('Failed to acquire token via popup:', popupError);
|
|
237
|
+
}
|
|
238
|
+
}
|
|
239
|
+
return null;
|
|
240
|
+
}
|
|
241
|
+
}
|
|
242
|
+
async handleCallback() {
|
|
243
|
+
// MSAL Angular handles callbacks internally through its broadcast service
|
|
244
|
+
// The handleRedirectPromise is called in initializeMSAL
|
|
245
|
+
await this.ensureInitialized();
|
|
246
|
+
}
|
|
247
|
+
getRequiredConfig() {
|
|
248
|
+
return ['clientId', 'tenantId'];
|
|
249
|
+
}
|
|
250
|
+
validateConfig(_config) {
|
|
251
|
+
// MSAL configuration is handled by Angular module providers
|
|
252
|
+
return true;
|
|
253
|
+
}
|
|
254
|
+
static ɵfac = function MJMSALProvider_Factory(t) { return new (t || MJMSALProvider)(i0.ɵɵinject(i1.MsalService), i0.ɵɵinject(i1.MsalBroadcastService)); };
|
|
255
|
+
static ɵprov = /*@__PURE__*/ i0.ɵɵdefineInjectable({ token: MJMSALProvider, factory: MJMSALProvider.ɵfac, providedIn: 'root' });
|
|
256
|
+
};
|
|
257
|
+
MJMSALProvider = MJMSALProvider_1 = __decorate([
|
|
258
|
+
RegisterClass(MJAuthBase, 'msal')
|
|
259
|
+
], MJMSALProvider);
|
|
260
|
+
export { MJMSALProvider };
|
|
261
|
+
(() => { (typeof ngDevMode === "undefined" || ngDevMode) && i0.ɵsetClassMetadata(MJMSALProvider, [{
|
|
262
|
+
type: Injectable,
|
|
263
|
+
args: [{
|
|
264
|
+
providedIn: 'root'
|
|
265
|
+
}]
|
|
266
|
+
}], () => [{ type: i1.MsalService }, { type: i1.MsalBroadcastService }], null); })();
|
|
267
|
+
//# sourceMappingURL=mjexplorer-msal-provider.service.js.map
|