@equinor/mad-auth 0.2.17 → 0.4.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 +17 -0
- package/README.md +3 -24
- package/dist/Expo-AuthSession/authenticationHandler/auth.d.ts +2 -2
- package/dist/Expo-AuthSession/authenticationHandler/auth.js +4 -4
- package/dist/Expo-AuthSession/authenticationHandler/index.js +9 -9
- package/dist/Expo-AuthSession/authenticationHandler/web/authWeb.d.ts +2 -0
- package/dist/Expo-AuthSession/authenticationHandler/web/authWeb.js +6 -2
- package/dist/Expo-AuthSession/authenticationHandler/web/index.js +7 -3
- package/dist/Expo-AuthSession/authenticationHandler/web/publicClientApplication.d.ts +1 -1
- package/dist/Expo-AuthSession/authenticationHandler/web/publicClientApplication.js +1 -1
- package/dist/Expo-AuthSession/components/LoginButton.d.ts +12 -1
- package/dist/Expo-AuthSession/components/LoginButton.js +11 -11
- package/dist/Expo-AuthSession/hooks/useAccount.js +10 -10
- package/dist/Expo-AuthSession/hooks/useAuthenticate.d.ts +1 -1
- package/dist/Expo-AuthSession/hooks/useAuthenticate.js +10 -10
- package/dist/Expo-AuthSession/index.js +28 -14
- package/dist/Expo-AuthSession/store/authStore.d.ts +10 -2
- package/dist/Expo-AuthSession/store/authStore.js +16 -2
- package/dist/Expo-AuthSession/store/encryption.js +1 -1
- package/dist/Expo-AuthSession/types.d.ts +9 -2
- package/dist/Expo-AuthSession/utils/tokenRefresh.d.ts +1 -1
- package/dist/Expo-AuthSession/utils/tokenRefresh.js +3 -3
- package/dist/{chunk-WKE5IW37.js → chunk-AF7VKFEK.js} +20 -11
- package/dist/{chunk-52LAPG3S.js → chunk-B7COQI7U.js} +44 -16
- package/dist/{chunk-7KZL6S5R.js → chunk-CFY3FFVW.js} +4 -4
- package/dist/{chunk-UYO5Y6CJ.js → chunk-DDBEKLVA.js} +1 -1
- package/dist/{chunk-IU75T6GM.js → chunk-DDCMUW43.js} +3 -3
- package/dist/{chunk-ELBTMDOI.js → chunk-DSDORXK5.js} +3 -3
- package/dist/{chunk-W4CNNXDN.js → chunk-GRAW2VSL.js} +4 -1
- package/dist/{chunk-PETOX4KF.js → chunk-H623QQTI.js} +1 -1
- package/dist/{chunk-IEVUSC3Q.js → chunk-MA2UFH5G.js} +49 -7
- package/dist/{chunk-FETRYEKH.js → chunk-VQLMMK6U.js} +5 -2
- package/dist/{chunk-YVBJ5RPR.js → chunk-XYBA2PIE.js} +21 -7
- package/dist/{chunk-K34WGG6L.js → chunk-ZMR2HMDR.js} +60 -15
- package/dist/index.d.ts +0 -3
- package/dist/index.js +15 -43
- package/package.json +8 -8
- package/dist/auth.d.ts +0 -39
- package/dist/auth.js +0 -20
- package/dist/chunk-7A7RZF24.js +0 -52
- package/dist/chunk-DNMYY37N.js +0 -117
- package/dist/chunk-GUKC6UGZ.js +0 -0
- package/dist/chunk-HAB34YS7.js +0 -0
- package/dist/chunk-RBOUHIMW.js +0 -28
- package/dist/chunk-XENWB4ZX.js +0 -55
- package/dist/components/LoginButton.d.ts +0 -14
- package/dist/components/LoginButton.js +0 -10
- package/dist/components/index.d.ts +0 -1
- package/dist/components/index.js +0 -11
- package/dist/hooks/index.d.ts +0 -2
- package/dist/hooks/index.js +0 -14
- package/dist/hooks/useAccount.d.ts +0 -5
- package/dist/hooks/useAccount.js +0 -9
- package/dist/hooks/useAuthenticate.d.ts +0 -22
- package/dist/hooks/useAuthenticate.js +0 -9
|
@@ -1,16 +1,22 @@
|
|
|
1
1
|
import {
|
|
2
2
|
PublicClientApplication
|
|
3
|
-
} from "./chunk-
|
|
3
|
+
} from "./chunk-GRAW2VSL.js";
|
|
4
4
|
import {
|
|
5
5
|
getMadAccount,
|
|
6
6
|
getMadAuthenticationResult
|
|
7
7
|
} from "./chunk-7SOSXNKP.js";
|
|
8
|
+
import {
|
|
9
|
+
getWebConfig,
|
|
10
|
+
setWebConfig,
|
|
11
|
+
useAuth
|
|
12
|
+
} from "./chunk-MA2UFH5G.js";
|
|
8
13
|
import {
|
|
9
14
|
__async
|
|
10
15
|
} from "./chunk-CWMXXUWU.js";
|
|
11
16
|
|
|
12
17
|
// src/Expo-AuthSession/authenticationHandler/web/authWeb.ts
|
|
13
18
|
var pca = null;
|
|
19
|
+
var initPca = null;
|
|
14
20
|
function _getMsalAccount() {
|
|
15
21
|
return __async(this, null, function* () {
|
|
16
22
|
if (!pca) {
|
|
@@ -45,7 +51,16 @@ function initiateAuthenticationClientWeb({
|
|
|
45
51
|
cache: { cacheLocation: "localStorage" }
|
|
46
52
|
};
|
|
47
53
|
pca = new PublicClientApplication(config);
|
|
48
|
-
|
|
54
|
+
setWebConfig({ clientId, redirectUri, authority });
|
|
55
|
+
}
|
|
56
|
+
function ensurePcaInitialized() {
|
|
57
|
+
if (!pca) {
|
|
58
|
+
throw new Error("Unable to authenticate, authentication client does not exist");
|
|
59
|
+
}
|
|
60
|
+
if (!initPca) {
|
|
61
|
+
initPca = pca.init();
|
|
62
|
+
}
|
|
63
|
+
return initPca;
|
|
49
64
|
}
|
|
50
65
|
function authenticationClientExistsWeb() {
|
|
51
66
|
return !!pca;
|
|
@@ -58,6 +73,7 @@ function authenticateInteractivelyWeb(scopes) {
|
|
|
58
73
|
if (!scopes) {
|
|
59
74
|
throw new Error("Unable to authenticate, scopes are not defined");
|
|
60
75
|
}
|
|
76
|
+
yield ensurePcaInitialized();
|
|
61
77
|
const result = yield pca.acquireToken({
|
|
62
78
|
scopes
|
|
63
79
|
});
|
|
@@ -72,23 +88,34 @@ function getAccountWeb() {
|
|
|
72
88
|
}
|
|
73
89
|
function authenticateSilentlyWeb(scopes) {
|
|
74
90
|
return __async(this, null, function* () {
|
|
91
|
+
yield useAuth.persist.rehydrate();
|
|
92
|
+
const webConfig = getWebConfig();
|
|
75
93
|
if (!pca) {
|
|
76
|
-
|
|
94
|
+
if (webConfig) {
|
|
95
|
+
initiateAuthenticationClientWeb(webConfig);
|
|
96
|
+
} else {
|
|
97
|
+
throw new Error("Unable to authenticate, authentication client does not exist");
|
|
98
|
+
}
|
|
77
99
|
}
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
const
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
100
|
+
if (pca) {
|
|
101
|
+
yield ensurePcaInitialized();
|
|
102
|
+
const msalAccount = yield _getMsalAccount();
|
|
103
|
+
if (msalAccount && scopes) {
|
|
104
|
+
const params = {
|
|
105
|
+
account: msalAccount,
|
|
106
|
+
scopes,
|
|
107
|
+
forceRefresh: false
|
|
108
|
+
};
|
|
109
|
+
const result = yield pca.acquireTokenSilent(params).catch((e) => {
|
|
110
|
+
console.log("Error while fetching token silently", e);
|
|
111
|
+
}).then((res) => res);
|
|
112
|
+
if (!result) return null;
|
|
113
|
+
return getMadAuthenticationResult(result);
|
|
114
|
+
}
|
|
115
|
+
throw new Error("Unable to authenticate, authentication client does not exist");
|
|
116
|
+
} else {
|
|
117
|
+
throw new Error("Unable to authenticate, authentication client does not exist");
|
|
90
118
|
}
|
|
91
|
-
return null;
|
|
92
119
|
});
|
|
93
120
|
}
|
|
94
121
|
function signOutWeb() {
|
|
@@ -110,6 +137,7 @@ function _resetWeb() {
|
|
|
110
137
|
|
|
111
138
|
export {
|
|
112
139
|
initiateAuthenticationClientWeb,
|
|
140
|
+
ensurePcaInitialized,
|
|
113
141
|
authenticationClientExistsWeb,
|
|
114
142
|
authenticateInteractivelyWeb,
|
|
115
143
|
getAccountWeb,
|
|
@@ -4,20 +4,20 @@ import {
|
|
|
4
4
|
authenticationClientExistsWeb,
|
|
5
5
|
initiateAuthenticationClientWeb,
|
|
6
6
|
signOutWeb
|
|
7
|
-
} from "./chunk-
|
|
7
|
+
} from "./chunk-B7COQI7U.js";
|
|
8
8
|
import {
|
|
9
9
|
authenticateInteractively,
|
|
10
10
|
authenticateSilently,
|
|
11
11
|
authenticationClientExists,
|
|
12
12
|
initiateAuthenticationClient,
|
|
13
13
|
signOut
|
|
14
|
-
} from "./chunk-
|
|
14
|
+
} from "./chunk-ZMR2HMDR.js";
|
|
15
15
|
|
|
16
16
|
// src/Expo-AuthSession/authenticationHandler/index.ts
|
|
17
17
|
import { Platform } from "react-native";
|
|
18
18
|
var signOut2 = () => Platform.OS === "web" ? signOutWeb() : signOut();
|
|
19
|
-
var authenticateSilently2 = (scopes) => Platform.OS === "web" ? authenticateSilentlyWeb(scopes) : authenticateSilently();
|
|
20
|
-
var authenticateInteractively2 = (scopes) => Platform.OS === "web" ? authenticateInteractivelyWeb(scopes) : authenticateInteractively();
|
|
19
|
+
var authenticateSilently2 = (scopes) => Platform.OS === "web" ? authenticateSilentlyWeb(scopes) : authenticateSilently(scopes);
|
|
20
|
+
var authenticateInteractively2 = (scopes) => Platform.OS === "web" ? authenticateInteractivelyWeb(scopes) : authenticateInteractively(scopes);
|
|
21
21
|
var initiateAuthenticationClient2 = (config, discovery) => Platform.OS === "web" ? initiateAuthenticationClientWeb({
|
|
22
22
|
clientId: config.clientId,
|
|
23
23
|
redirectUri: config.redirectUri
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import {
|
|
2
2
|
getAccountWeb
|
|
3
|
-
} from "./chunk-
|
|
3
|
+
} from "./chunk-B7COQI7U.js";
|
|
4
4
|
import {
|
|
5
5
|
useAuth
|
|
6
|
-
} from "./chunk-
|
|
6
|
+
} from "./chunk-MA2UFH5G.js";
|
|
7
7
|
import {
|
|
8
8
|
__async
|
|
9
9
|
} from "./chunk-CWMXXUWU.js";
|
|
@@ -18,7 +18,7 @@ var useAccountNative = () => {
|
|
|
18
18
|
var useAccountWeb = () => {
|
|
19
19
|
const [account, setAccount] = useState();
|
|
20
20
|
useEffect(() => {
|
|
21
|
-
const getAndSetAccount = () => __async(
|
|
21
|
+
const getAndSetAccount = () => __async(null, null, function* () {
|
|
22
22
|
try {
|
|
23
23
|
const account2 = yield getAccountWeb();
|
|
24
24
|
setAccount(account2);
|
|
@@ -3,7 +3,7 @@ import {
|
|
|
3
3
|
authenticateSilently,
|
|
4
4
|
authenticationClientExists,
|
|
5
5
|
initiateAuthenticationClient
|
|
6
|
-
} from "./chunk-
|
|
6
|
+
} from "./chunk-CFY3FFVW.js";
|
|
7
7
|
import {
|
|
8
8
|
__async
|
|
9
9
|
} from "./chunk-CWMXXUWU.js";
|
|
@@ -22,7 +22,7 @@ var useAuthenticate = ({
|
|
|
22
22
|
);
|
|
23
23
|
const [authenticationInProgress, setAuthenticationInProgress] = useState(false);
|
|
24
24
|
const [authenticationClientInitialized, setAuthenticationClientInitialized] = useState(false);
|
|
25
|
-
const withAuthenticationPromiseHandler = (promise, type) => __async(
|
|
25
|
+
const withAuthenticationPromiseHandler = (promise, type) => __async(null, null, function* () {
|
|
26
26
|
setAuthenticationInProgress(true);
|
|
27
27
|
try {
|
|
28
28
|
const res = yield promise();
|
|
@@ -34,7 +34,7 @@ var useAuthenticate = ({
|
|
|
34
34
|
}
|
|
35
35
|
});
|
|
36
36
|
useEffect(() => {
|
|
37
|
-
const initiateClientAndMaybeAuthenticateSilently = () => __async(
|
|
37
|
+
const initiateClientAndMaybeAuthenticateSilently = () => __async(null, null, function* () {
|
|
38
38
|
initiateAuthenticationClient(config, discovery);
|
|
39
39
|
if (authenticationClientExists()) setAuthenticationClientInitialized(true);
|
|
40
40
|
if (enableAutomaticAuthentication)
|
|
@@ -13,7 +13,10 @@ var PublicClientApplication = class {
|
|
|
13
13
|
this._pca = new MSALPublicClientApplication(this.config);
|
|
14
14
|
}
|
|
15
15
|
init() {
|
|
16
|
-
return this
|
|
16
|
+
return __async(this, null, function* () {
|
|
17
|
+
yield this._pca.initialize();
|
|
18
|
+
return this;
|
|
19
|
+
});
|
|
17
20
|
}
|
|
18
21
|
acquireToken(params) {
|
|
19
22
|
return __async(this, null, function* () {
|
|
@@ -2,7 +2,7 @@ import {
|
|
|
2
2
|
getItem,
|
|
3
3
|
removeItem,
|
|
4
4
|
setItem
|
|
5
|
-
} from "./chunk-
|
|
5
|
+
} from "./chunk-AF7VKFEK.js";
|
|
6
6
|
|
|
7
7
|
// src/Expo-AuthSession/store/authStore.ts
|
|
8
8
|
import { TokenResponse } from "expo-auth-session";
|
|
@@ -13,7 +13,13 @@ var useAuth = create()(
|
|
|
13
13
|
persist(
|
|
14
14
|
(set) => ({
|
|
15
15
|
setToken: (token) => {
|
|
16
|
-
set(
|
|
16
|
+
set((state) => {
|
|
17
|
+
const filteredTokens = state.token ? state.token.filter((t) => t.scope !== token.scope) : [];
|
|
18
|
+
return { token: filteredTokens ? [...filteredTokens, token] : [token] };
|
|
19
|
+
});
|
|
20
|
+
},
|
|
21
|
+
setRefreshToken: (refreshToken) => {
|
|
22
|
+
set({ refreshToken });
|
|
17
23
|
},
|
|
18
24
|
setUserData: (account) => {
|
|
19
25
|
set({ userData: account });
|
|
@@ -24,6 +30,9 @@ var useAuth = create()(
|
|
|
24
30
|
setConfig: (config) => {
|
|
25
31
|
set({ config });
|
|
26
32
|
},
|
|
33
|
+
setWebConfig: (webConfig) => {
|
|
34
|
+
set({ webConfig });
|
|
35
|
+
},
|
|
27
36
|
resetToken: () => {
|
|
28
37
|
set({ token: void 0 });
|
|
29
38
|
},
|
|
@@ -35,12 +44,18 @@ var useAuth = create()(
|
|
|
35
44
|
},
|
|
36
45
|
resetConfig: () => {
|
|
37
46
|
set({ config: void 0 });
|
|
47
|
+
},
|
|
48
|
+
resetRefreshToken: () => {
|
|
49
|
+
set({ refreshToken: void 0 });
|
|
50
|
+
},
|
|
51
|
+
resetWebConfig: () => {
|
|
52
|
+
set({ webConfig: void 0 });
|
|
38
53
|
}
|
|
39
54
|
}),
|
|
40
55
|
{
|
|
41
56
|
partialize: (state) => Object.fromEntries(
|
|
42
57
|
Object.entries(state).filter(
|
|
43
|
-
([key]) => ["token", "userData"].includes(key)
|
|
58
|
+
([key]) => ["token", "userData", "webConfig", "refreshToken"].includes(key)
|
|
44
59
|
)
|
|
45
60
|
),
|
|
46
61
|
name: "storage",
|
|
@@ -54,34 +69,61 @@ var useAuth = create()(
|
|
|
54
69
|
{ name: "core/auth" }
|
|
55
70
|
)
|
|
56
71
|
);
|
|
57
|
-
var getToken = () => {
|
|
58
|
-
const
|
|
59
|
-
|
|
72
|
+
var getToken = (scopes) => {
|
|
73
|
+
const tokens = useAuth.getState().token;
|
|
74
|
+
const config = getConfig();
|
|
75
|
+
if (!scopes && !config) {
|
|
76
|
+
return tokens && tokens.length > 0 ? tokens[0] : null;
|
|
77
|
+
}
|
|
78
|
+
const currentScopes = scopes ? scopes : (config == null ? void 0 : config.scopes) ? config.scopes : [];
|
|
79
|
+
const omittedScopes = ["openid", "profile", "offline_access"];
|
|
80
|
+
const tokenWithScope = tokens ? tokens.find((t) => {
|
|
81
|
+
if (!t.scope) return false;
|
|
82
|
+
const granted = t.scope.split(" ");
|
|
83
|
+
return currentScopes.every(
|
|
84
|
+
(s) => omittedScopes.includes(s) || granted.includes(s)
|
|
85
|
+
);
|
|
86
|
+
}) : null;
|
|
87
|
+
return tokenWithScope ? new TokenResponse(tokenWithScope) : void 0;
|
|
60
88
|
};
|
|
89
|
+
var getAllTokens = () => useAuth.getState().token;
|
|
61
90
|
var getUserData = () => useAuth.getState().userData;
|
|
62
91
|
var getDiscovery = () => useAuth.getState().discovery;
|
|
63
92
|
var getConfig = () => useAuth.getState().config;
|
|
93
|
+
var getWebConfig = () => useAuth.getState().webConfig;
|
|
94
|
+
var getRefreshToken = () => useAuth.getState().refreshToken;
|
|
64
95
|
var setToken = (token) => useAuth.getState().setToken(token);
|
|
65
96
|
var setUserData = (userData) => useAuth.getState().setUserData(userData);
|
|
66
97
|
var setDiscovery = (discovery) => useAuth.getState().setDiscovery(discovery);
|
|
67
98
|
var setConfig = (config) => useAuth.getState().setConfig(config);
|
|
99
|
+
var setWebConfig = (webConfig) => useAuth.getState().setWebConfig(webConfig);
|
|
100
|
+
var setRefreshToken = (refreshToken) => useAuth.getState().setRefreshToken(refreshToken);
|
|
68
101
|
var resetToken = () => useAuth.getState().resetToken();
|
|
69
102
|
var resetUserData = () => useAuth.getState().resetUserData();
|
|
70
103
|
var resetDiscovery = () => useAuth.getState().resetDiscovery();
|
|
71
104
|
var resetConfig = () => useAuth.getState().resetConfig();
|
|
105
|
+
var resetWebConfig = () => useAuth.getState().resetWebConfig();
|
|
106
|
+
var resetRefreshToken = () => useAuth.getState().resetRefreshToken();
|
|
72
107
|
|
|
73
108
|
export {
|
|
74
109
|
useAuth,
|
|
75
110
|
getToken,
|
|
111
|
+
getAllTokens,
|
|
76
112
|
getUserData,
|
|
77
113
|
getDiscovery,
|
|
78
114
|
getConfig,
|
|
115
|
+
getWebConfig,
|
|
116
|
+
getRefreshToken,
|
|
79
117
|
setToken,
|
|
80
118
|
setUserData,
|
|
81
119
|
setDiscovery,
|
|
82
120
|
setConfig,
|
|
121
|
+
setWebConfig,
|
|
122
|
+
setRefreshToken,
|
|
83
123
|
resetToken,
|
|
84
124
|
resetUserData,
|
|
85
125
|
resetDiscovery,
|
|
86
|
-
resetConfig
|
|
126
|
+
resetConfig,
|
|
127
|
+
resetWebConfig,
|
|
128
|
+
resetRefreshToken
|
|
87
129
|
};
|
|
@@ -1,18 +1,21 @@
|
|
|
1
1
|
import {
|
|
2
2
|
getConfig,
|
|
3
3
|
getDiscovery
|
|
4
|
-
} from "./chunk-
|
|
4
|
+
} from "./chunk-MA2UFH5G.js";
|
|
5
5
|
import {
|
|
6
6
|
__async
|
|
7
7
|
} from "./chunk-CWMXXUWU.js";
|
|
8
8
|
|
|
9
9
|
// src/Expo-AuthSession/utils/tokenRefresh.ts
|
|
10
|
-
var tokenRefresh = (token) => __async(
|
|
10
|
+
var tokenRefresh = (token, scopes) => __async(null, null, function* () {
|
|
11
11
|
const discovery = getDiscovery();
|
|
12
12
|
const config = getConfig();
|
|
13
13
|
if (!discovery || !config) {
|
|
14
14
|
return;
|
|
15
15
|
}
|
|
16
|
+
if (scopes) {
|
|
17
|
+
config.scopes = scopes;
|
|
18
|
+
}
|
|
16
19
|
return yield token.refreshAsync(config, discovery);
|
|
17
20
|
});
|
|
18
21
|
|
|
@@ -1,40 +1,47 @@
|
|
|
1
1
|
import {
|
|
2
2
|
useAccount
|
|
3
|
-
} from "./chunk-
|
|
3
|
+
} from "./chunk-DDCMUW43.js";
|
|
4
4
|
import {
|
|
5
5
|
LoginButton
|
|
6
|
-
} from "./chunk-
|
|
6
|
+
} from "./chunk-DDBEKLVA.js";
|
|
7
7
|
import {
|
|
8
8
|
useAuthenticate
|
|
9
|
-
} from "./chunk-
|
|
9
|
+
} from "./chunk-DSDORXK5.js";
|
|
10
10
|
import {
|
|
11
11
|
authenticateInteractively,
|
|
12
12
|
authenticateSilently,
|
|
13
13
|
authenticationClientExists,
|
|
14
14
|
initiateAuthenticationClient,
|
|
15
15
|
signOut
|
|
16
|
-
} from "./chunk-
|
|
16
|
+
} from "./chunk-CFY3FFVW.js";
|
|
17
17
|
import {
|
|
18
18
|
getAccountWeb
|
|
19
|
-
} from "./chunk-
|
|
19
|
+
} from "./chunk-B7COQI7U.js";
|
|
20
20
|
import {
|
|
21
21
|
getAccount
|
|
22
|
-
} from "./chunk-
|
|
22
|
+
} from "./chunk-ZMR2HMDR.js";
|
|
23
23
|
import {
|
|
24
|
+
getAllTokens,
|
|
24
25
|
getConfig,
|
|
25
26
|
getDiscovery,
|
|
27
|
+
getRefreshToken,
|
|
26
28
|
getToken,
|
|
27
29
|
getUserData,
|
|
30
|
+
getWebConfig,
|
|
28
31
|
resetConfig,
|
|
29
32
|
resetDiscovery,
|
|
33
|
+
resetRefreshToken,
|
|
30
34
|
resetToken,
|
|
31
35
|
resetUserData,
|
|
36
|
+
resetWebConfig,
|
|
32
37
|
setConfig,
|
|
33
38
|
setDiscovery,
|
|
39
|
+
setRefreshToken,
|
|
34
40
|
setToken,
|
|
35
41
|
setUserData,
|
|
42
|
+
setWebConfig,
|
|
36
43
|
useAuth
|
|
37
|
-
} from "./chunk-
|
|
44
|
+
} from "./chunk-MA2UFH5G.js";
|
|
38
45
|
import {
|
|
39
46
|
__export
|
|
40
47
|
} from "./chunk-CWMXXUWU.js";
|
|
@@ -48,19 +55,26 @@ __export(Expo_AuthSession_exports, {
|
|
|
48
55
|
authenticationClientExists: () => authenticationClientExists,
|
|
49
56
|
getAccount: () => getAccount,
|
|
50
57
|
getAccountWeb: () => getAccountWeb,
|
|
58
|
+
getAllTokens: () => getAllTokens,
|
|
51
59
|
getConfig: () => getConfig,
|
|
52
60
|
getDiscovery: () => getDiscovery,
|
|
61
|
+
getRefreshToken: () => getRefreshToken,
|
|
53
62
|
getToken: () => getToken,
|
|
54
63
|
getUserData: () => getUserData,
|
|
64
|
+
getWebConfig: () => getWebConfig,
|
|
55
65
|
initiateAuthenticationClient: () => initiateAuthenticationClient,
|
|
56
66
|
resetConfig: () => resetConfig,
|
|
57
67
|
resetDiscovery: () => resetDiscovery,
|
|
68
|
+
resetRefreshToken: () => resetRefreshToken,
|
|
58
69
|
resetToken: () => resetToken,
|
|
59
70
|
resetUserData: () => resetUserData,
|
|
71
|
+
resetWebConfig: () => resetWebConfig,
|
|
60
72
|
setConfig: () => setConfig,
|
|
61
73
|
setDiscovery: () => setDiscovery,
|
|
74
|
+
setRefreshToken: () => setRefreshToken,
|
|
62
75
|
setToken: () => setToken,
|
|
63
76
|
setUserData: () => setUserData,
|
|
77
|
+
setWebConfig: () => setWebConfig,
|
|
64
78
|
signOut: () => signOut,
|
|
65
79
|
useAccount: () => useAccount,
|
|
66
80
|
useAuth: () => useAuth,
|
|
@@ -3,10 +3,11 @@ import {
|
|
|
3
3
|
} from "./chunk-7NSJ6UAV.js";
|
|
4
4
|
import {
|
|
5
5
|
tokenRefresh
|
|
6
|
-
} from "./chunk-
|
|
6
|
+
} from "./chunk-VQLMMK6U.js";
|
|
7
7
|
import {
|
|
8
8
|
getConfig,
|
|
9
9
|
getDiscovery,
|
|
10
|
+
getRefreshToken,
|
|
10
11
|
getToken,
|
|
11
12
|
getUserData,
|
|
12
13
|
resetConfig,
|
|
@@ -15,9 +16,11 @@ import {
|
|
|
15
16
|
resetUserData,
|
|
16
17
|
setConfig,
|
|
17
18
|
setDiscovery,
|
|
19
|
+
setRefreshToken,
|
|
18
20
|
setToken,
|
|
19
|
-
setUserData
|
|
20
|
-
|
|
21
|
+
setUserData,
|
|
22
|
+
useAuth
|
|
23
|
+
} from "./chunk-MA2UFH5G.js";
|
|
21
24
|
import {
|
|
22
25
|
__async
|
|
23
26
|
} from "./chunk-CWMXXUWU.js";
|
|
@@ -26,6 +29,7 @@ import {
|
|
|
26
29
|
import {
|
|
27
30
|
AuthRequest,
|
|
28
31
|
exchangeCodeAsync,
|
|
32
|
+
refreshAsync,
|
|
29
33
|
TokenResponse
|
|
30
34
|
} from "expo-auth-session";
|
|
31
35
|
import "core-js/stable/atob";
|
|
@@ -36,10 +40,13 @@ function initiateAuthenticationClient(config, discovery) {
|
|
|
36
40
|
function authenticationClientExists() {
|
|
37
41
|
return !!getConfig() && !!getDiscovery();
|
|
38
42
|
}
|
|
39
|
-
var authenticateInteractively = () => __async(
|
|
43
|
+
var authenticateInteractively = (scopes) => __async(null, null, function* () {
|
|
40
44
|
const discovery = getDiscovery();
|
|
41
45
|
const config = getConfig();
|
|
42
46
|
if (!discovery || !config) return null;
|
|
47
|
+
if (scopes) {
|
|
48
|
+
config.scopes = scopes;
|
|
49
|
+
}
|
|
43
50
|
const authRequest = new AuthRequest(config);
|
|
44
51
|
const codeResponse = yield authRequest.promptAsync(discovery);
|
|
45
52
|
if ((codeResponse == null ? void 0 : codeResponse.type) === "success") {
|
|
@@ -54,23 +61,61 @@ var authenticateInteractively = () => __async(void 0, null, function* () {
|
|
|
54
61
|
if (!userData) return null;
|
|
55
62
|
setUserData(userData);
|
|
56
63
|
setToken(tokenResponse);
|
|
64
|
+
if (tokenResponse.refreshToken) setRefreshToken(tokenResponse.refreshToken);
|
|
57
65
|
return { account: userData, accessToken: tokenResponse.accessToken };
|
|
58
66
|
}
|
|
59
67
|
return null;
|
|
60
68
|
});
|
|
61
|
-
var authenticateSilently = () => __async(
|
|
69
|
+
var authenticateSilently = (scopes) => __async(null, null, function* () {
|
|
70
|
+
yield useAuth.persist.rehydrate();
|
|
62
71
|
const userData = getUserData();
|
|
63
|
-
const token = getToken();
|
|
64
|
-
if (!userData
|
|
65
|
-
if (
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
+
const token = getToken(scopes);
|
|
73
|
+
if (!userData) return null;
|
|
74
|
+
if (token) {
|
|
75
|
+
if (TokenResponse.isTokenFresh(token)) {
|
|
76
|
+
return {
|
|
77
|
+
account: userData,
|
|
78
|
+
accessToken: token.accessToken
|
|
79
|
+
};
|
|
80
|
+
}
|
|
81
|
+
const newToken = yield tokenRefresh(token, scopes);
|
|
82
|
+
if (newToken) {
|
|
83
|
+
setToken(newToken);
|
|
84
|
+
if (newToken.refreshToken) setRefreshToken(newToken.refreshToken);
|
|
85
|
+
return {
|
|
86
|
+
account: userData,
|
|
87
|
+
accessToken: newToken.accessToken
|
|
88
|
+
};
|
|
89
|
+
}
|
|
90
|
+
const interactiveToken = yield authenticateInteractively();
|
|
91
|
+
return interactiveToken;
|
|
92
|
+
} else {
|
|
93
|
+
const refreshToken = getRefreshToken();
|
|
94
|
+
const config = getConfig();
|
|
95
|
+
const discovery = getDiscovery();
|
|
96
|
+
if (!config || !discovery) return null;
|
|
97
|
+
if (refreshToken) {
|
|
98
|
+
try {
|
|
99
|
+
const refreshed = yield refreshAsync(
|
|
100
|
+
{
|
|
101
|
+
clientId: config.clientId,
|
|
102
|
+
refreshToken,
|
|
103
|
+
scopes
|
|
104
|
+
},
|
|
105
|
+
discovery
|
|
106
|
+
);
|
|
107
|
+
setToken(refreshed);
|
|
108
|
+
if (refreshed.refreshToken) setRefreshToken(refreshed.refreshToken);
|
|
109
|
+
return {
|
|
110
|
+
account: userData,
|
|
111
|
+
accessToken: refreshed.accessToken
|
|
112
|
+
};
|
|
113
|
+
} catch (e) {
|
|
114
|
+
return null;
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
return null;
|
|
72
118
|
}
|
|
73
|
-
return null;
|
|
74
119
|
});
|
|
75
120
|
function getAccount() {
|
|
76
121
|
var _a;
|
package/dist/index.d.ts
CHANGED
|
@@ -1,5 +1,2 @@
|
|
|
1
|
-
export { authenticateInteractively, authenticateSilently, authenticationClientExists, initiateAuthenticationClient, getAccount, signOut, } from "./auth";
|
|
2
1
|
export * from "./types";
|
|
3
|
-
export * from "./components";
|
|
4
|
-
export * from "./hooks";
|
|
5
2
|
export * as ExpoAuthSession from "./Expo-AuthSession";
|
package/dist/index.js
CHANGED
|
@@ -1,51 +1,23 @@
|
|
|
1
|
-
import "./chunk-GUKC6UGZ.js";
|
|
2
|
-
import {
|
|
3
|
-
useAccount
|
|
4
|
-
} from "./chunk-RBOUHIMW.js";
|
|
5
1
|
import "./chunk-6F4PWJZI.js";
|
|
6
2
|
import {
|
|
7
3
|
Expo_AuthSession_exports
|
|
8
|
-
} from "./chunk-
|
|
9
|
-
import "./chunk-
|
|
10
|
-
import "./chunk-UYO5Y6CJ.js";
|
|
11
|
-
import "./chunk-ELBTMDOI.js";
|
|
12
|
-
import "./chunk-7KZL6S5R.js";
|
|
13
|
-
import "./chunk-PETOX4KF.js";
|
|
14
|
-
import "./chunk-52LAPG3S.js";
|
|
15
|
-
import "./chunk-W4CNNXDN.js";
|
|
16
|
-
import "./chunk-MWXZHQN3.js";
|
|
17
|
-
import "./chunk-K34WGG6L.js";
|
|
18
|
-
import "./chunk-7NSJ6UAV.js";
|
|
19
|
-
import "./chunk-FETRYEKH.js";
|
|
20
|
-
import "./chunk-IEVUSC3Q.js";
|
|
21
|
-
import "./chunk-WKE5IW37.js";
|
|
4
|
+
} from "./chunk-XYBA2PIE.js";
|
|
5
|
+
import "./chunk-DDCMUW43.js";
|
|
22
6
|
import "./chunk-NP4GJ5X5.js";
|
|
23
|
-
import "./chunk-
|
|
24
|
-
import
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
import
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
import {
|
|
31
|
-
authenticateInteractively,
|
|
32
|
-
authenticateSilently,
|
|
33
|
-
authenticationClientExists,
|
|
34
|
-
getAccount,
|
|
35
|
-
initiateAuthenticationClient,
|
|
36
|
-
signOut
|
|
37
|
-
} from "./chunk-DNMYY37N.js";
|
|
7
|
+
import "./chunk-DDBEKLVA.js";
|
|
8
|
+
import "./chunk-DSDORXK5.js";
|
|
9
|
+
import "./chunk-CFY3FFVW.js";
|
|
10
|
+
import "./chunk-H623QQTI.js";
|
|
11
|
+
import "./chunk-B7COQI7U.js";
|
|
12
|
+
import "./chunk-GRAW2VSL.js";
|
|
13
|
+
import "./chunk-MWXZHQN3.js";
|
|
38
14
|
import "./chunk-7SOSXNKP.js";
|
|
15
|
+
import "./chunk-ZMR2HMDR.js";
|
|
16
|
+
import "./chunk-7NSJ6UAV.js";
|
|
17
|
+
import "./chunk-VQLMMK6U.js";
|
|
18
|
+
import "./chunk-MA2UFH5G.js";
|
|
19
|
+
import "./chunk-AF7VKFEK.js";
|
|
39
20
|
import "./chunk-CWMXXUWU.js";
|
|
40
21
|
export {
|
|
41
|
-
Expo_AuthSession_exports as ExpoAuthSession
|
|
42
|
-
LoginButton,
|
|
43
|
-
authenticateInteractively,
|
|
44
|
-
authenticateSilently,
|
|
45
|
-
authenticationClientExists,
|
|
46
|
-
getAccount,
|
|
47
|
-
initiateAuthenticationClient,
|
|
48
|
-
signOut,
|
|
49
|
-
useAccount,
|
|
50
|
-
useAuthenticate
|
|
22
|
+
Expo_AuthSession_exports as ExpoAuthSession
|
|
51
23
|
};
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@equinor/mad-auth",
|
|
3
|
-
"description": "
|
|
4
|
-
"version": "0.
|
|
3
|
+
"description": "An authentication library that uses expo-auth-session (mobile) and @azure/msal-browser (web) under the hood",
|
|
4
|
+
"version": "0.4.0",
|
|
5
5
|
"author": {
|
|
6
6
|
"name": "Equinor Mobile App Delivery team (MAD)"
|
|
7
7
|
},
|
|
@@ -27,8 +27,8 @@
|
|
|
27
27
|
"@types/showdown": "^2.0.0",
|
|
28
28
|
"eslint": "^8.46.0",
|
|
29
29
|
"jest": "^29.7.0",
|
|
30
|
-
"jest-expo": "~
|
|
31
|
-
"react-test-renderer": "
|
|
30
|
+
"jest-expo": "~53.0.9",
|
|
31
|
+
"react-test-renderer": "19.0.0",
|
|
32
32
|
"tsup": "^8.3.5"
|
|
33
33
|
},
|
|
34
34
|
"files": [
|
|
@@ -47,12 +47,12 @@
|
|
|
47
47
|
"license": "MIT",
|
|
48
48
|
"main": "./dist/index.js",
|
|
49
49
|
"peerDependencies": {
|
|
50
|
+
"@azure/msal-browser": "3.30.0",
|
|
50
51
|
"expo-auth-session": "~6.0.0",
|
|
51
52
|
"expo-crypto": "~14.0.1",
|
|
52
|
-
"react": "
|
|
53
|
-
"react-dom": "
|
|
54
|
-
"react-native": "~0.
|
|
55
|
-
"react-native-msal": "*"
|
|
53
|
+
"react": "19.0.0",
|
|
54
|
+
"react-dom": "19.0.0",
|
|
55
|
+
"react-native": "~0.79.5"
|
|
56
56
|
},
|
|
57
57
|
"scripts": {
|
|
58
58
|
"build": "tsup-node && echo '\n ⚙️ Generating typescript declarations..' && tsc --project tsconfig.json --emitDeclarationOnly --declaration",
|