@equinor/fusion-framework-module-msal 3.1.0 → 3.1.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 +116 -57
- package/dist/esm/client/behavior.js +3 -0
- package/dist/esm/client/behavior.js.map +1 -1
- package/dist/esm/client/client.js +68 -0
- package/dist/esm/client/client.js.map +1 -1
- package/dist/esm/client/create-auth-client.js +20 -0
- package/dist/esm/client/create-auth-client.js.map +1 -1
- package/dist/esm/client/log/console.js +15 -0
- package/dist/esm/client/log/console.js.map +1 -1
- package/dist/esm/client/util/browser.js +10 -0
- package/dist/esm/client/util/browser.js.map +1 -1
- package/dist/esm/client/util/url.js +14 -0
- package/dist/esm/client/util/url.js.map +1 -1
- package/dist/esm/configurator.js +1 -0
- package/dist/esm/configurator.js.map +1 -1
- package/dist/esm/index.js +4 -0
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/module.js +19 -0
- package/dist/esm/module.js.map +1 -1
- package/dist/esm/provider.js +1 -0
- package/dist/esm/provider.js.map +1 -1
- package/dist/esm/version.js +2 -1
- package/dist/esm/version.js.map +1 -1
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/dist/types/client/behavior.d.ts +11 -0
- package/dist/types/client/client.d.ts +68 -0
- package/dist/types/client/create-auth-client.d.ts +21 -1
- package/dist/types/client/log/console.d.ts +18 -0
- package/dist/types/client/request.d.ts +63 -0
- package/dist/types/configurator.d.ts +17 -0
- package/dist/types/index.d.ts +4 -0
- package/dist/types/module.d.ts +17 -0
- package/dist/types/provider.d.ts +21 -0
- package/dist/types/version.d.ts +1 -1
- package/package.json +3 -3
- package/src/version.ts +1 -1
|
@@ -1,2 +1,13 @@
|
|
|
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
|
+
*/
|
|
1
9
|
export type AuthBehavior = 'popup' | 'redirect';
|
|
10
|
+
/**
|
|
11
|
+
* Default behavior for login and acquisition of token
|
|
12
|
+
*/
|
|
2
13
|
export declare const defaultBehavior: AuthBehavior;
|
|
@@ -8,14 +8,82 @@ export type IdTokenClaims = {
|
|
|
8
8
|
export type AccountInfo = AccountInfoBase & {
|
|
9
9
|
idTokenClaims?: IdTokenClaims;
|
|
10
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
|
+
*/
|
|
11
42
|
export declare class AuthClient extends PublicClientApplication {
|
|
12
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
|
+
*/
|
|
13
49
|
get account(): AccountInfo | undefined;
|
|
14
50
|
get hasValidClaims(): boolean;
|
|
51
|
+
/**
|
|
52
|
+
* @returns - Configured client id
|
|
53
|
+
*/
|
|
15
54
|
get clientId(): string | undefined;
|
|
16
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
|
+
*/
|
|
17
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
|
+
*/
|
|
18
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
|
+
*/
|
|
19
87
|
acquireToken(options?: AuthRequest, behavior?: AuthBehavior, silent?: boolean): Promise<AuthenticationResult | void>;
|
|
20
88
|
}
|
|
21
89
|
export default AuthClient;
|
|
@@ -3,5 +3,25 @@ import { AuthClient } from './client';
|
|
|
3
3
|
export type AuthClientConfig = Configuration & {
|
|
4
4
|
auth: Partial<Configuration['auth']>;
|
|
5
5
|
};
|
|
6
|
-
|
|
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;
|
|
7
27
|
export default createAuthClient;
|
|
@@ -1,8 +1,26 @@
|
|
|
1
1
|
import { Logger, LogLevel } from '@azure/msal-browser';
|
|
2
|
+
/**
|
|
3
|
+
* Logger functions of {@link Console}
|
|
4
|
+
*/
|
|
2
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
|
+
*/
|
|
3
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
|
+
*/
|
|
4
18
|
constructor(logLevel?: LogLevel);
|
|
19
|
+
/** @inheritdoc */
|
|
5
20
|
protected loggerCallback(lvl: LogLevel, msg: string, _containsPii?: boolean): void;
|
|
21
|
+
/**
|
|
22
|
+
* Map log level to console log function type
|
|
23
|
+
*/
|
|
6
24
|
protected getLogType: (lvl: LogLevel) => ConsoleLevel;
|
|
7
25
|
}
|
|
8
26
|
export default ConsoleLogger;
|
|
@@ -1,2 +1,65 @@
|
|
|
1
1
|
import { 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
|
+
*/
|
|
2
65
|
export type AuthRequest = PopupRequest | RedirectRequest;
|
|
@@ -6,13 +6,30 @@ export type AuthClientOptions = {
|
|
|
6
6
|
config?: AuthClientConfig;
|
|
7
7
|
};
|
|
8
8
|
export interface IAuthConfigurator {
|
|
9
|
+
/**
|
|
10
|
+
* get default configuration for module
|
|
11
|
+
*/
|
|
9
12
|
readonly defaultConfig: AuthClientOptions | undefined;
|
|
13
|
+
/**
|
|
14
|
+
* Get named config by key
|
|
15
|
+
* @param name key for config
|
|
16
|
+
*/
|
|
10
17
|
getClientConfig(name: string): AuthClientOptions;
|
|
18
|
+
/**
|
|
19
|
+
* Create named config
|
|
20
|
+
* @param name key for config
|
|
21
|
+
* @param options config options
|
|
22
|
+
*/
|
|
11
23
|
configureClient(name: string, options: AuthClientOptions): AuthConfigurator;
|
|
24
|
+
/**
|
|
25
|
+
* Create default module config
|
|
26
|
+
* @param options config options
|
|
27
|
+
*/
|
|
12
28
|
configureDefault(options: AuthClientOptions): void;
|
|
13
29
|
requiresAuth: boolean;
|
|
14
30
|
}
|
|
15
31
|
export declare class AuthConfigurator implements IAuthConfigurator {
|
|
32
|
+
/** internal map of keyed configs */
|
|
16
33
|
protected _configs: Record<string, AuthClientOptions>;
|
|
17
34
|
requiresAuth: boolean;
|
|
18
35
|
get defaultConfig(): AuthClientOptions | undefined;
|
package/dist/types/index.d.ts
CHANGED
package/dist/types/module.d.ts
CHANGED
|
@@ -3,6 +3,23 @@ import { IAuthProvider } from './provider';
|
|
|
3
3
|
import type { Module, IModuleConfigurator } from '@equinor/fusion-framework-module';
|
|
4
4
|
export type MsalModule = Module<'auth', IAuthProvider, IAuthConfigurator>;
|
|
5
5
|
export declare const module: MsalModule;
|
|
6
|
+
/**
|
|
7
|
+
* Enable MSAL module
|
|
8
|
+
*
|
|
9
|
+
* @example
|
|
10
|
+
```ts
|
|
11
|
+
configureMsal(
|
|
12
|
+
{
|
|
13
|
+
tenantId: '{TENANT_ID}',
|
|
14
|
+
clientId: '{CLIENT_ID}',
|
|
15
|
+
redirectUri: '/authentication/login-callback',
|
|
16
|
+
},
|
|
17
|
+
// requires authenticated user when module is initialized (force login)
|
|
18
|
+
{ requiresAuth: true }
|
|
19
|
+
);
|
|
20
|
+
```
|
|
21
|
+
* @param defaultClient - default auth client for the module
|
|
22
|
+
*/
|
|
6
23
|
export declare const configureMsal: (defaultClient: AuthClientOptions, args?: {
|
|
7
24
|
clients?: Record<string, AuthClientOptions>;
|
|
8
25
|
requiresAuth?: boolean;
|
package/dist/types/provider.d.ts
CHANGED
|
@@ -12,11 +12,32 @@ export interface IAuthProvider {
|
|
|
12
12
|
readonly defaultClient: AuthClient;
|
|
13
13
|
readonly defaultConfig: AuthClientOptions | undefined;
|
|
14
14
|
readonly defaultAccount: AccountInfo | undefined;
|
|
15
|
+
/**
|
|
16
|
+
* Get auth client by registered config name
|
|
17
|
+
*/
|
|
15
18
|
getClient(name: string): AuthClient;
|
|
19
|
+
/**
|
|
20
|
+
* Create auth client by registered config name
|
|
21
|
+
* @param name name of configured client, default to defaultConfig {@link IAuthConfigurator.configureDefault}
|
|
22
|
+
*/
|
|
16
23
|
createClient(name?: string): AuthClient;
|
|
24
|
+
/**
|
|
25
|
+
* Acquire token from default auth client
|
|
26
|
+
* @param req Auth request options
|
|
27
|
+
*/
|
|
17
28
|
acquireToken(req: AuthRequest): ReturnType<AuthClient['acquireToken']>;
|
|
29
|
+
/**
|
|
30
|
+
* Acquire access token from default auth client
|
|
31
|
+
* @param req Auth request options
|
|
32
|
+
*/
|
|
18
33
|
acquireAccessToken(req: AuthRequest): Promise<string | undefined>;
|
|
34
|
+
/**
|
|
35
|
+
* Login to default auth client
|
|
36
|
+
*/
|
|
19
37
|
login(): Promise<void>;
|
|
38
|
+
/**
|
|
39
|
+
* Handle default client redirect callback
|
|
40
|
+
*/
|
|
20
41
|
handleRedirect(): ReturnType<AuthClient['handleRedirectPromise']>;
|
|
21
42
|
}
|
|
22
43
|
export declare class AuthProvider implements IAuthProvider {
|
package/dist/types/version.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export declare const version = "3.1.
|
|
1
|
+
export declare const version = "3.1.2";
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@equinor/fusion-framework-module-msal",
|
|
3
|
-
"version": "3.1.
|
|
3
|
+
"version": "3.1.2",
|
|
4
4
|
"description": "",
|
|
5
5
|
"main": "dist/esm/index.js",
|
|
6
6
|
"exports": {
|
|
@@ -34,10 +34,10 @@
|
|
|
34
34
|
},
|
|
35
35
|
"dependencies": {
|
|
36
36
|
"@azure/msal-browser": "^2.21.0",
|
|
37
|
-
"@equinor/fusion-framework-module": "^4.3.
|
|
37
|
+
"@equinor/fusion-framework-module": "^4.3.2"
|
|
38
38
|
},
|
|
39
39
|
"devDependencies": {
|
|
40
|
-
"typescript": "^5.
|
|
40
|
+
"typescript": "^5.5.3"
|
|
41
41
|
},
|
|
42
42
|
"scripts": {
|
|
43
43
|
"build": "tsc -b"
|
package/src/version.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
// Generated by genversion.
|
|
2
|
-
export const version = '3.1.
|
|
2
|
+
export const version = '3.1.2';
|