@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.
Files changed (42) hide show
  1. package/CHANGELOG.md +103 -81
  2. package/dist/esm/index.js.map +1 -1
  3. package/dist/esm/module.js.map +1 -1
  4. package/dist/esm/resolve-version.js.map +1 -1
  5. package/dist/esm/static.js +1 -1
  6. package/dist/esm/static.js.map +1 -1
  7. package/dist/esm/v2/client/client.js.map +1 -1
  8. package/dist/esm/v2/client/create-auth-client.js.map +1 -1
  9. package/dist/esm/v2/client/log/console.js +4 -1
  10. package/dist/esm/v2/client/log/console.js.map +1 -1
  11. package/dist/esm/v2/client/util/browser.js.map +1 -1
  12. package/dist/esm/v2/client/util/url.js.map +1 -1
  13. package/dist/esm/v2/configurator.js.map +1 -1
  14. package/dist/esm/v2/provider.js +2 -0
  15. package/dist/esm/v2/provider.js.map +1 -1
  16. package/dist/esm/version.js +1 -1
  17. package/dist/tsconfig.tsbuildinfo +1 -1
  18. package/dist/types/static.d.ts +1 -1
  19. package/dist/types/types.d.ts +2 -2
  20. package/dist/types/v2/client/client.d.ts +3 -3
  21. package/dist/types/v2/client/create-auth-client.d.ts +1 -1
  22. package/dist/types/v2/client/log/console.d.ts +2 -0
  23. package/dist/types/v2/client/request.d.ts +1 -1
  24. package/dist/types/v2/configurator.d.ts +1 -1
  25. package/dist/types/v2/provider.d.ts +8 -4
  26. package/dist/types/version.d.ts +1 -1
  27. package/package.json +3 -3
  28. package/src/index.ts +7 -7
  29. package/src/module.ts +48 -48
  30. package/src/resolve-version.ts +30 -30
  31. package/src/static.ts +2 -2
  32. package/src/types.ts +4 -4
  33. package/src/v2/client/client.ts +126 -130
  34. package/src/v2/client/create-auth-client.ts +17 -17
  35. package/src/v2/client/log/console.ts +37 -34
  36. package/src/v2/client/request.ts +1 -1
  37. package/src/v2/client/util/browser.ts +2 -2
  38. package/src/v2/client/util/url.ts +5 -5
  39. package/src/v2/configurator.ts +29 -29
  40. package/src/v2/provider.ts +155 -151
  41. package/src/v2/types.ts +19 -19
  42. package/src/version.ts +1 -1
@@ -1,5 +1,5 @@
1
1
  export declare const ModuleName: "msal";
2
2
  export declare enum MsalModuleVersion {
3
3
  V2 = "v2",
4
- Latest = "4.0.0"
4
+ Latest = "4.0.2"
5
5
  }
@@ -1,5 +1,5 @@
1
- import { type SemVer } from 'semver';
2
- import { MsalModuleVersion } from './static';
1
+ import type { SemVer } from 'semver';
2
+ import type { MsalModuleVersion } from './static';
3
3
  export interface IProxyProvider {
4
4
  version: string | SemVer;
5
5
  createProxyProvider<T>(version: MsalModuleVersion): T;
@@ -1,6 +1,6 @@
1
- import { PublicClientApplication, Configuration, AuthenticationResult, AccountInfo as AccountInfoBase } from '@azure/msal-browser';
2
- import { AuthBehavior } from './behavior';
3
- import { AuthRequest } from './request';
1
+ import { PublicClientApplication, type Configuration, type AuthenticationResult, type AccountInfo as AccountInfoBase } from '@azure/msal-browser';
2
+ import { type AuthBehavior } from './behavior';
3
+ import type { AuthRequest } from './request';
4
4
  export type IdTokenClaims = {
5
5
  aud: string;
6
6
  exp: number;
@@ -1,4 +1,4 @@
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
  export type AuthClientConfig = Configuration & {
4
4
  auth: Partial<Configuration['auth']>;
@@ -20,6 +20,8 @@ export declare class ConsoleLogger extends Logger {
20
20
  protected loggerCallback(lvl: LogLevel, msg: string, _containsPii?: boolean): void;
21
21
  /**
22
22
  * Map log level to console log function type
23
+ *
24
+ * @default LogLevel.Verbose
23
25
  */
24
26
  protected getLogType: (lvl: LogLevel) => ConsoleLevel;
25
27
  }
@@ -1,4 +1,4 @@
1
- import { PopupRequest, RedirectRequest } from '@azure/msal-browser';
1
+ import type { PopupRequest, RedirectRequest } from '@azure/msal-browser';
2
2
  /**
3
3
  * Request object passed by user to retrieve a Code from the
4
4
  * server (first leg of authorization code grant flow).
@@ -1,7 +1,7 @@
1
1
  import z from 'zod';
2
2
  import { BaseConfigBuilder } from '@equinor/fusion-framework-module';
3
3
  import { MsalModuleVersion } from '../static';
4
- import { IAuthProvider } from './provider';
4
+ import type { IAuthProvider } from './provider';
5
5
  declare const AuthClientConfigSchema: z.ZodObject<{
6
6
  clientId: z.ZodString;
7
7
  tenantId: z.ZodString;
@@ -1,9 +1,13 @@
1
- import { AuthClient, AuthRequest } from './client';
2
- import { AuthClientConfig } from './configurator';
3
- import { AccountInfo, AuthenticationResult } from './types';
4
- import { IProxyProvider } from '../types';
1
+ import { type AuthClient, type AuthRequest } from './client';
2
+ import type { AuthClientConfig } from './configurator';
3
+ import type { AccountInfo, AuthenticationResult } from './types';
4
+ import type { IProxyProvider } from '../types';
5
5
  import { SemanticVersion } from '@equinor/fusion-framework-module';
6
6
  export interface IAuthProvider {
7
+ /**
8
+ * @deprecated
9
+ */
10
+ readonly defaultConfig: any | undefined;
7
11
  readonly defaultAccount: AccountInfo | undefined;
8
12
  /**
9
13
  * Acquire token from default auth client
@@ -1 +1 @@
1
- export declare const version = "4.0.0";
1
+ export declare const version = "4.0.2";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@equinor/fusion-framework-module-msal",
3
- "version": "4.0.0",
3
+ "version": "4.0.2",
4
4
  "description": "",
5
5
  "main": "dist/esm/index.js",
6
6
  "exports": {
@@ -37,10 +37,10 @@
37
37
  "@types/semver": "^7.5.0",
38
38
  "semver": "^7.5.4",
39
39
  "zod": "^3.23.8",
40
- "@equinor/fusion-framework-module": "^4.3.5"
40
+ "@equinor/fusion-framework-module": "^4.3.7"
41
41
  },
42
42
  "devDependencies": {
43
- "typescript": "^5.5.4"
43
+ "typescript": "^5.8.2"
44
44
  },
45
45
  "scripts": {
46
46
  "build": "tsc -b"
package/src/index.ts CHANGED
@@ -1,11 +1,11 @@
1
1
  export {
2
- module,
3
- configureMsal,
4
- enableMSAL,
5
- type AuthConfigurator as IAppConfigurator,
6
- type AuthConfigFn,
7
- type IAuthProvider,
8
- type MsalModule,
2
+ module,
3
+ configureMsal,
4
+ enableMSAL,
5
+ type AuthConfigurator as IAppConfigurator,
6
+ type AuthConfigFn,
7
+ type IAuthProvider,
8
+ type MsalModule,
9
9
  } from './module';
10
10
 
11
11
  export { MsalModuleVersion } from './static';
package/src/module.ts CHANGED
@@ -1,7 +1,7 @@
1
1
  import {
2
- type Module,
3
- type IModulesConfigurator,
4
- SemanticVersion,
2
+ type Module,
3
+ type IModulesConfigurator,
4
+ SemanticVersion,
5
5
  } from '@equinor/fusion-framework-module';
6
6
 
7
7
  import { MsalModuleVersion } from './static';
@@ -12,70 +12,70 @@ export type MsalModule = Module<'auth', IAuthProvider, AuthConfigurator, [MsalMo
12
12
  export type { AuthConfigurator, IAuthProvider };
13
13
 
14
14
  export const module: MsalModule = {
15
- name: 'auth',
16
- version: new SemanticVersion(MsalModuleVersion.Latest),
17
- configure: () => new AuthConfigurator(),
18
- initialize: async (init) => {
19
- const config = await init.config.createConfigAsync(init);
15
+ name: 'auth',
16
+ version: new SemanticVersion(MsalModuleVersion.Latest),
17
+ configure: () => new AuthConfigurator(),
18
+ initialize: async (init) => {
19
+ const config = await init.config.createConfigAsync(init);
20
20
 
21
- // configured to use a custom provider
22
- if (config.provider) {
23
- return config.provider;
24
- }
21
+ // configured to use a custom provider
22
+ if (config.provider) {
23
+ return config.provider;
24
+ }
25
25
 
26
- // check if the provider is defined in the parent module
27
- const hostProvider = init.ref?.auth as AuthProvider;
28
- if (hostProvider) {
29
- try {
30
- return hostProvider.createProxyProvider(config.version);
31
- } catch (error) {
32
- console.error('MsalModule::Failed to create proxy provider', error);
33
- // just to make sure during migration that the provider is not set
34
- return hostProvider;
35
- }
36
- }
26
+ // check if the provider is defined in the parent module
27
+ const hostProvider = init.ref?.auth as AuthProvider;
28
+ if (hostProvider) {
29
+ try {
30
+ return hostProvider.createProxyProvider(config.version);
31
+ } catch (error) {
32
+ console.error('MsalModule::Failed to create proxy provider', error);
33
+ // just to make sure during migration that the provider is not set
34
+ return hostProvider;
35
+ }
36
+ }
37
37
 
38
- if (!config.client) {
39
- throw new Error(
40
- 'Client configuration is required when provider is not in the parent module nor defined',
41
- );
42
- }
38
+ if (!config.client) {
39
+ throw new Error(
40
+ 'Client configuration is required when provider is not in the parent module nor defined',
41
+ );
42
+ }
43
43
 
44
- // create a new provider
45
- const authProvider = new AuthProvider(config.client);
44
+ // create a new provider
45
+ const authProvider = new AuthProvider(config.client);
46
46
 
47
- if (config.requiresAuth) {
48
- await authProvider.handleRedirect();
49
- await authProvider.login({ onlyIfRequired: true });
50
- }
47
+ if (config.requiresAuth) {
48
+ await authProvider.handleRedirect();
49
+ await authProvider.login({ onlyIfRequired: true });
50
+ }
51
51
 
52
- return authProvider;
53
- },
52
+ return authProvider;
53
+ },
54
54
  };
55
55
 
56
56
  export type AuthConfigFn = (builder: {
57
- setClientConfig: (config: AuthClientConfig) => void;
58
- setRequiresAuth: (requiresAuth: boolean) => void;
57
+ setClientConfig: (config: AuthClientConfig) => void;
58
+ setRequiresAuth: (requiresAuth: boolean) => void;
59
59
  }) => void;
60
60
 
61
61
  export const enableMSAL = (
62
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
63
- configurator: IModulesConfigurator<any, any>,
64
- configure?: AuthConfigFn,
62
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
63
+ configurator: IModulesConfigurator<any, any>,
64
+ configure?: AuthConfigFn,
65
65
  ): void => {
66
- const config = configure ? configureMsal(configure) : { module };
67
- configurator.addConfig(config);
66
+ const config = configure ? configureMsal(configure) : { module };
67
+ configurator.addConfig(config);
68
68
  };
69
69
 
70
70
  export const configureMsal = (configure: AuthConfigFn) => ({
71
- module,
72
- configure,
71
+ module,
72
+ configure,
73
73
  });
74
74
 
75
75
  declare module '@equinor/fusion-framework-module' {
76
- interface Modules {
77
- auth: MsalModule;
78
- }
76
+ interface Modules {
77
+ auth: MsalModule;
78
+ }
79
79
  }
80
80
 
81
81
  export default module;
@@ -3,41 +3,41 @@ import semver, { type SemVer } from 'semver';
3
3
  import { MsalModuleVersion } from './static';
4
4
 
5
5
  export function resolveVersion(version: string | SemVer): {
6
- wantedVersion: SemVer;
7
- latestVersion: SemVer;
8
- isLatest: boolean;
9
- satisfiesLatest: boolean;
10
- enumVersion: MsalModuleVersion;
6
+ wantedVersion: SemVer;
7
+ latestVersion: SemVer;
8
+ isLatest: boolean;
9
+ satisfiesLatest: boolean;
10
+ enumVersion: MsalModuleVersion;
11
11
  } {
12
- const wantedVersion = semver.coerce(version || MsalModuleVersion.Latest);
13
- const latestVersion = semver.coerce(MsalModuleVersion.Latest);
14
- // check if version is valid semver version
15
- if (!wantedVersion) {
16
- throw new Error(`Invalid version ${version} provided`);
17
- }
12
+ const wantedVersion = semver.coerce(version || MsalModuleVersion.Latest);
13
+ const latestVersion = semver.coerce(MsalModuleVersion.Latest);
14
+ // check if version is valid semver version
15
+ if (!wantedVersion) {
16
+ throw new Error(`Invalid version ${version} provided`);
17
+ }
18
18
 
19
- if (!latestVersion) {
20
- throw new Error('Invalid latest version');
21
- }
19
+ if (!latestVersion) {
20
+ throw new Error('Invalid latest version');
21
+ }
22
22
 
23
- // check if version is greater than latest
24
- if (semver.gt(wantedVersion, latestVersion!)) {
25
- throw new Error(
26
- `Requested version ${version} is greater than the latest version ${MsalModuleVersion.Latest}`,
27
- );
28
- }
23
+ // check if version is greater than latest
24
+ if (semver.gt(wantedVersion, latestVersion!)) {
25
+ throw new Error(
26
+ `Requested version ${version} is greater than the latest version ${MsalModuleVersion.Latest}`,
27
+ );
28
+ }
29
29
 
30
- const enumVersion = Object.values(MsalModuleVersion).find(
31
- (x) => semver.coerce(x)?.major === wantedVersion.major,
32
- ) as MsalModuleVersion;
30
+ const enumVersion = Object.values(MsalModuleVersion).find(
31
+ (x) => semver.coerce(x)?.major === wantedVersion.major,
32
+ ) as MsalModuleVersion;
33
33
 
34
- return {
35
- wantedVersion,
36
- latestVersion,
37
- enumVersion,
38
- isLatest: wantedVersion.compare(latestVersion) === 0,
39
- satisfiesLatest: wantedVersion.major === latestVersion.major,
40
- };
34
+ return {
35
+ wantedVersion,
36
+ latestVersion,
37
+ enumVersion,
38
+ isLatest: wantedVersion.compare(latestVersion) === 0,
39
+ satisfiesLatest: wantedVersion.major === latestVersion.major,
40
+ };
41
41
  }
42
42
 
43
43
  export default resolveVersion;
package/src/static.ts CHANGED
@@ -3,6 +3,6 @@ import { version } from './version';
3
3
  export const ModuleName = 'msal' as const;
4
4
 
5
5
  export enum MsalModuleVersion {
6
- V2 = 'v2',
7
- Latest = version,
6
+ V2 = 'v2',
7
+ Latest = version,
8
8
  }
package/src/types.ts CHANGED
@@ -1,8 +1,8 @@
1
- import { type SemVer } from 'semver';
2
- import { MsalModuleVersion } from './static';
1
+ import type { SemVer } from 'semver';
2
+ import type { MsalModuleVersion } from './static';
3
3
 
4
4
  // this should be defined the @equinor/fusion-framework-module package
5
5
  export interface IProxyProvider {
6
- version: string | SemVer;
7
- createProxyProvider<T>(version: MsalModuleVersion): T;
6
+ version: string | SemVer;
7
+ createProxyProvider<T>(version: MsalModuleVersion): T;
8
8
  }
@@ -1,23 +1,23 @@
1
1
  import {
2
- PublicClientApplication,
3
- Configuration,
4
- AuthenticationResult,
5
- SsoSilentRequest,
6
- PopupRequest,
7
- RedirectRequest,
8
- AccountInfo as AccountInfoBase,
2
+ PublicClientApplication,
3
+ type Configuration,
4
+ type AuthenticationResult,
5
+ type SsoSilentRequest,
6
+ type PopupRequest,
7
+ type RedirectRequest,
8
+ type AccountInfo as AccountInfoBase,
9
9
  } from '@azure/msal-browser';
10
10
 
11
- import { AuthBehavior, defaultBehavior } from './behavior';
12
- import { AuthRequest } from './request';
11
+ import { type AuthBehavior, defaultBehavior } from './behavior';
12
+ import type { AuthRequest } from './request';
13
13
 
14
14
  export type IdTokenClaims = {
15
- aud: string;
16
- exp: number;
15
+ aud: string;
16
+ exp: number;
17
17
  };
18
18
 
19
19
  export type AccountInfo = AccountInfoBase & {
20
- idTokenClaims?: IdTokenClaims;
20
+ idTokenClaims?: IdTokenClaims;
21
21
  };
22
22
 
23
23
  /**
@@ -52,133 +52,129 @@ export type AccountInfo = AccountInfoBase & {
52
52
  * @see [Microsoft identity platform](https://docs.microsoft.com/en-us/azure/active-directory/develop/v2-oauth2-auth-code-flow)
53
53
  */
54
54
  export class AuthClient extends PublicClientApplication {
55
- /**
56
- * @returns
57
- * Returns account for client tenant that MSAL currently has data for.
58
- * (the account object is created at the time of successful login)
59
- */
60
- get account(): AccountInfo | undefined {
61
- const accounts = this.getAllAccounts();
62
- const account = accounts.find(
63
- (a) => (a as AccountInfo).idTokenClaims?.aud === this.clientId,
64
- );
65
- return account as AccountInfo;
55
+ /**
56
+ * @returns
57
+ * Returns account for client tenant that MSAL currently has data for.
58
+ * (the account object is created at the time of successful login)
59
+ */
60
+ get account(): AccountInfo | undefined {
61
+ const accounts = this.getAllAccounts();
62
+ const account = accounts.find((a) => (a as AccountInfo).idTokenClaims?.aud === this.clientId);
63
+ return account as AccountInfo;
64
+ }
65
+
66
+ get hasValidClaims(): boolean {
67
+ const idTokenClaims = this.account?.idTokenClaims;
68
+ if (idTokenClaims) {
69
+ const epoch = Math.ceil(Date.now() / 1000);
70
+ return idTokenClaims.exp > epoch;
66
71
  }
67
-
68
- get hasValidClaims(): boolean {
69
- const idTokenClaims = this.account?.idTokenClaims;
70
- if (idTokenClaims) {
71
- const epoch = Math.ceil(Date.now() / 1000);
72
- return idTokenClaims.exp > epoch;
73
- }
74
- return false;
72
+ return false;
73
+ }
74
+
75
+ /**
76
+ * @returns - Configured client id
77
+ */
78
+ get clientId(): string | undefined {
79
+ return this.config.auth?.clientId;
80
+ }
81
+
82
+ get requestOrigin(): string | null {
83
+ return this.browserStorage.getTemporaryCache('request.origin', true);
84
+ }
85
+
86
+ /**
87
+ * @param tenantId - tenant id for client domain
88
+ * @param config - required [Configuration](https://github.com/AzureAD/microsoft-authentication-library-for-js/blob/dev/lib/msal-browser/src/config/Configuration.ts)
89
+ */
90
+ constructor(
91
+ readonly tenantId: string,
92
+ config: Configuration,
93
+ ) {
94
+ super(config);
95
+ }
96
+
97
+ /**
98
+ * @param silent
99
+ * Attempt to use a hidden iframe to fetch an authorization code from the eSTS if {@link AuthClient.account} or login hint.
100
+ * Provided {@link AuthBehavior} is used as fallback.
101
+ * There are cases where this may not work:
102
+ * - Any browser using a form of Intelligent Tracking Prevention
103
+ * - If there is not an established session with the service
104
+ *
105
+ * @returns
106
+ * Promise that is fulfilled when this function has completed, or rejected if an error was raised.
107
+ */
108
+ async login(
109
+ options?: AuthRequest,
110
+ behavior: AuthBehavior = defaultBehavior,
111
+ silent = true,
112
+ ): Promise<AuthenticationResult | void> {
113
+ const loginHint = options?.loginHint || this.account?.username;
114
+ const scopes = options?.scopes || [];
115
+ const request = { ...options, loginHint, scopes };
116
+
117
+ if (loginHint && silent) {
118
+ this.logger.verbose('Attempting to login in silently');
119
+ try {
120
+ const res = await this.ssoSilent(request as SsoSilentRequest);
121
+ return res;
122
+ } catch {
123
+ this.logger.verbose('Silent login attempt failed');
124
+ }
75
125
  }
76
126
 
77
- /**
78
- * @returns - Configured client id
79
- */
80
- get clientId(): string | undefined {
81
- return this.config.auth?.clientId;
82
- }
127
+ this.logger.verbose(`Attempting to login in by [${behavior}]`);
83
128
 
84
- get requestOrigin(): string | null {
85
- return this.browserStorage.getTemporaryCache('request.origin', true);
129
+ switch (behavior) {
130
+ case 'popup':
131
+ return this.loginPopup(request as PopupRequest);
132
+ case 'redirect': {
133
+ return this.loginRedirect(request as RedirectRequest);
134
+ }
86
135
  }
87
-
88
- /**
89
- * @param tenantId - tenant id for client domain
90
- * @param config - required [Configuration](https://github.com/AzureAD/microsoft-authentication-library-for-js/blob/dev/lib/msal-browser/src/config/Configuration.ts)
91
- */
92
- constructor(
93
- readonly tenantId: string,
94
- config: Configuration,
95
- ) {
96
- super(config);
136
+ }
137
+
138
+ /**
139
+ * Will try to silently acquire an access token for a given set of scopes.
140
+ * Will use cached token if available, otherwise will attempt to acquire a new token from the network via refresh token.
141
+ *
142
+ * @param silent
143
+ * Attempt to use a hidden iframe to fetch an authorization code from the eSTS if {@link AuthClient.account} or login hint.
144
+ * Provided {@link AuthBehavior} is used as fallback.
145
+ * There are cases where this may not work:
146
+ * - Any browser using a form of Intelligent Tracking Prevention
147
+ * - If there is not an established session with the service
148
+ *
149
+ * @returns
150
+ * Promise that is fulfilled when this function has completed, or rejected if an error was raised.
151
+ */
152
+ public async acquireToken(
153
+ options: AuthRequest = { scopes: [] },
154
+ behavior: AuthBehavior = defaultBehavior,
155
+ silent = true,
156
+ ): Promise<AuthenticationResult | void> {
157
+ const account = await this.account;
158
+ if (silent && account) {
159
+ this.logger.verbose('Attempting to acquire token in silently');
160
+ try {
161
+ const token = await this.acquireTokenSilent({ account, ...options });
162
+ return token;
163
+ } catch (err) {
164
+ this.logger.info('Expected to navigate away from the current page but timeout occurred.');
165
+ }
97
166
  }
98
167
 
99
- /**
100
- * @param silent
101
- * Attempt to use a hidden iframe to fetch an authorization code from the eSTS if {@link AuthClient.account} or login hint.
102
- * Provided {@link AuthBehavior} is used as fallback.
103
- * There are cases where this may not work:
104
- * - Any browser using a form of Intelligent Tracking Prevention
105
- * - If there is not an established session with the service
106
- *
107
- * @returns
108
- * Promise that is fulfilled when this function has completed, or rejected if an error was raised.
109
- */
110
- async login(
111
- options?: AuthRequest,
112
- behavior: AuthBehavior = defaultBehavior,
113
- silent = true,
114
- ): Promise<AuthenticationResult | void> {
115
- const loginHint = options?.loginHint || this.account?.username;
116
- const scopes = options?.scopes || [];
117
- const request = { ...options, loginHint, scopes };
118
-
119
- if (loginHint && silent) {
120
- this.logger.verbose('Attempting to login in silently');
121
- try {
122
- const res = await this.ssoSilent(request as SsoSilentRequest);
123
- return res;
124
- } catch {
125
- this.logger.verbose('Silent login attempt failed');
126
- }
127
- }
128
-
129
- this.logger.verbose(`Attempting to login in by [${behavior}]`);
130
-
131
- switch (behavior) {
132
- case 'popup':
133
- return this.loginPopup(request as PopupRequest);
134
- case 'redirect': {
135
- return this.loginRedirect(request as RedirectRequest);
136
- }
137
- }
138
- }
168
+ this.logger.verbose(`Attempting to acquire token by [${behavior}]`);
139
169
 
140
- /**
141
- * Will try to silently acquire an access token for a given set of scopes.
142
- * Will use cached token if available, otherwise will attempt to acquire a new token from the network via refresh token.
143
- *
144
- * @param silent
145
- * Attempt to use a hidden iframe to fetch an authorization code from the eSTS if {@link AuthClient.account} or login hint.
146
- * Provided {@link AuthBehavior} is used as fallback.
147
- * There are cases where this may not work:
148
- * - Any browser using a form of Intelligent Tracking Prevention
149
- * - If there is not an established session with the service
150
- *
151
- * @returns
152
- * Promise that is fulfilled when this function has completed, or rejected if an error was raised.
153
- */
154
- public async acquireToken(
155
- options: AuthRequest = { scopes: [] },
156
- behavior: AuthBehavior = defaultBehavior,
157
- silent = true,
158
- ): Promise<AuthenticationResult | void> {
159
- const account = await this.account;
160
- if (silent && account) {
161
- this.logger.verbose('Attempting to acquire token in silently');
162
- try {
163
- const token = await this.acquireTokenSilent({ account, ...options });
164
- return token;
165
- } catch (err) {
166
- this.logger.info(
167
- 'Expected to navigate away from the current page but timeout occurred.',
168
- );
169
- }
170
- }
171
-
172
- this.logger.verbose(`Attempting to acquire token by [${behavior}]`);
173
-
174
- switch (behavior) {
175
- case 'popup':
176
- return this.acquireTokenPopup(options);
177
- case 'redirect': {
178
- return this.acquireTokenRedirect(options);
179
- }
180
- }
170
+ switch (behavior) {
171
+ case 'popup':
172
+ return this.acquireTokenPopup(options);
173
+ case 'redirect': {
174
+ return this.acquireTokenRedirect(options);
175
+ }
181
176
  }
177
+ }
182
178
  }
183
179
 
184
180
  export default AuthClient;