@equinor/fusion-framework-module-msal 5.1.2 → 6.0.0-next.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/CHANGELOG.md +98 -0
- package/README.md +237 -40
- package/dist/esm/MsalClient.interface.js +2 -0
- package/dist/esm/MsalClient.interface.js.map +1 -0
- package/dist/esm/MsalClient.js +215 -0
- package/dist/esm/MsalClient.js.map +1 -0
- package/dist/esm/MsalConfigurator.js +248 -0
- package/dist/esm/MsalConfigurator.js.map +1 -0
- package/dist/esm/MsalProvider.interface.js +2 -0
- package/dist/esm/MsalProvider.interface.js.map +1 -0
- package/dist/esm/MsalProvider.js +525 -0
- package/dist/esm/MsalProvider.js.map +1 -0
- package/dist/esm/MsalProxyProvider.interface.js +2 -0
- package/dist/esm/MsalProxyProvider.interface.js.map +1 -0
- package/dist/esm/__tests__/versioning/resolve-version.test.js +29 -38
- package/dist/esm/__tests__/versioning/resolve-version.test.js.map +1 -1
- package/dist/esm/create-client-log-callback.js +87 -0
- package/dist/esm/create-client-log-callback.js.map +1 -0
- package/dist/esm/create-proxy-provider.js +84 -0
- package/dist/esm/create-proxy-provider.js.map +1 -0
- package/dist/esm/index.js +1 -1
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/module.js +64 -16
- package/dist/esm/module.js.map +1 -1
- package/dist/esm/static.js +32 -2
- package/dist/esm/static.js.map +1 -1
- package/dist/esm/types.js +9 -0
- package/dist/esm/types.js.map +1 -1
- package/dist/esm/util/compare-origin.js +11 -0
- package/dist/esm/util/compare-origin.js.map +1 -0
- package/dist/esm/{v2/client/util/url.js → util/normalize-uri.js} +1 -10
- package/dist/esm/util/normalize-uri.js.map +1 -0
- package/dist/esm/{v2/client/util/browser.js → util/redirect.js} +1 -1
- package/dist/esm/util/redirect.js.map +1 -0
- package/dist/esm/v2/IAuthClient.interface.js +2 -0
- package/dist/esm/v2/IAuthClient.interface.js.map +1 -0
- package/dist/esm/v2/IPublicClientApplication.interface.js +2 -0
- package/dist/esm/v2/IPublicClientApplication.interface.js.map +1 -0
- package/dist/esm/v2/MsalProvider.interface.js +2 -0
- package/dist/esm/v2/MsalProvider.interface.js.map +1 -0
- package/dist/esm/v2/create-proxy-client.js +155 -0
- package/dist/esm/v2/create-proxy-client.js.map +1 -0
- package/dist/esm/v2/create-proxy-provider.js +140 -0
- package/dist/esm/v2/create-proxy-provider.js.map +1 -0
- package/dist/esm/v2/map-account-info.js +18 -0
- package/dist/esm/v2/map-account-info.js.map +1 -0
- package/dist/esm/v2/map-authentication-result.js +22 -0
- package/dist/esm/v2/map-authentication-result.js.map +1 -0
- package/dist/esm/version.js +1 -1
- package/dist/esm/version.js.map +1 -1
- package/dist/esm/versioning/resolve-version.js +28 -16
- package/dist/esm/versioning/resolve-version.js.map +1 -1
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/dist/types/MsalClient.d.ts +141 -0
- package/dist/types/MsalClient.interface.d.ts +103 -0
- package/dist/types/MsalConfigurator.d.ts +147 -0
- package/dist/types/MsalProvider.d.ts +291 -0
- package/dist/types/MsalProvider.interface.d.ts +159 -0
- package/dist/types/MsalProxyProvider.interface.d.ts +52 -0
- package/dist/types/create-client-log-callback.d.ts +38 -0
- package/dist/types/create-proxy-provider.d.ts +19 -0
- package/dist/types/index.d.ts +5 -4
- package/dist/types/module.d.ts +70 -4
- package/dist/types/static.d.ts +32 -1
- package/dist/types/types.d.ts +14 -6
- package/dist/types/util/redirect.d.ts +1 -0
- package/dist/types/v2/IAuthClient.interface.d.ts +68 -0
- package/dist/types/v2/IPublicClientApplication.interface.d.ts +68 -0
- package/dist/types/v2/MsalProvider.interface.d.ts +85 -0
- package/dist/types/v2/create-proxy-client.d.ts +22 -0
- package/dist/types/v2/create-proxy-provider.d.ts +24 -0
- package/dist/types/v2/map-account-info.d.ts +9 -0
- package/dist/types/v2/map-authentication-result.d.ts +9 -0
- package/dist/types/v2/types.d.ts +12 -0
- package/dist/types/version.d.ts +1 -1
- package/dist/types/versioning/resolve-version.d.ts +1 -1
- package/package.json +11 -6
- package/src/MsalClient.interface.ts +121 -0
- package/src/MsalClient.ts +274 -0
- package/src/MsalConfigurator.ts +289 -0
- package/src/MsalProvider.interface.ts +175 -0
- package/src/MsalProvider.ts +597 -0
- package/src/MsalProxyProvider.interface.ts +71 -0
- package/src/__tests__/versioning/resolve-version.test.ts +29 -42
- package/src/create-client-log-callback.ts +101 -0
- package/src/create-proxy-provider.ts +89 -0
- package/src/index.ts +6 -7
- package/src/module.ts +88 -20
- package/src/static.ts +32 -3
- package/src/types.ts +15 -7
- package/src/util/compare-origin.ts +11 -0
- package/src/{v2/client/util/url.ts → util/normalize-uri.ts} +0 -10
- package/src/v2/IAuthClient.interface.ts +91 -0
- package/src/v2/IPublicClientApplication.interface.ts +71 -0
- package/src/v2/MsalProvider.interface.ts +92 -0
- package/src/v2/create-proxy-client.ts +186 -0
- package/src/v2/create-proxy-provider.ts +156 -0
- package/src/v2/map-account-info.ts +20 -0
- package/src/v2/map-authentication-result.ts +24 -0
- package/src/v2/types.ts +12 -0
- package/src/version.ts +1 -1
- package/src/versioning/resolve-version.ts +35 -28
- package/tsconfig.json +3 -0
- package/dist/esm/v2/client/behavior.js +0 -5
- package/dist/esm/v2/client/behavior.js.map +0 -1
- package/dist/esm/v2/client/client.js +0 -142
- package/dist/esm/v2/client/client.js.map +0 -1
- package/dist/esm/v2/client/create-auth-client.js +0 -36
- package/dist/esm/v2/client/create-auth-client.js.map +0 -1
- package/dist/esm/v2/client/index.js +0 -5
- package/dist/esm/v2/client/index.js.map +0 -1
- package/dist/esm/v2/client/log/console.js +0 -45
- package/dist/esm/v2/client/log/console.js.map +0 -1
- package/dist/esm/v2/client/request.js +0 -2
- package/dist/esm/v2/client/request.js.map +0 -1
- package/dist/esm/v2/client/util/browser.js.map +0 -1
- package/dist/esm/v2/client/util/url.js.map +0 -1
- package/dist/esm/v2/configurator.js +0 -42
- package/dist/esm/v2/configurator.js.map +0 -1
- package/dist/esm/v2/index.js +0 -3
- package/dist/esm/v2/index.js.map +0 -1
- package/dist/esm/v2/provider.js +0 -115
- package/dist/esm/v2/provider.js.map +0 -1
- package/dist/types/v2/client/behavior.d.ts +0 -13
- package/dist/types/v2/client/client.d.ts +0 -89
- package/dist/types/v2/client/create-auth-client.d.ts +0 -27
- package/dist/types/v2/client/index.d.ts +0 -5
- package/dist/types/v2/client/log/console.d.ts +0 -28
- package/dist/types/v2/client/request.d.ts +0 -65
- package/dist/types/v2/configurator.d.ts +0 -32
- package/dist/types/v2/index.d.ts +0 -2
- package/dist/types/v2/provider.d.ts +0 -59
- package/src/v2/client/behavior.ts +0 -14
- package/src/v2/client/client.ts +0 -180
- package/src/v2/client/create-auth-client.ts +0 -48
- package/src/v2/client/index.ts +0 -8
- package/src/v2/client/log/console.ts +0 -58
- package/src/v2/client/request.ts +0 -66
- package/src/v2/configurator.ts +0 -58
- package/src/v2/index.ts +0 -2
- package/src/v2/provider.ts +0 -178
- /package/dist/types/{v2/client/util/browser.d.ts → util/compare-origin.d.ts} +0 -0
- /package/dist/types/{v2/client/util/url.d.ts → util/normalize-uri.d.ts} +0 -0
- /package/src/{v2/client/util/browser.ts → util/redirect.ts} +0 -0
|
@@ -1,89 +0,0 @@
|
|
|
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
|
-
export type IdTokenClaims = {
|
|
5
|
-
aud: string;
|
|
6
|
-
exp: number;
|
|
7
|
-
};
|
|
8
|
-
export type AccountInfo = AccountInfoBase & {
|
|
9
|
-
idTokenClaims?: IdTokenClaims;
|
|
10
|
-
};
|
|
11
|
-
/**
|
|
12
|
-
* ### Simple extension of Microsoft`s authentication client.
|
|
13
|
-
*
|
|
14
|
-
* When using this client tenant is **required** since common login is deprecated after all.
|
|
15
|
-
* By providing tenant the user account can simple be extracted from current session *if any*.
|
|
16
|
-
*
|
|
17
|
-
* @example
|
|
18
|
-
* ```typescript
|
|
19
|
-
* const tenantId = '224123a0d-7990-4ba1-aff3-1dss9569af32';
|
|
20
|
-
* const authPath = '/my-app/auth';
|
|
21
|
-
* const client = new AuthClient(tenantId, {
|
|
22
|
-
* auth: {
|
|
23
|
-
* clientId: '6dab35d4-59ff-4dcc-3356-24479e6fc888',
|
|
24
|
-
* authority: `https://login.microsoftonline.com/${tenantId}`,
|
|
25
|
-
* redirectUri: window.location.origin + '/my-app/auth'
|
|
26
|
-
* }
|
|
27
|
-
* });
|
|
28
|
-
* document.getElementById('login-btn').addEventListener('click', () =>
|
|
29
|
-
* client.login({ scopes: ['data.read'] })
|
|
30
|
-
* .then(console.log)
|
|
31
|
-
* .catch(console.error)
|
|
32
|
-
* );
|
|
33
|
-
* (async() => {
|
|
34
|
-
* if(window.location.path === authPath) {
|
|
35
|
-
* await client.handleRedirectPromise()
|
|
36
|
-
* }
|
|
37
|
-
* )();
|
|
38
|
-
* ```
|
|
39
|
-
* @see [Microsoft Authentication Library](https://github.com/AzureAD/microsoft-authentication-library-for-js)
|
|
40
|
-
* @see [Microsoft identity platform](https://docs.microsoft.com/en-us/azure/active-directory/develop/v2-oauth2-auth-code-flow)
|
|
41
|
-
*/
|
|
42
|
-
export declare class AuthClient extends PublicClientApplication {
|
|
43
|
-
readonly tenantId: string;
|
|
44
|
-
/**
|
|
45
|
-
* @returns
|
|
46
|
-
* Returns account for client tenant that MSAL currently has data for.
|
|
47
|
-
* (the account object is created at the time of successful login)
|
|
48
|
-
*/
|
|
49
|
-
get account(): AccountInfo | undefined;
|
|
50
|
-
get hasValidClaims(): boolean;
|
|
51
|
-
/**
|
|
52
|
-
* @returns - Configured client id
|
|
53
|
-
*/
|
|
54
|
-
get clientId(): string | undefined;
|
|
55
|
-
get requestOrigin(): string | null;
|
|
56
|
-
/**
|
|
57
|
-
* @param tenantId - tenant id for client domain
|
|
58
|
-
* @param config - required [Configuration](https://github.com/AzureAD/microsoft-authentication-library-for-js/blob/dev/lib/msal-browser/src/config/Configuration.ts)
|
|
59
|
-
*/
|
|
60
|
-
constructor(tenantId: string, config: Configuration);
|
|
61
|
-
/**
|
|
62
|
-
* @param silent
|
|
63
|
-
* Attempt to use a hidden iframe to fetch an authorization code from the eSTS if {@link AuthClient.account} or login hint.
|
|
64
|
-
* Provided {@link AuthBehavior} is used as fallback.
|
|
65
|
-
* There are cases where this may not work:
|
|
66
|
-
* - Any browser using a form of Intelligent Tracking Prevention
|
|
67
|
-
* - If there is not an established session with the service
|
|
68
|
-
*
|
|
69
|
-
* @returns
|
|
70
|
-
* Promise that is fulfilled when this function has completed, or rejected if an error was raised.
|
|
71
|
-
*/
|
|
72
|
-
login(options?: AuthRequest, behavior?: AuthBehavior, silent?: boolean): Promise<AuthenticationResult | void>;
|
|
73
|
-
/**
|
|
74
|
-
* Will try to silently acquire an access token for a given set of scopes.
|
|
75
|
-
* Will use cached token if available, otherwise will attempt to acquire a new token from the network via refresh token.
|
|
76
|
-
*
|
|
77
|
-
* @param silent
|
|
78
|
-
* Attempt to use a hidden iframe to fetch an authorization code from the eSTS if {@link AuthClient.account} or login hint.
|
|
79
|
-
* Provided {@link AuthBehavior} is used as fallback.
|
|
80
|
-
* There are cases where this may not work:
|
|
81
|
-
* - Any browser using a form of Intelligent Tracking Prevention
|
|
82
|
-
* - If there is not an established session with the service
|
|
83
|
-
*
|
|
84
|
-
* @returns
|
|
85
|
-
* Promise that is fulfilled when this function has completed, or rejected if an error was raised.
|
|
86
|
-
*/
|
|
87
|
-
acquireToken(options?: AuthRequest, behavior?: AuthBehavior, silent?: boolean): Promise<AuthenticationResult | void>;
|
|
88
|
-
}
|
|
89
|
-
export default AuthClient;
|
|
@@ -1,27 +0,0 @@
|
|
|
1
|
-
import type { Configuration, IPublicClientApplication } from '@azure/msal-browser';
|
|
2
|
-
import { AuthClient } from './client';
|
|
3
|
-
export type AuthClientConfig = Configuration & {
|
|
4
|
-
auth: Partial<Configuration['auth']>;
|
|
5
|
-
};
|
|
6
|
-
/**
|
|
7
|
-
* Creates an authentication client with basic config.
|
|
8
|
-
*
|
|
9
|
-
* @example
|
|
10
|
-
* ```typescript
|
|
11
|
-
* const myClient = createClient(
|
|
12
|
-
* '224123a0d-7990-4ba1-aff3-1dss9569af32',
|
|
13
|
-
* '6dab35d4-59ff-4dcc-3356-24479e6fc888',
|
|
14
|
-
* '/my-app/auth'
|
|
15
|
-
* );
|
|
16
|
-
* ```
|
|
17
|
-
*
|
|
18
|
-
* @template T - client type, default to {@link AuthClient}
|
|
19
|
-
*
|
|
20
|
-
* @param tenantId - tenant to for authentication
|
|
21
|
-
* @param clientId - client id for authentication
|
|
22
|
-
* @param redirectUri - callback url for authentication (must match exact configured url in app)
|
|
23
|
-
* @param config - optional [Configuration](https://github.com/AzureAD/microsoft-authentication-library-for-js/blob/dev/lib/msal-browser/src/config/Configuration.ts)
|
|
24
|
-
* @param ctor - optional client class
|
|
25
|
-
*/
|
|
26
|
-
export declare const createAuthClient: <T extends IPublicClientApplication = AuthClient>(tenantId: string, clientId: string, redirectUri?: string, config?: AuthClientConfig, ctor?: new (tenantId: string, config: Configuration) => T) => T;
|
|
27
|
-
export default createAuthClient;
|
|
@@ -1,28 +0,0 @@
|
|
|
1
|
-
import { Logger, LogLevel } from '@azure/msal-browser';
|
|
2
|
-
/**
|
|
3
|
-
* Logger functions of {@link Console}
|
|
4
|
-
*/
|
|
5
|
-
type ConsoleLevel = 'error' | 'warn' | 'info' | 'debug';
|
|
6
|
-
/**
|
|
7
|
-
* MSAL client logger for development, production should use telemetry
|
|
8
|
-
*
|
|
9
|
-
* @example
|
|
10
|
-
* ```typescript
|
|
11
|
-
* client.setLogger(new ConsoleLogger());
|
|
12
|
-
* ```
|
|
13
|
-
*/
|
|
14
|
-
export declare class ConsoleLogger extends Logger {
|
|
15
|
-
/**
|
|
16
|
-
* @param logLevel - 0-1-2-3 (error-warning-info-debug) if not provided all records logged
|
|
17
|
-
*/
|
|
18
|
-
constructor(logLevel?: LogLevel);
|
|
19
|
-
/** @inheritdoc */
|
|
20
|
-
protected loggerCallback(lvl: LogLevel, msg: string, _containsPii?: boolean): void;
|
|
21
|
-
/**
|
|
22
|
-
* Map log level to console log function type
|
|
23
|
-
*
|
|
24
|
-
* @default LogLevel.Verbose
|
|
25
|
-
*/
|
|
26
|
-
protected getLogType: (lvl: LogLevel) => ConsoleLevel;
|
|
27
|
-
}
|
|
28
|
-
export default ConsoleLogger;
|
|
@@ -1,65 +0,0 @@
|
|
|
1
|
-
import type { PopupRequest, RedirectRequest } from '@azure/msal-browser';
|
|
2
|
-
/**
|
|
3
|
-
* Request object passed by user to retrieve a Code from the
|
|
4
|
-
* server (first leg of authorization code grant flow).
|
|
5
|
-
*
|
|
6
|
-
* **scopes**\
|
|
7
|
-
* Array of scopes the application is requesting access to.
|
|
8
|
-
*
|
|
9
|
-
* **authority**\
|
|
10
|
-
* Url of the authority which the application acquires tokens from.
|
|
11
|
-
*
|
|
12
|
-
* **correlationId**\
|
|
13
|
-
* Unique GUID set per request to trace a request end-to-end for telemetry purposes.
|
|
14
|
-
*
|
|
15
|
-
* **redirectUri**\
|
|
16
|
-
* The redirect URI where authentication responses can be received by your application. It must exactly match one of the redirect URIs registered in the Azure portal.
|
|
17
|
-
*
|
|
18
|
-
* **extraScopesToConsent**\
|
|
19
|
-
* Scopes for a different resource when the user needs consent upfront.
|
|
20
|
-
*
|
|
21
|
-
* **responseMode**\
|
|
22
|
-
* Specifies the method that should be used to send the authentication result to your app. Fragment is the only valid option for msal-browser.
|
|
23
|
-
*
|
|
24
|
-
* **codeChallenge**\
|
|
25
|
-
* Used to secure authorization code grant via Proof of Key for Code Exchange (PKCE). For more information, see the PKCE RCF:https://tools.ietf.org/html/rfc7636
|
|
26
|
-
*
|
|
27
|
-
* **codeChallengeMethod**\
|
|
28
|
-
* The method used to encode the code verifier for the code challenge parameter. Can be "plain" or "S256". If excluded, code challenge is assumed to be plaintext. For more information, see the PKCE RCF: https://tools.ietf.org/html/rfc7636
|
|
29
|
-
*
|
|
30
|
-
* **state**\
|
|
31
|
-
* A value included in the request that is also returned in the token response. A randomly generated unique value is typically used for preventing cross site request forgery attacks. The state is also used to encode information about the user's state in the app before the authentication request occurred.
|
|
32
|
-
*
|
|
33
|
-
* **prompt**\
|
|
34
|
-
* Indicates the type of user interaction that is required.
|
|
35
|
-
* - login: will force the user to enter their credentials on that request, negating single-sign on
|
|
36
|
-
* - none: will ensure that the user isn't presented with any interactive prompt. if request can't be completed via single-sign on, the endpoint will return an interaction_required error
|
|
37
|
-
* - consent: will the trigger the OAuth consent dialog after the user signs in, asking the user to grant permissions to the app
|
|
38
|
-
* - select_account: will interrupt single sign-=on providing account selection experience listing all the accounts in session or any remembered accounts or an option to choose to use a different account
|
|
39
|
-
*
|
|
40
|
-
* **loginHint**\
|
|
41
|
-
* Can be used to pre-fill the username/email address field of the sign-in page for the user, if you know the username/email address ahead of time. Often apps use this parameter during re-authentication, having already extracted the username from a previous sign-in using the preferred_username claim.
|
|
42
|
-
*
|
|
43
|
-
* **sid**\
|
|
44
|
-
* Session ID, unique identifier for the session. Available as an optional claim on ID tokens.
|
|
45
|
-
*
|
|
46
|
-
* **domainHint**\
|
|
47
|
-
* Provides a hint about the tenant or domain that the user should use to sign in. The value of the domain hint is a registered domain for the tenant.
|
|
48
|
-
*
|
|
49
|
-
* **extraQueryParameters**\
|
|
50
|
-
* String to string map of custom query parameters.
|
|
51
|
-
*
|
|
52
|
-
* **claims**\
|
|
53
|
-
* In cases where Azure AD tenant admin has enabled conditional access policies, and the policy has not been met, exceptions will contain claims that need to be consented to.
|
|
54
|
-
*
|
|
55
|
-
* **nonce**\
|
|
56
|
-
* A value included in the request that is returned in the id token. A randomly generated unique value is typically used to mitigate replay attacks.
|
|
57
|
-
*
|
|
58
|
-
* **redirectStartPage**\
|
|
59
|
-
* The page that should be returned to after loginRedirect or acquireTokenRedirect.
|
|
60
|
-
* This should only be used if this is different from the redirectUri and will default to the page that initiates the request.
|
|
61
|
-
* When the navigateToLoginRequestUrl config option is set to false this parameter will be ignored.
|
|
62
|
-
*
|
|
63
|
-
* @see [microsoft-authentication-library-for-js](https://github.com/AzureAD/microsoft-authentication-library-for-js/tree/dev/lib/msal-browser/src/request)
|
|
64
|
-
*/
|
|
65
|
-
export type AuthRequest = PopupRequest | RedirectRequest;
|
|
@@ -1,32 +0,0 @@
|
|
|
1
|
-
import z from 'zod';
|
|
2
|
-
import { BaseConfigBuilder } from '@equinor/fusion-framework-module';
|
|
3
|
-
import { MsalModuleVersion } from '../static';
|
|
4
|
-
import type { IAuthProvider } from './provider';
|
|
5
|
-
declare const AuthClientConfigSchema: z.ZodObject<{
|
|
6
|
-
clientId: z.ZodString;
|
|
7
|
-
tenantId: z.ZodString;
|
|
8
|
-
redirectUri: z.ZodOptional<z.ZodString>;
|
|
9
|
-
}, z.core.$strip>;
|
|
10
|
-
declare const AuthClientSchema: z.ZodCustom<IAuthProvider, IAuthProvider>;
|
|
11
|
-
declare const AuthConfigSchema: z.ZodObject<{
|
|
12
|
-
client: z.ZodOptional<z.ZodObject<{
|
|
13
|
-
clientId: z.ZodString;
|
|
14
|
-
tenantId: z.ZodString;
|
|
15
|
-
redirectUri: z.ZodOptional<z.ZodString>;
|
|
16
|
-
}, z.core.$strip>>;
|
|
17
|
-
provider: z.ZodOptional<z.ZodCustom<IAuthProvider, IAuthProvider>>;
|
|
18
|
-
requiresAuth: z.ZodOptional<z.ZodBoolean>;
|
|
19
|
-
version: z.ZodPipe<z.ZodString, z.ZodTransform<string, string>>;
|
|
20
|
-
}, z.core.$strip>;
|
|
21
|
-
export type AuthClientConfig = z.infer<typeof AuthClientConfigSchema>;
|
|
22
|
-
export type AuthConfig = z.infer<typeof AuthConfigSchema>;
|
|
23
|
-
export declare class AuthConfigurator extends BaseConfigBuilder<AuthConfig> {
|
|
24
|
-
version: MsalModuleVersion.Latest;
|
|
25
|
-
constructor();
|
|
26
|
-
setClientConfig(config?: z.infer<typeof AuthClientConfigSchema>): void;
|
|
27
|
-
setRequiresAuth(requiresAuth: boolean): void;
|
|
28
|
-
setProvider(provider?: z.infer<typeof AuthClientSchema>): void;
|
|
29
|
-
setVersion(version: string): void;
|
|
30
|
-
_processConfig(config: AuthConfig): Promise<AuthConfig>;
|
|
31
|
-
}
|
|
32
|
-
export {};
|
package/dist/types/v2/index.d.ts
DELETED
|
@@ -1,59 +0,0 @@
|
|
|
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
|
-
import { BaseModuleProvider } from '@equinor/fusion-framework-module/provider';
|
|
6
|
-
export interface IAuthProvider {
|
|
7
|
-
/**
|
|
8
|
-
* @deprecated
|
|
9
|
-
*/
|
|
10
|
-
readonly defaultConfig: any | undefined;
|
|
11
|
-
readonly defaultAccount: AccountInfo | undefined;
|
|
12
|
-
readonly client: AuthClient;
|
|
13
|
-
/**
|
|
14
|
-
* Acquire token from default auth client
|
|
15
|
-
* @param req Auth request options
|
|
16
|
-
*/
|
|
17
|
-
acquireToken(req: AuthRequest): Promise<AuthenticationResult | void>;
|
|
18
|
-
/**
|
|
19
|
-
* Acquire access token from default auth client
|
|
20
|
-
* @param req Auth request options
|
|
21
|
-
*/
|
|
22
|
-
acquireAccessToken(req: AuthRequest): Promise<string | undefined>;
|
|
23
|
-
/**
|
|
24
|
-
* Login to default auth client
|
|
25
|
-
*/
|
|
26
|
-
login(): Promise<void>;
|
|
27
|
-
/**
|
|
28
|
-
* Logout
|
|
29
|
-
*/
|
|
30
|
-
logout(options?: {
|
|
31
|
-
redirectUri?: string;
|
|
32
|
-
}): Promise<void>;
|
|
33
|
-
/**
|
|
34
|
-
* Handle default client redirect callback
|
|
35
|
-
*/
|
|
36
|
-
handleRedirect(): Promise<void | null>;
|
|
37
|
-
}
|
|
38
|
-
export declare class AuthProvider extends BaseModuleProvider<AuthClientConfig> implements IAuthProvider, IProxyProvider {
|
|
39
|
-
#private;
|
|
40
|
-
protected _config: AuthClientConfig;
|
|
41
|
-
get defaultAccount(): AccountInfo | undefined;
|
|
42
|
-
/** @deprecated */
|
|
43
|
-
get defaultConfig(): AuthClientConfig | undefined;
|
|
44
|
-
constructor(_config: AuthClientConfig);
|
|
45
|
-
get client(): AuthClient;
|
|
46
|
-
/** @deprecated */
|
|
47
|
-
createClient(): AuthClient;
|
|
48
|
-
handleRedirect(): Promise<null>;
|
|
49
|
-
acquireToken(req: AuthRequest): ReturnType<IAuthProvider['acquireToken']>;
|
|
50
|
-
acquireAccessToken(req: AuthRequest): Promise<string | undefined>;
|
|
51
|
-
login(options?: {
|
|
52
|
-
onlyIfRequired?: boolean;
|
|
53
|
-
}): Promise<void>;
|
|
54
|
-
logout(options?: {
|
|
55
|
-
redirectUri?: string;
|
|
56
|
-
}): Promise<void>;
|
|
57
|
-
createProxyProvider<T = IAuthProvider>(version: string): T;
|
|
58
|
-
_createProxyProvider_v2(): IAuthProvider;
|
|
59
|
-
}
|
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* - **Popup:**
|
|
3
|
-
* Use when initiating the process via opening a popup window in the user's browser
|
|
4
|
-
*
|
|
5
|
-
* - **Redirect:**
|
|
6
|
-
* Use when initiating the login process by redirecting the user's browser to the authorization endpoint.
|
|
7
|
-
* This function redirects the page, so any code that follows this function will not execute.
|
|
8
|
-
*/
|
|
9
|
-
export type AuthBehavior = 'popup' | 'redirect';
|
|
10
|
-
|
|
11
|
-
/**
|
|
12
|
-
* Default behavior for login and acquisition of token
|
|
13
|
-
*/
|
|
14
|
-
export const defaultBehavior: AuthBehavior = 'redirect';
|
package/src/v2/client/client.ts
DELETED
|
@@ -1,180 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
PublicClientApplication,
|
|
3
|
-
type Configuration,
|
|
4
|
-
type AuthenticationResult,
|
|
5
|
-
type SsoSilentRequest,
|
|
6
|
-
type PopupRequest,
|
|
7
|
-
type RedirectRequest,
|
|
8
|
-
type AccountInfo as AccountInfoBase,
|
|
9
|
-
} from '@azure/msal-browser';
|
|
10
|
-
|
|
11
|
-
import { type AuthBehavior, defaultBehavior } from './behavior';
|
|
12
|
-
import type { AuthRequest } from './request';
|
|
13
|
-
|
|
14
|
-
export type IdTokenClaims = {
|
|
15
|
-
aud: string;
|
|
16
|
-
exp: number;
|
|
17
|
-
};
|
|
18
|
-
|
|
19
|
-
export type AccountInfo = AccountInfoBase & {
|
|
20
|
-
idTokenClaims?: IdTokenClaims;
|
|
21
|
-
};
|
|
22
|
-
|
|
23
|
-
/**
|
|
24
|
-
* ### Simple extension of Microsoft`s authentication client.
|
|
25
|
-
*
|
|
26
|
-
* When using this client tenant is **required** since common login is deprecated after all.
|
|
27
|
-
* By providing tenant the user account can simple be extracted from current session *if any*.
|
|
28
|
-
*
|
|
29
|
-
* @example
|
|
30
|
-
* ```typescript
|
|
31
|
-
* const tenantId = '224123a0d-7990-4ba1-aff3-1dss9569af32';
|
|
32
|
-
* const authPath = '/my-app/auth';
|
|
33
|
-
* const client = new AuthClient(tenantId, {
|
|
34
|
-
* auth: {
|
|
35
|
-
* clientId: '6dab35d4-59ff-4dcc-3356-24479e6fc888',
|
|
36
|
-
* authority: `https://login.microsoftonline.com/${tenantId}`,
|
|
37
|
-
* redirectUri: window.location.origin + '/my-app/auth'
|
|
38
|
-
* }
|
|
39
|
-
* });
|
|
40
|
-
* document.getElementById('login-btn').addEventListener('click', () =>
|
|
41
|
-
* client.login({ scopes: ['data.read'] })
|
|
42
|
-
* .then(console.log)
|
|
43
|
-
* .catch(console.error)
|
|
44
|
-
* );
|
|
45
|
-
* (async() => {
|
|
46
|
-
* if(window.location.path === authPath) {
|
|
47
|
-
* await client.handleRedirectPromise()
|
|
48
|
-
* }
|
|
49
|
-
* )();
|
|
50
|
-
* ```
|
|
51
|
-
* @see [Microsoft Authentication Library](https://github.com/AzureAD/microsoft-authentication-library-for-js)
|
|
52
|
-
* @see [Microsoft identity platform](https://docs.microsoft.com/en-us/azure/active-directory/develop/v2-oauth2-auth-code-flow)
|
|
53
|
-
*/
|
|
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((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;
|
|
71
|
-
}
|
|
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
|
-
}
|
|
125
|
-
}
|
|
126
|
-
|
|
127
|
-
this.logger.verbose(`Attempting to login in by [${behavior}]`);
|
|
128
|
-
|
|
129
|
-
switch (behavior) {
|
|
130
|
-
case 'popup':
|
|
131
|
-
return this.loginPopup(request as PopupRequest);
|
|
132
|
-
case 'redirect': {
|
|
133
|
-
return this.loginRedirect(request as RedirectRequest);
|
|
134
|
-
}
|
|
135
|
-
}
|
|
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
|
-
}
|
|
166
|
-
}
|
|
167
|
-
|
|
168
|
-
this.logger.verbose(`Attempting to acquire token by [${behavior}]`);
|
|
169
|
-
|
|
170
|
-
switch (behavior) {
|
|
171
|
-
case 'popup':
|
|
172
|
-
return this.acquireTokenPopup(options);
|
|
173
|
-
case 'redirect': {
|
|
174
|
-
return this.acquireTokenRedirect(options);
|
|
175
|
-
}
|
|
176
|
-
}
|
|
177
|
-
}
|
|
178
|
-
}
|
|
179
|
-
|
|
180
|
-
export default AuthClient;
|
|
@@ -1,48 +0,0 @@
|
|
|
1
|
-
import type { Configuration, IPublicClientApplication } from '@azure/msal-browser';
|
|
2
|
-
import { AuthClient } from './client';
|
|
3
|
-
import { normalizeUri } from './util/url';
|
|
4
|
-
|
|
5
|
-
export type AuthClientConfig = Configuration & {
|
|
6
|
-
auth: Partial<Configuration['auth']>;
|
|
7
|
-
};
|
|
8
|
-
|
|
9
|
-
/**
|
|
10
|
-
* Creates an authentication client with basic config.
|
|
11
|
-
*
|
|
12
|
-
* @example
|
|
13
|
-
* ```typescript
|
|
14
|
-
* const myClient = createClient(
|
|
15
|
-
* '224123a0d-7990-4ba1-aff3-1dss9569af32',
|
|
16
|
-
* '6dab35d4-59ff-4dcc-3356-24479e6fc888',
|
|
17
|
-
* '/my-app/auth'
|
|
18
|
-
* );
|
|
19
|
-
* ```
|
|
20
|
-
*
|
|
21
|
-
* @template T - client type, default to {@link AuthClient}
|
|
22
|
-
*
|
|
23
|
-
* @param tenantId - tenant to for authentication
|
|
24
|
-
* @param clientId - client id for authentication
|
|
25
|
-
* @param redirectUri - callback url for authentication (must match exact configured url in app)
|
|
26
|
-
* @param config - optional [Configuration](https://github.com/AzureAD/microsoft-authentication-library-for-js/blob/dev/lib/msal-browser/src/config/Configuration.ts)
|
|
27
|
-
* @param ctor - optional client class
|
|
28
|
-
*/
|
|
29
|
-
export const createAuthClient = <T extends IPublicClientApplication = AuthClient>(
|
|
30
|
-
tenantId: string,
|
|
31
|
-
clientId: string,
|
|
32
|
-
redirectUri?: string,
|
|
33
|
-
config?: AuthClientConfig,
|
|
34
|
-
ctor?: new (tenantId: string, config: Configuration) => T,
|
|
35
|
-
): T => {
|
|
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
|
-
};
|
|
47
|
-
|
|
48
|
-
export default createAuthClient;
|
package/src/v2/client/index.ts
DELETED
|
@@ -1,58 +0,0 @@
|
|
|
1
|
-
import { Logger, LogLevel } from '@azure/msal-browser';
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* Logger functions of {@link Console}
|
|
5
|
-
*/
|
|
6
|
-
type ConsoleLevel = 'error' | 'warn' | 'info' | 'debug';
|
|
7
|
-
|
|
8
|
-
/**
|
|
9
|
-
* MSAL client logger for development, production should use telemetry
|
|
10
|
-
*
|
|
11
|
-
* @example
|
|
12
|
-
* ```typescript
|
|
13
|
-
* client.setLogger(new ConsoleLogger());
|
|
14
|
-
* ```
|
|
15
|
-
*/
|
|
16
|
-
export class ConsoleLogger extends Logger {
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
};
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
export default ConsoleLogger;
|