@equinor/fusion-framework-react-app 4.1.18 → 4.2.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 +204 -175
- package/dist/esm/msal/index.js +4 -0
- package/dist/esm/msal/index.js.map +1 -0
- package/dist/esm/msal/useAccessToken.js +6 -0
- package/dist/esm/msal/useAccessToken.js.map +1 -0
- package/dist/esm/msal/useCurrentAccount.js +6 -0
- package/dist/esm/msal/useCurrentAccount.js.map +1 -0
- package/dist/esm/msal/useToken.js +20 -0
- package/dist/esm/msal/useToken.js.map +1 -0
- package/dist/esm/version.js +1 -1
- package/dist/esm/version.js.map +1 -1
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/dist/types/msal/index.d.ts +3 -0
- package/dist/types/msal/useAccessToken.d.ts +6 -0
- package/dist/types/msal/useCurrentAccount.d.ts +2 -0
- package/dist/types/msal/useToken.d.ts +7 -0
- package/dist/types/version.d.ts +1 -1
- package/package.json +19 -10
- package/src/msal/index.ts +3 -0
- package/src/msal/useAccessToken.ts +15 -0
- package/src/msal/useCurrentAccount.ts +11 -0
- package/src/msal/useToken.ts +29 -0
- package/src/version.ts +1 -1
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { AuthRequest, AuthenticationResult } from '@equinor/fusion-framework-module-msal/client';
|
|
2
|
+
export declare const useToken: (req: AuthRequest) => {
|
|
3
|
+
token?: AuthenticationResult | undefined;
|
|
4
|
+
pending: boolean;
|
|
5
|
+
error: unknown;
|
|
6
|
+
};
|
|
7
|
+
export default useToken;
|
package/dist/types/version.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export declare const version = "4.
|
|
1
|
+
export declare const version = "4.2.0";
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@equinor/fusion-framework-react-app",
|
|
3
|
-
"version": "4.
|
|
3
|
+
"version": "4.2.0",
|
|
4
4
|
"description": "",
|
|
5
5
|
"main": "dist/esm/index.js",
|
|
6
6
|
"exports": {
|
|
@@ -24,6 +24,10 @@
|
|
|
24
24
|
"import": "./dist/esm/http/index.js",
|
|
25
25
|
"types": "./dist/types/http/index.d.ts"
|
|
26
26
|
},
|
|
27
|
+
"./msal": {
|
|
28
|
+
"import": "./dist/esm/msal/index.js",
|
|
29
|
+
"types": "./dist/types/msal/index.d.ts"
|
|
30
|
+
},
|
|
27
31
|
"./navigation": {
|
|
28
32
|
"import": "./dist/esm/navigation/index.js",
|
|
29
33
|
"types": "./dist/types/navigation/index.d.ts"
|
|
@@ -44,6 +48,9 @@
|
|
|
44
48
|
"http": [
|
|
45
49
|
"dist/types/http/index.d.ts"
|
|
46
50
|
],
|
|
51
|
+
"msal": [
|
|
52
|
+
"dist/types/msal/index.d.ts"
|
|
53
|
+
],
|
|
47
54
|
"navigation": [
|
|
48
55
|
"dist/types/navigation/index.d.ts"
|
|
49
56
|
]
|
|
@@ -61,13 +68,13 @@
|
|
|
61
68
|
"directory": "packages/react"
|
|
62
69
|
},
|
|
63
70
|
"dependencies": {
|
|
64
|
-
"@equinor/fusion-framework-app": "^7.1.
|
|
65
|
-
"@equinor/fusion-framework-module-app": "^5.2.12",
|
|
71
|
+
"@equinor/fusion-framework-app": "^7.1.15",
|
|
66
72
|
"@equinor/fusion-framework-module": "^4.2.6",
|
|
67
|
-
"@equinor/fusion-framework-module-
|
|
73
|
+
"@equinor/fusion-framework-module-app": "^5.2.12",
|
|
74
|
+
"@equinor/fusion-framework-react": "^5.3.8",
|
|
68
75
|
"@equinor/fusion-framework-react-module": "^3.0.7",
|
|
69
|
-
"@equinor/fusion-framework-
|
|
70
|
-
"@equinor/fusion-framework-react-module-http": "^4.0.
|
|
76
|
+
"@equinor/fusion-framework-module-navigation": "^3.1.3",
|
|
77
|
+
"@equinor/fusion-framework-react-module-http": "^4.0.5"
|
|
71
78
|
},
|
|
72
79
|
"devDependencies": {
|
|
73
80
|
"@types/react": "^18.2.20",
|
|
@@ -75,14 +82,16 @@
|
|
|
75
82
|
"react": "^18.2.0",
|
|
76
83
|
"react-dom": "^18.2.0",
|
|
77
84
|
"typescript": "^5.1.3",
|
|
78
|
-
"@equinor/fusion-framework-
|
|
79
|
-
"@equinor/fusion-framework-react-module-
|
|
80
|
-
"@equinor/fusion-framework-module-event": "^4.0.7"
|
|
85
|
+
"@equinor/fusion-framework-module-msal": "^3.0.9",
|
|
86
|
+
"@equinor/fusion-framework-react-module-bookmark": "^2.0.27",
|
|
87
|
+
"@equinor/fusion-framework-module-event": "^4.0.7",
|
|
88
|
+
"@equinor/fusion-framework-react-module-context": "^6.0.18"
|
|
81
89
|
},
|
|
82
90
|
"peerDependencies": {
|
|
83
91
|
"@types/react": "^17.0.0 || ^18.0.0",
|
|
84
92
|
"react": "^17.0.0 || ^18.0.0",
|
|
85
|
-
"react-dom": "^17.0.0 || ^18.0.0"
|
|
93
|
+
"react-dom": "^17.0.0 || ^18.0.0",
|
|
94
|
+
"@equinor/fusion-framework-module-msal": "^3.0.9"
|
|
86
95
|
},
|
|
87
96
|
"peerDependenciesMeta": {
|
|
88
97
|
"@equinor/fusion-framework-react-module-context": {
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { AuthRequest } from '@equinor/fusion-framework-module-msal/client';
|
|
2
|
+
import { useToken } from './useToken';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Custom hook that retrieves an access token for the specified authentication request.
|
|
6
|
+
*
|
|
7
|
+
* @param req - The authentication request.
|
|
8
|
+
* @returns An object containing the access token, pending state, and error.
|
|
9
|
+
*/
|
|
10
|
+
export const useAccessToken = (
|
|
11
|
+
req: AuthRequest,
|
|
12
|
+
): { token?: string; pending: boolean; error: unknown } => {
|
|
13
|
+
const { token, error, pending } = useToken(req);
|
|
14
|
+
return { token: token?.accessToken, pending, error };
|
|
15
|
+
};
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { AccountInfo } from '@equinor/fusion-framework-module-msal';
|
|
2
|
+
import useAppModule from '../useAppModule';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Retrieves the current account information from the MSAL provider.
|
|
6
|
+
* @returns The current account information or undefined if no account is available.
|
|
7
|
+
*/
|
|
8
|
+
export const useCurrentAccount = (): AccountInfo | undefined => {
|
|
9
|
+
const msalProvider = useAppModule('auth');
|
|
10
|
+
return msalProvider.defaultAccount;
|
|
11
|
+
};
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { AuthRequest, AuthenticationResult } from '@equinor/fusion-framework-module-msal/client';
|
|
2
|
+
import useAppModule from '../useAppModule';
|
|
3
|
+
import { useEffect, useState } from 'react';
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Custom hook for acquiring an authentication token using MSAL.
|
|
7
|
+
* @param req - The authentication request.
|
|
8
|
+
* @returns An object containing the acquired token, pending state, and error.
|
|
9
|
+
*/
|
|
10
|
+
export const useToken = (
|
|
11
|
+
req: AuthRequest,
|
|
12
|
+
): { token?: AuthenticationResult; pending: boolean; error: unknown } => {
|
|
13
|
+
const msalProvider = useAppModule('auth');
|
|
14
|
+
const [token, setToken] = useState<AuthenticationResult | undefined>(undefined);
|
|
15
|
+
const [pending, setPending] = useState<boolean>(false);
|
|
16
|
+
const [error, setError] = useState<unknown>(null);
|
|
17
|
+
useEffect(() => {
|
|
18
|
+
setPending(true);
|
|
19
|
+
setToken(undefined);
|
|
20
|
+
msalProvider
|
|
21
|
+
.acquireToken(req)
|
|
22
|
+
.then((token) => token && setToken(token))
|
|
23
|
+
.catch(setError)
|
|
24
|
+
.finally(() => setPending(false));
|
|
25
|
+
}, [msalProvider, req]);
|
|
26
|
+
return { token, pending, error };
|
|
27
|
+
};
|
|
28
|
+
|
|
29
|
+
export default useToken;
|
package/src/version.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
// Generated by genversion.
|
|
2
|
-
export const version = '4.
|
|
2
|
+
export const version = '4.2.0';
|