@equinor/fusion-framework-module-msal 4.0.0 → 4.0.2
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/CHANGELOG.md +103 -81
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/module.js.map +1 -1
- package/dist/esm/resolve-version.js.map +1 -1
- package/dist/esm/static.js +1 -1
- package/dist/esm/static.js.map +1 -1
- package/dist/esm/v2/client/client.js.map +1 -1
- package/dist/esm/v2/client/create-auth-client.js.map +1 -1
- package/dist/esm/v2/client/log/console.js +4 -1
- package/dist/esm/v2/client/log/console.js.map +1 -1
- package/dist/esm/v2/client/util/browser.js.map +1 -1
- package/dist/esm/v2/client/util/url.js.map +1 -1
- package/dist/esm/v2/configurator.js.map +1 -1
- package/dist/esm/v2/provider.js +2 -0
- package/dist/esm/v2/provider.js.map +1 -1
- package/dist/esm/version.js +1 -1
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/dist/types/static.d.ts +1 -1
- package/dist/types/types.d.ts +2 -2
- package/dist/types/v2/client/client.d.ts +3 -3
- package/dist/types/v2/client/create-auth-client.d.ts +1 -1
- package/dist/types/v2/client/log/console.d.ts +2 -0
- package/dist/types/v2/client/request.d.ts +1 -1
- package/dist/types/v2/configurator.d.ts +1 -1
- package/dist/types/v2/provider.d.ts +8 -4
- package/dist/types/version.d.ts +1 -1
- package/package.json +3 -3
- package/src/index.ts +7 -7
- package/src/module.ts +48 -48
- package/src/resolve-version.ts +30 -30
- package/src/static.ts +2 -2
- package/src/types.ts +4 -4
- package/src/v2/client/client.ts +126 -130
- package/src/v2/client/create-auth-client.ts +17 -17
- package/src/v2/client/log/console.ts +37 -34
- package/src/v2/client/request.ts +1 -1
- package/src/v2/client/util/browser.ts +2 -2
- package/src/v2/client/util/url.ts +5 -5
- package/src/v2/configurator.ts +29 -29
- package/src/v2/provider.ts +155 -151
- package/src/v2/types.ts +19 -19
- package/src/version.ts +1 -1
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import { Configuration, IPublicClientApplication } from '@azure/msal-browser';
|
|
1
|
+
import type { Configuration, IPublicClientApplication } from '@azure/msal-browser';
|
|
2
2
|
import { AuthClient } from './client';
|
|
3
3
|
import { normalizeUri } from './util/url';
|
|
4
4
|
|
|
5
5
|
export type AuthClientConfig = Configuration & {
|
|
6
|
-
|
|
6
|
+
auth: Partial<Configuration['auth']>;
|
|
7
7
|
};
|
|
8
8
|
|
|
9
9
|
/**
|
|
@@ -27,22 +27,22 @@ export type AuthClientConfig = Configuration & {
|
|
|
27
27
|
* @param ctor - optional client class
|
|
28
28
|
*/
|
|
29
29
|
export const createAuthClient = <T extends IPublicClientApplication = AuthClient>(
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
30
|
+
tenantId: string,
|
|
31
|
+
clientId: string,
|
|
32
|
+
redirectUri?: string,
|
|
33
|
+
config?: AuthClientConfig,
|
|
34
|
+
ctor?: new (tenantId: string, config: Configuration) => T,
|
|
35
35
|
): T => {
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
36
|
+
const auth: Configuration['auth'] = {
|
|
37
|
+
clientId,
|
|
38
|
+
redirectUri: normalizeUri(redirectUri || ''),
|
|
39
|
+
navigateToLoginRequestUrl: false,
|
|
40
|
+
authority: `https://login.microsoftonline.com/${tenantId}`,
|
|
41
|
+
...config?.auth,
|
|
42
|
+
};
|
|
43
|
+
const cache = { cacheLocation: 'localStorage', ...config?.cache };
|
|
44
|
+
const system = config?.system;
|
|
45
|
+
return new (ctor || AuthClient)(tenantId, { auth, cache, system }) as T;
|
|
46
46
|
};
|
|
47
47
|
|
|
48
48
|
export default createAuthClient;
|
|
@@ -14,42 +14,45 @@ type ConsoleLevel = 'error' | 'warn' | 'info' | 'debug';
|
|
|
14
14
|
* ```
|
|
15
15
|
*/
|
|
16
16
|
export class ConsoleLogger extends Logger {
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
17
|
+
/**
|
|
18
|
+
* @param logLevel - 0-1-2-3 (error-warning-info-debug) if not provided all records logged
|
|
19
|
+
*/
|
|
20
|
+
constructor(logLevel?: LogLevel) {
|
|
21
|
+
super({
|
|
22
|
+
logLevel,
|
|
23
|
+
loggerCallback: (...args: [LogLevel, string, boolean]) => this.loggerCallback(...args),
|
|
24
|
+
});
|
|
25
|
+
}
|
|
26
26
|
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
27
|
+
/** @inheritdoc */
|
|
28
|
+
protected loggerCallback(lvl: LogLevel, msg: string, _containsPii?: boolean): void {
|
|
29
|
+
console[this.getLogType(lvl)](
|
|
30
|
+
`%c FUSION::MSAL %c %s`,
|
|
31
|
+
'border: 1px solid;',
|
|
32
|
+
'border: none;',
|
|
33
|
+
msg,
|
|
34
|
+
);
|
|
35
|
+
}
|
|
36
36
|
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
37
|
+
/**
|
|
38
|
+
* Map log level to console log function type
|
|
39
|
+
*
|
|
40
|
+
* @default LogLevel.Verbose
|
|
41
|
+
*/
|
|
42
|
+
protected getLogType = (lvl: LogLevel): ConsoleLevel => {
|
|
43
|
+
switch (lvl) {
|
|
44
|
+
case LogLevel.Error:
|
|
45
|
+
return 'error';
|
|
46
|
+
case LogLevel.Warning:
|
|
47
|
+
return 'warn';
|
|
48
|
+
case LogLevel.Info:
|
|
49
|
+
return 'info';
|
|
50
|
+
case LogLevel.Verbose:
|
|
51
|
+
return 'debug';
|
|
52
|
+
default:
|
|
53
|
+
return this.getLogType(LogLevel.Verbose);
|
|
54
|
+
}
|
|
55
|
+
};
|
|
53
56
|
}
|
|
54
57
|
|
|
55
58
|
export default ConsoleLogger;
|
package/src/v2/client/request.ts
CHANGED
|
@@ -9,6 +9,6 @@
|
|
|
9
9
|
* @param history - append navigation to history
|
|
10
10
|
*/
|
|
11
11
|
export const redirect = (url: string, timeout = 3000, history?: boolean): Promise<void> => {
|
|
12
|
-
|
|
13
|
-
|
|
12
|
+
history ? window.location.assign(url) : window.location.replace(url);
|
|
13
|
+
return new Promise((_, reject) => setTimeout(reject, timeout));
|
|
14
14
|
};
|
|
@@ -8,9 +8,9 @@
|
|
|
8
8
|
* @param home - base url for relative urls
|
|
9
9
|
*/
|
|
10
10
|
export const normalizeUri = (uri: string, home: string = window.location.origin): string => {
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
11
|
+
uri = uri.match(/^http[s]?/) ? uri : home + uri;
|
|
12
|
+
const { origin, pathname } = new URL(uri);
|
|
13
|
+
return origin + pathname.replace(/([^:]\/)\/+/g, '$1');
|
|
14
14
|
};
|
|
15
15
|
|
|
16
16
|
/**
|
|
@@ -19,6 +19,6 @@ export const normalizeUri = (uri: string, home: string = window.location.origin)
|
|
|
19
19
|
* @internal
|
|
20
20
|
*/
|
|
21
21
|
export const compareOrigin = (a: string, b: string): boolean => {
|
|
22
|
-
|
|
23
|
-
|
|
22
|
+
const url = { a: normalizeUri(a), b: normalizeUri(b) };
|
|
23
|
+
return url.a === url.b;
|
|
24
24
|
};
|
package/src/v2/configurator.ts
CHANGED
|
@@ -4,55 +4,55 @@ import { BaseConfigBuilder } from '@equinor/fusion-framework-module';
|
|
|
4
4
|
|
|
5
5
|
import { MsalModuleVersion } from '../static';
|
|
6
6
|
import semver from 'semver';
|
|
7
|
-
import { IAuthProvider } from './provider';
|
|
7
|
+
import type { IAuthProvider } from './provider';
|
|
8
8
|
|
|
9
9
|
const VersionSchema = z.string().transform((x: string) => String(semver.coerce(x)));
|
|
10
10
|
|
|
11
11
|
const AuthClientConfigSchema = z.object({
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
12
|
+
clientId: z.string(),
|
|
13
|
+
tenantId: z.string(),
|
|
14
|
+
redirectUri: z.string().optional(),
|
|
15
15
|
});
|
|
16
16
|
|
|
17
17
|
// NOTE: this might need refinement to validate the provider
|
|
18
18
|
const AuthClientSchema = z.custom<IAuthProvider>();
|
|
19
19
|
|
|
20
20
|
const AuthConfigSchema = z.object({
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
21
|
+
client: AuthClientConfigSchema.optional(),
|
|
22
|
+
provider: AuthClientSchema.optional(),
|
|
23
|
+
requiresAuth: z.boolean().optional(),
|
|
24
|
+
version: VersionSchema,
|
|
25
25
|
});
|
|
26
26
|
|
|
27
27
|
export type AuthClientConfig = z.infer<typeof AuthClientConfigSchema>;
|
|
28
28
|
export type AuthConfig = z.infer<typeof AuthConfigSchema>;
|
|
29
29
|
|
|
30
30
|
export class AuthConfigurator extends BaseConfigBuilder<AuthConfig> {
|
|
31
|
-
|
|
31
|
+
public version = MsalModuleVersion.Latest as const;
|
|
32
32
|
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
33
|
+
constructor() {
|
|
34
|
+
super();
|
|
35
|
+
this._set('version', async () => this.version);
|
|
36
|
+
}
|
|
37
37
|
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
38
|
+
setClientConfig(config?: z.infer<typeof AuthClientConfigSchema>): void {
|
|
39
|
+
this._set('client', async () => config);
|
|
40
|
+
}
|
|
41
41
|
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
42
|
+
setRequiresAuth(requiresAuth: boolean): void {
|
|
43
|
+
this._set('requiresAuth', async () => requiresAuth);
|
|
44
|
+
}
|
|
45
45
|
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
46
|
+
setProvider(provider?: z.infer<typeof AuthClientSchema>): void {
|
|
47
|
+
this._set('provider', async () => provider);
|
|
48
|
+
}
|
|
49
49
|
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
50
|
+
setVersion(version: string): void {
|
|
51
|
+
this._set('version', async () => version);
|
|
52
|
+
}
|
|
53
53
|
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
54
|
+
async _processConfig(config: AuthConfig): Promise<AuthConfig> {
|
|
55
|
+
// TODO: handle parsing of clientConfig
|
|
56
|
+
return AuthConfigSchema.parseAsync(config);
|
|
57
|
+
}
|
|
58
58
|
}
|
package/src/v2/provider.ts
CHANGED
|
@@ -1,166 +1,170 @@
|
|
|
1
|
-
import { AuthClient, createAuthClient, AuthRequest, ConsoleLogger } from './client';
|
|
1
|
+
import { type AuthClient, createAuthClient, type AuthRequest, ConsoleLogger } from './client';
|
|
2
2
|
|
|
3
3
|
import { MsalModuleVersion } from '../static';
|
|
4
4
|
|
|
5
|
-
import { AuthClientConfig } from './configurator';
|
|
6
|
-
import { AccountInfo, AuthenticationResult } from './types';
|
|
7
|
-
import { IProxyProvider } from '../types';
|
|
5
|
+
import type { AuthClientConfig } from './configurator';
|
|
6
|
+
import type { AccountInfo, AuthenticationResult } from './types';
|
|
7
|
+
import type { IProxyProvider } from '../types';
|
|
8
8
|
import resolveVersion from '../resolve-version';
|
|
9
9
|
import { SemanticVersion } from '@equinor/fusion-framework-module';
|
|
10
10
|
|
|
11
11
|
export interface IAuthProvider {
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
12
|
+
// readonly defaultClient: AuthClient;
|
|
13
|
+
/**
|
|
14
|
+
* @deprecated
|
|
15
|
+
*/
|
|
16
|
+
// biome-ignore lint/suspicious/noExplicitAny: this is deprecated
|
|
17
|
+
readonly defaultConfig: any | undefined;
|
|
18
|
+
readonly defaultAccount: AccountInfo | undefined;
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* Acquire token from default auth client
|
|
22
|
+
* @param req Auth request options
|
|
23
|
+
*/
|
|
24
|
+
acquireToken(req: AuthRequest): Promise<AuthenticationResult | void>;
|
|
25
|
+
|
|
26
|
+
/**
|
|
27
|
+
* Acquire access token from default auth client
|
|
28
|
+
* @param req Auth request options
|
|
29
|
+
*/
|
|
30
|
+
acquireAccessToken(req: AuthRequest): Promise<string | undefined>;
|
|
31
|
+
|
|
32
|
+
/**
|
|
33
|
+
* Login to default auth client
|
|
34
|
+
*/
|
|
35
|
+
login(): Promise<void>;
|
|
36
|
+
|
|
37
|
+
/**
|
|
38
|
+
* Logout
|
|
39
|
+
*/
|
|
40
|
+
logout(options?: { redirectUri?: string }): Promise<void>;
|
|
41
|
+
|
|
42
|
+
/**
|
|
43
|
+
* Handle default client redirect callback
|
|
44
|
+
*/
|
|
45
|
+
handleRedirect(): Promise<void | null>;
|
|
42
46
|
}
|
|
43
47
|
|
|
44
48
|
export class AuthProvider implements IAuthProvider, IProxyProvider {
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
49
|
+
#client: AuthClient;
|
|
50
|
+
|
|
51
|
+
get version(): SemanticVersion {
|
|
52
|
+
return new SemanticVersion(MsalModuleVersion.Latest);
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
/** @deprecated */
|
|
56
|
+
get defaultClient(): AuthClient {
|
|
57
|
+
return this.getClient();
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
get defaultAccount(): AccountInfo | undefined {
|
|
61
|
+
return this.defaultClient.account;
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
/** @deprecated */
|
|
65
|
+
get defaultConfig(): AuthClientConfig | undefined {
|
|
66
|
+
return this._config;
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
constructor(protected _config: AuthClientConfig) {
|
|
70
|
+
this.#client = this.createClient();
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
/** @deprecated */
|
|
74
|
+
getClient(): AuthClient {
|
|
75
|
+
return this.#client;
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
/** @deprecated */
|
|
79
|
+
createClient(): AuthClient {
|
|
80
|
+
const client = createAuthClient(
|
|
81
|
+
this._config.tenantId,
|
|
82
|
+
this._config.clientId,
|
|
83
|
+
this._config.redirectUri,
|
|
84
|
+
);
|
|
85
|
+
// TODO - fix with log streamer
|
|
86
|
+
client.setLogger(new ConsoleLogger(0));
|
|
87
|
+
|
|
88
|
+
return client;
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
async handleRedirect() {
|
|
92
|
+
const { redirectUri } = this.defaultConfig || {};
|
|
93
|
+
if (window.location.pathname === redirectUri) {
|
|
94
|
+
const client = this.defaultClient;
|
|
95
|
+
const logger = client.getLogger();
|
|
96
|
+
const { requestOrigin } = client;
|
|
97
|
+
|
|
98
|
+
await client.handleRedirectPromise();
|
|
99
|
+
if (requestOrigin === redirectUri) {
|
|
100
|
+
logger.warning(`detected callback loop from url ${redirectUri}, redirecting to root`);
|
|
101
|
+
window.location.replace('/');
|
|
102
|
+
} else {
|
|
103
|
+
window.location.replace(requestOrigin || '/');
|
|
104
|
+
}
|
|
63
105
|
}
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
106
|
+
return null;
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
acquireToken(req: AuthRequest): ReturnType<IAuthProvider['acquireToken']> {
|
|
110
|
+
return this.defaultClient.acquireToken(req);
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
async acquireAccessToken(req: AuthRequest) {
|
|
114
|
+
const token = await this.acquireToken(req);
|
|
115
|
+
return token ? token.accessToken : undefined;
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
async login(options?: { onlyIfRequired?: boolean }) {
|
|
119
|
+
// skip login if already logged in and has valid claims
|
|
120
|
+
if (options?.onlyIfRequired && this.defaultClient.hasValidClaims) {
|
|
121
|
+
return;
|
|
72
122
|
}
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
123
|
+
await this.defaultClient.login();
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
async logout(options?: { redirectUri?: string }): Promise<void> {
|
|
127
|
+
// TODO - might have an option for popup or redirect
|
|
128
|
+
await this.defaultClient.logoutRedirect({
|
|
129
|
+
postLogoutRedirectUri: options?.redirectUri,
|
|
130
|
+
account: this.defaultAccount,
|
|
131
|
+
});
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
createProxyProvider<T = IAuthProvider>(version: string): T {
|
|
135
|
+
// TODO - check if version is supported and telemetry
|
|
136
|
+
const { enumVersion } = resolveVersion(version);
|
|
137
|
+
switch (enumVersion) {
|
|
138
|
+
case MsalModuleVersion.V2:
|
|
139
|
+
case MsalModuleVersion.Latest:
|
|
140
|
+
return this._createProxyProvider_v2() as T;
|
|
141
|
+
default:
|
|
142
|
+
throw new Error(`Version ${version} is not supported`);
|
|
85
143
|
}
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
_createProxyProvider_v2(): IAuthProvider {
|
|
147
|
+
return new Proxy(this, {
|
|
148
|
+
get: (target: AuthProvider, prop) => {
|
|
149
|
+
switch (prop) {
|
|
150
|
+
case 'version':
|
|
151
|
+
return target.version;
|
|
152
|
+
case 'defaultAccount':
|
|
153
|
+
return target.defaultAccount;
|
|
154
|
+
case 'defaultConfig':
|
|
155
|
+
return target.defaultConfig;
|
|
156
|
+
case 'acquireToken':
|
|
157
|
+
return target.acquireToken.bind(target);
|
|
158
|
+
case 'acquireAccessToken':
|
|
159
|
+
return target.acquireAccessToken.bind(target);
|
|
160
|
+
case 'login':
|
|
161
|
+
return target.login.bind(target);
|
|
162
|
+
case 'handleRedirect':
|
|
163
|
+
return target.handleRedirect.bind(target);
|
|
164
|
+
case 'createProxyProvider':
|
|
165
|
+
return target.createProxyProvider.bind(target);
|
|
103
166
|
}
|
|
104
|
-
|
|
105
|
-
}
|
|
106
|
-
|
|
107
|
-
acquireToken(req: AuthRequest): ReturnType<IAuthProvider['acquireToken']> {
|
|
108
|
-
return this.defaultClient.acquireToken(req);
|
|
109
|
-
}
|
|
110
|
-
|
|
111
|
-
async acquireAccessToken(req: AuthRequest) {
|
|
112
|
-
const token = await this.acquireToken(req);
|
|
113
|
-
return token ? token.accessToken : undefined;
|
|
114
|
-
}
|
|
115
|
-
|
|
116
|
-
async login(options?: { onlyIfRequired?: boolean }) {
|
|
117
|
-
// skip login if already logged in and has valid claims
|
|
118
|
-
if (options?.onlyIfRequired && this.defaultClient.hasValidClaims) {
|
|
119
|
-
return;
|
|
120
|
-
}
|
|
121
|
-
await this.defaultClient.login();
|
|
122
|
-
}
|
|
123
|
-
|
|
124
|
-
async logout(options?: { redirectUri?: string }): Promise<void> {
|
|
125
|
-
// TODO - might have an option for popup or redirect
|
|
126
|
-
await this.defaultClient.logoutRedirect({
|
|
127
|
-
postLogoutRedirectUri: options?.redirectUri,
|
|
128
|
-
account: this.defaultAccount,
|
|
129
|
-
});
|
|
130
|
-
}
|
|
131
|
-
|
|
132
|
-
createProxyProvider<T = IAuthProvider>(version: string): T {
|
|
133
|
-
// TODO - check if version is supported and telemetry
|
|
134
|
-
const { enumVersion } = resolveVersion(version);
|
|
135
|
-
switch (enumVersion) {
|
|
136
|
-
case MsalModuleVersion.V2:
|
|
137
|
-
case MsalModuleVersion.Latest:
|
|
138
|
-
return this._createProxyProvider_v2() as T;
|
|
139
|
-
default:
|
|
140
|
-
throw new Error(`Version ${version} is not supported`);
|
|
141
|
-
}
|
|
142
|
-
}
|
|
143
|
-
|
|
144
|
-
_createProxyProvider_v2(): IAuthProvider {
|
|
145
|
-
return new Proxy(this, {
|
|
146
|
-
get: (target: AuthProvider, prop) => {
|
|
147
|
-
switch (prop) {
|
|
148
|
-
case 'version':
|
|
149
|
-
return target.version;
|
|
150
|
-
case 'defaultAccount':
|
|
151
|
-
return target.defaultAccount;
|
|
152
|
-
case 'acquireToken':
|
|
153
|
-
return target.acquireToken.bind(target);
|
|
154
|
-
case 'acquireAccessToken':
|
|
155
|
-
return target.acquireAccessToken.bind(target);
|
|
156
|
-
case 'login':
|
|
157
|
-
return target.login.bind(target);
|
|
158
|
-
case 'handleRedirect':
|
|
159
|
-
return target.handleRedirect.bind(target);
|
|
160
|
-
case 'createProxyProvider':
|
|
161
|
-
return target.createProxyProvider.bind(target);
|
|
162
|
-
}
|
|
163
|
-
},
|
|
164
|
-
});
|
|
165
|
-
}
|
|
167
|
+
},
|
|
168
|
+
});
|
|
169
|
+
}
|
|
166
170
|
}
|
package/src/v2/types.ts
CHANGED
|
@@ -1,24 +1,24 @@
|
|
|
1
1
|
export type AccountInfo = {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
2
|
+
homeAccountId: string;
|
|
3
|
+
environment: string;
|
|
4
|
+
tenantId: string;
|
|
5
|
+
username: string;
|
|
6
|
+
localAccountId: string;
|
|
7
|
+
name?: string;
|
|
8
|
+
idTokenClaims?: {
|
|
9
|
+
[key: string]: string | number | string[] | object | undefined | unknown;
|
|
10
|
+
};
|
|
11
11
|
};
|
|
12
12
|
|
|
13
13
|
export type AuthenticationResult = {
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
14
|
+
authority: string;
|
|
15
|
+
uniqueId: string;
|
|
16
|
+
tenantId: string;
|
|
17
|
+
scopes: Array<string>;
|
|
18
|
+
account: AccountInfo | null;
|
|
19
|
+
idToken: string;
|
|
20
|
+
idTokenClaims: object;
|
|
21
|
+
accessToken: string;
|
|
22
|
+
expiresOn: Date | null;
|
|
23
|
+
tokenType: string;
|
|
24
24
|
};
|
package/src/version.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
// Generated by genversion.
|
|
2
|
-
export const version = '4.0.
|
|
2
|
+
export const version = '4.0.2';
|