@equinor/mad-auth 0.1.24 → 0.2.1

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 (64) hide show
  1. package/CHANGELOG.md +16 -0
  2. package/dist/Expo-AuthSession/authenticationHandler/auth.d.ts +32 -0
  3. package/dist/Expo-AuthSession/authenticationHandler/auth.js +23 -0
  4. package/dist/Expo-AuthSession/authenticationHandler/index.d.ts +8 -0
  5. package/dist/Expo-AuthSession/authenticationHandler/index.js +31 -0
  6. package/dist/Expo-AuthSession/authenticationHandler/web/authWeb.d.ts +39 -0
  7. package/dist/Expo-AuthSession/authenticationHandler/web/authWeb.js +22 -0
  8. package/dist/Expo-AuthSession/authenticationHandler/web/index.d.ts +4 -0
  9. package/dist/Expo-AuthSession/authenticationHandler/web/index.js +33 -0
  10. package/dist/Expo-AuthSession/authenticationHandler/web/publicClientApplication.d.ts +13 -0
  11. package/dist/Expo-AuthSession/authenticationHandler/web/publicClientApplication.js +8 -0
  12. package/dist/Expo-AuthSession/authenticationHandler/web/types.d.ts +304 -0
  13. package/dist/Expo-AuthSession/authenticationHandler/web/types.js +11 -0
  14. package/dist/Expo-AuthSession/components/LoginButton.d.ts +4 -0
  15. package/dist/Expo-AuthSession/components/LoginButton.js +19 -0
  16. package/dist/Expo-AuthSession/hooks/useAccount.d.ts +2 -0
  17. package/dist/Expo-AuthSession/hooks/useAccount.js +18 -0
  18. package/dist/Expo-AuthSession/hooks/useAuthenticate.d.ts +20 -0
  19. package/dist/Expo-AuthSession/hooks/useAuthenticate.js +18 -0
  20. package/dist/Expo-AuthSession/index.d.ts +6 -0
  21. package/dist/Expo-AuthSession/index.js +72 -0
  22. package/dist/Expo-AuthSession/store/authStore.d.ts +36 -0
  23. package/dist/Expo-AuthSession/store/authStore.js +32 -0
  24. package/dist/Expo-AuthSession/store/encryption.d.ts +4 -0
  25. package/dist/Expo-AuthSession/store/encryption.js +11 -0
  26. package/dist/Expo-AuthSession/types.d.ts +16 -0
  27. package/dist/Expo-AuthSession/types.js +1 -0
  28. package/dist/Expo-AuthSession/utils/decodeToken.d.ts +8 -0
  29. package/dist/Expo-AuthSession/utils/decodeToken.js +7 -0
  30. package/dist/Expo-AuthSession/utils/tokenRefresh.d.ts +2 -0
  31. package/dist/Expo-AuthSession/utils/tokenRefresh.js +9 -0
  32. package/dist/_internal/translationLayer.d.ts +1 -1
  33. package/dist/_internal/translationLayer.js +2 -1
  34. package/dist/auth.d.ts +4 -0
  35. package/dist/auth.js +5 -2
  36. package/dist/chunk-2APLN7PB.js +63 -0
  37. package/dist/chunk-5WASXW2G.js +49 -0
  38. package/dist/chunk-6Q5OCWP7.js +21 -0
  39. package/dist/chunk-6UTWP7VI.js +123 -0
  40. package/dist/{chunk-ZTEWSERJ.js → chunk-7FYKB6SB.js} +2 -2
  41. package/dist/chunk-7SOSXNKP.js +17 -0
  42. package/dist/{chunk-HIGCNJNC.js → chunk-AD532AOW.js} +2 -2
  43. package/dist/chunk-D7L44FRV.js +17 -0
  44. package/dist/chunk-DXZ4T5LX.js +87 -0
  45. package/dist/chunk-FF7UDUOZ.js +33 -0
  46. package/dist/chunk-GCVP36UH.js +10 -0
  47. package/dist/chunk-MWXZHQN3.js +36 -0
  48. package/dist/chunk-NP4GJ5X5.js +0 -0
  49. package/dist/chunk-OFQ6U2BU.js +103 -0
  50. package/dist/chunk-RJMLROQP.js +37 -0
  51. package/dist/{chunk-UT6IGOV7.js → chunk-TTVDYDVO.js} +9 -3
  52. package/dist/{chunk-763B4HQC.js → chunk-WEAGW6MQ.js} +10 -16
  53. package/dist/chunk-WQQ3TZZU.js +127 -0
  54. package/dist/{chunk-GCZJ767T.js → chunk-XAS776NQ.js} +2 -2
  55. package/dist/chunk-XHVESUQ2.js +60 -0
  56. package/dist/chunk-YFQJZFRR.js +72 -0
  57. package/dist/components/LoginButton.js +5 -4
  58. package/dist/components/index.js +5 -4
  59. package/dist/hooks/index.js +7 -6
  60. package/dist/hooks/useAccount.js +4 -3
  61. package/dist/hooks/useAuthenticate.js +4 -3
  62. package/dist/index.d.ts +2 -1
  63. package/dist/index.js +27 -8
  64. package/package.json +66 -46
@@ -0,0 +1,72 @@
1
+ import "../chunk-YFQJZFRR.js";
2
+ import {
3
+ LoginButton
4
+ } from "../chunk-XHVESUQ2.js";
5
+ import {
6
+ useAccount
7
+ } from "../chunk-RJMLROQP.js";
8
+ import {
9
+ useAuthenticate
10
+ } from "../chunk-2APLN7PB.js";
11
+ import {
12
+ authenticateInteractively,
13
+ authenticateSilently,
14
+ authenticationClientExists,
15
+ initiateAuthenticationClient,
16
+ signOut
17
+ } from "../chunk-FF7UDUOZ.js";
18
+ import "../chunk-GCVP36UH.js";
19
+ import {
20
+ getAccountWeb
21
+ } from "../chunk-6UTWP7VI.js";
22
+ import "../chunk-WQQ3TZZU.js";
23
+ import "../chunk-MWXZHQN3.js";
24
+ import {
25
+ getAccount
26
+ } from "../chunk-OFQ6U2BU.js";
27
+ import "../chunk-D7L44FRV.js";
28
+ import "../chunk-6Q5OCWP7.js";
29
+ import {
30
+ getConfig,
31
+ getDiscovery,
32
+ getToken,
33
+ getUserData,
34
+ resetConfig,
35
+ resetDiscovery,
36
+ resetToken,
37
+ resetUserData,
38
+ setConfig,
39
+ setDiscovery,
40
+ setToken,
41
+ setUserData,
42
+ useAuth
43
+ } from "../chunk-DXZ4T5LX.js";
44
+ import "../chunk-5WASXW2G.js";
45
+ import "../chunk-NP4GJ5X5.js";
46
+ import "../chunk-7SOSXNKP.js";
47
+ import "../chunk-WEAGW6MQ.js";
48
+ export {
49
+ LoginButton,
50
+ authenticateInteractively,
51
+ authenticateSilently,
52
+ authenticationClientExists,
53
+ getAccount,
54
+ getAccountWeb,
55
+ getConfig,
56
+ getDiscovery,
57
+ getToken,
58
+ getUserData,
59
+ initiateAuthenticationClient,
60
+ resetConfig,
61
+ resetDiscovery,
62
+ resetToken,
63
+ resetUserData,
64
+ setConfig,
65
+ setDiscovery,
66
+ setToken,
67
+ setUserData,
68
+ signOut,
69
+ useAccount,
70
+ useAuth,
71
+ useAuthenticate
72
+ };
@@ -0,0 +1,36 @@
1
+ import { AuthRequestConfig, DiscoveryDocument, TokenResponse } from "expo-auth-session";
2
+ import { AuthState } from "../types";
3
+ import { MadAccount } from "../../types";
4
+ /**
5
+ * Creates a zustand store with all the relevant values for authentication handling. Token and user info is persisted
6
+ */
7
+ export declare const useAuth: import("zustand").UseBoundStore<Omit<Omit<import("zustand").StoreApi<AuthState>, "setState"> & {
8
+ setState<A extends string | {
9
+ type: string;
10
+ }>(partial: AuthState | Partial<AuthState> | ((state: AuthState) => AuthState | Partial<AuthState>), replace?: boolean | undefined, action?: A | undefined): void;
11
+ }, "persist"> & {
12
+ persist: {
13
+ setOptions: (options: Partial<import("zustand/middleware").PersistOptions<AuthState, unknown>>) => void;
14
+ clearStorage: () => void;
15
+ rehydrate: () => void | Promise<void>;
16
+ hasHydrated: () => boolean;
17
+ onHydrate: (fn: (state: AuthState) => void) => () => void;
18
+ onFinishHydration: (fn: (state: AuthState) => void) => () => void;
19
+ getOptions: () => Partial<import("zustand/middleware").PersistOptions<AuthState, unknown>>;
20
+ };
21
+ }>;
22
+ /**
23
+ * We avoid using hooks for backwards compatibility so these are all methods to interact with the store without the use of hooks.
24
+ */
25
+ export declare const getToken: () => TokenResponse | undefined;
26
+ export declare const getUserData: () => MadAccount | undefined;
27
+ export declare const getDiscovery: () => DiscoveryDocument | null | undefined;
28
+ export declare const getConfig: () => AuthRequestConfig | undefined;
29
+ export declare const setToken: (token: TokenResponse) => void;
30
+ export declare const setUserData: (userData: MadAccount) => void;
31
+ export declare const setDiscovery: (discovery: DiscoveryDocument) => void;
32
+ export declare const setConfig: (config: AuthRequestConfig) => void;
33
+ export declare const resetToken: () => void;
34
+ export declare const resetUserData: () => void;
35
+ export declare const resetDiscovery: () => void;
36
+ export declare const resetConfig: () => void;
@@ -0,0 +1,32 @@
1
+ import {
2
+ getConfig,
3
+ getDiscovery,
4
+ getToken,
5
+ getUserData,
6
+ resetConfig,
7
+ resetDiscovery,
8
+ resetToken,
9
+ resetUserData,
10
+ setConfig,
11
+ setDiscovery,
12
+ setToken,
13
+ setUserData,
14
+ useAuth
15
+ } from "../../chunk-DXZ4T5LX.js";
16
+ import "../../chunk-5WASXW2G.js";
17
+ import "../../chunk-WEAGW6MQ.js";
18
+ export {
19
+ getConfig,
20
+ getDiscovery,
21
+ getToken,
22
+ getUserData,
23
+ resetConfig,
24
+ resetDiscovery,
25
+ resetToken,
26
+ resetUserData,
27
+ setConfig,
28
+ setDiscovery,
29
+ setToken,
30
+ setUserData,
31
+ useAuth
32
+ };
@@ -0,0 +1,4 @@
1
+ import "react-native-get-random-values";
2
+ export declare const getItem: (key: string) => Promise<string | null>;
3
+ export declare const removeItem: (key: string) => Promise<void>;
4
+ export declare const setItem: (key: string, value: string) => Promise<void>;
@@ -0,0 +1,11 @@
1
+ import {
2
+ getItem,
3
+ removeItem,
4
+ setItem
5
+ } from "../../chunk-5WASXW2G.js";
6
+ import "../../chunk-WEAGW6MQ.js";
7
+ export {
8
+ getItem,
9
+ removeItem,
10
+ setItem
11
+ };
@@ -0,0 +1,16 @@
1
+ import { AuthRequestConfig, DiscoveryDocument, TokenResponse, TokenResponseConfig } from "expo-auth-session";
2
+ import { MadAccount } from "../types";
3
+ export type AuthState = {
4
+ token?: TokenResponseConfig;
5
+ setToken: (token: TokenResponse) => void;
6
+ resetToken: () => void;
7
+ userData?: MadAccount;
8
+ setUserData: (account: MadAccount) => void;
9
+ resetUserData: () => void;
10
+ discovery?: DiscoveryDocument | null;
11
+ setDiscovery: (discovery: DiscoveryDocument | null) => void;
12
+ resetDiscovery: () => void;
13
+ config?: AuthRequestConfig;
14
+ setConfig: (config: AuthRequestConfig) => void;
15
+ resetConfig: () => void;
16
+ };
@@ -0,0 +1 @@
1
+ import "../chunk-NP4GJ5X5.js";
@@ -0,0 +1,8 @@
1
+ import { MadAccount } from "../../types";
2
+ /**
3
+ * For some reason we are unable to exchange the id token for user data.
4
+ * Instead, we decode the access token get the user info from there
5
+ * @param token
6
+ * @return account {MadAccount} -- the logged-in user info
7
+ */
8
+ export declare const decodeToken: (token: string | undefined) => MadAccount | undefined;
@@ -0,0 +1,7 @@
1
+ import {
2
+ decodeToken
3
+ } from "../../chunk-D7L44FRV.js";
4
+ import "../../chunk-WEAGW6MQ.js";
5
+ export {
6
+ decodeToken
7
+ };
@@ -0,0 +1,2 @@
1
+ import { TokenResponse } from "expo-auth-session";
2
+ export declare const tokenRefresh: (token: TokenResponse) => Promise<TokenResponse | undefined>;
@@ -0,0 +1,9 @@
1
+ import {
2
+ tokenRefresh
3
+ } from "../../chunk-6Q5OCWP7.js";
4
+ import "../../chunk-DXZ4T5LX.js";
5
+ import "../../chunk-5WASXW2G.js";
6
+ import "../../chunk-WEAGW6MQ.js";
7
+ export {
8
+ tokenRefresh
9
+ };
@@ -1,4 +1,4 @@
1
- import { MSALAccount, MSALResult } from "react-native-msal";
1
+ import { MSALAccount, MSALResult } from "../Expo-AuthSession";
2
2
  import { MadAccount, MadAuthenticationResult } from "../types";
3
3
  export declare const getMadAccount: (account: MSALAccount) => MadAccount;
4
4
  export declare const getMadAuthenticationResult: (result: MSALResult) => MadAuthenticationResult;
@@ -1,7 +1,8 @@
1
1
  import {
2
2
  getMadAccount,
3
3
  getMadAuthenticationResult
4
- } from "../chunk-763B4HQC.js";
4
+ } from "../chunk-7SOSXNKP.js";
5
+ import "../chunk-WEAGW6MQ.js";
5
6
  export {
6
7
  getMadAccount,
7
8
  getMadAuthenticationResult
package/dist/auth.d.ts CHANGED
@@ -33,3 +33,7 @@ export declare function authenticateSilently(scopes: string[]): Promise<MadAuthe
33
33
  * @returns {boolean} whether we successfully signed out.
34
34
  */
35
35
  export declare function signOut(): Promise<boolean>;
36
+ /**
37
+ *
38
+ */
39
+ export declare function _reset(): void;
package/dist/auth.js CHANGED
@@ -1,13 +1,16 @@
1
1
  import {
2
+ _reset,
2
3
  authenticateInteractively,
3
4
  authenticateSilently,
4
5
  authenticationClientExists,
5
6
  getAccount,
6
7
  initiateAuthenticationClient,
7
8
  signOut
8
- } from "./chunk-UT6IGOV7.js";
9
- import "./chunk-763B4HQC.js";
9
+ } from "./chunk-TTVDYDVO.js";
10
+ import "./chunk-7SOSXNKP.js";
11
+ import "./chunk-WEAGW6MQ.js";
10
12
  export {
13
+ _reset,
11
14
  authenticateInteractively,
12
15
  authenticateSilently,
13
16
  authenticationClientExists,
@@ -0,0 +1,63 @@
1
+ import {
2
+ authenticateInteractively,
3
+ authenticateSilently,
4
+ authenticationClientExists,
5
+ initiateAuthenticationClient
6
+ } from "./chunk-FF7UDUOZ.js";
7
+ import {
8
+ __async
9
+ } from "./chunk-WEAGW6MQ.js";
10
+
11
+ // src/Expo-AuthSession/hooks/useAuthenticate.ts
12
+ import { useAutoDiscovery } from "expo-auth-session";
13
+ import { useEffect, useState } from "react";
14
+ var useAuthenticate = ({
15
+ config,
16
+ onAuthenticationSuccessful,
17
+ onAuthenticationFailed,
18
+ enableAutomaticAuthentication
19
+ }) => {
20
+ const discovery = useAutoDiscovery(
21
+ "https://login.microsoftonline.com/statoilsrm.onmicrosoft.com/v2.0"
22
+ );
23
+ const [authenticationInProgress, setAuthenticationInProgress] = useState(false);
24
+ const [authenticationClientInitialized, setAuthenticationClientInitialized] = useState(false);
25
+ const withAuthenticationPromiseHandler = (promise, type) => __async(void 0, null, function* () {
26
+ setAuthenticationInProgress(true);
27
+ try {
28
+ const res = yield promise();
29
+ if (res)
30
+ onAuthenticationSuccessful(res, type);
31
+ } catch (e) {
32
+ if (type === "MANUAL")
33
+ onAuthenticationFailed(e);
34
+ } finally {
35
+ setAuthenticationInProgress(false);
36
+ }
37
+ });
38
+ useEffect(() => {
39
+ const initiateClientAndMaybeAuthenticateSilently = () => __async(void 0, null, function* () {
40
+ initiateAuthenticationClient(config, discovery);
41
+ if (authenticationClientExists())
42
+ setAuthenticationClientInitialized(true);
43
+ if (enableAutomaticAuthentication)
44
+ yield withAuthenticationPromiseHandler(
45
+ () => authenticateSilently(config.scopes),
46
+ "AUTOMATIC"
47
+ );
48
+ });
49
+ void initiateClientAndMaybeAuthenticateSilently();
50
+ }, [discovery]);
51
+ return {
52
+ authenticationInProgress,
53
+ authenticate: () => void withAuthenticationPromiseHandler(
54
+ () => authenticateInteractively(config.scopes),
55
+ "MANUAL"
56
+ ),
57
+ authenticationClientInitialized: authenticationClientExists() && authenticationClientInitialized
58
+ };
59
+ };
60
+
61
+ export {
62
+ useAuthenticate
63
+ };
@@ -0,0 +1,49 @@
1
+ import {
2
+ __async
3
+ } from "./chunk-WEAGW6MQ.js";
4
+
5
+ // src/Expo-AuthSession/store/encryption.ts
6
+ import AsyncStorage from "@react-native-async-storage/async-storage";
7
+ import * as SecureStore from "expo-secure-store";
8
+ import * as aesjs from "aes-js";
9
+ import "react-native-get-random-values";
10
+ var encrypt = (key, value) => __async(void 0, null, function* () {
11
+ const encryptionKey = crypto.getRandomValues(new Uint8Array(256 / 8));
12
+ const cipher = new aesjs.ModeOfOperation.ctr(encryptionKey, new aesjs.Counter(1));
13
+ const encryptedBytes = cipher.encrypt(aesjs.utils.utf8.toBytes(value));
14
+ yield SecureStore.setItemAsync(key, aesjs.utils.hex.fromBytes(encryptionKey));
15
+ return aesjs.utils.hex.fromBytes(encryptedBytes);
16
+ });
17
+ var decrypt = (key, value) => __async(void 0, null, function* () {
18
+ const encryptionKeyHex = yield SecureStore.getItemAsync(key);
19
+ if (!encryptionKeyHex) {
20
+ return encryptionKeyHex;
21
+ }
22
+ const cipher = new aesjs.ModeOfOperation.ctr(
23
+ aesjs.utils.hex.toBytes(encryptionKeyHex),
24
+ new aesjs.Counter(1)
25
+ );
26
+ const decryptedBytes = cipher.decrypt(aesjs.utils.hex.toBytes(value));
27
+ return aesjs.utils.utf8.fromBytes(decryptedBytes);
28
+ });
29
+ var getItem = (key) => __async(void 0, null, function* () {
30
+ const encrypted = yield AsyncStorage.getItem(key);
31
+ if (!encrypted) {
32
+ return encrypted;
33
+ }
34
+ return yield decrypt(key, encrypted);
35
+ });
36
+ var removeItem = (key) => __async(void 0, null, function* () {
37
+ yield AsyncStorage.removeItem(key);
38
+ yield SecureStore.deleteItemAsync(key);
39
+ });
40
+ var setItem = (key, value) => __async(void 0, null, function* () {
41
+ const encrypted = yield encrypt(key, value);
42
+ yield AsyncStorage.setItem(key, encrypted);
43
+ });
44
+
45
+ export {
46
+ getItem,
47
+ removeItem,
48
+ setItem
49
+ };
@@ -0,0 +1,21 @@
1
+ import {
2
+ getConfig,
3
+ getDiscovery
4
+ } from "./chunk-DXZ4T5LX.js";
5
+ import {
6
+ __async
7
+ } from "./chunk-WEAGW6MQ.js";
8
+
9
+ // src/Expo-AuthSession/utils/tokenRefresh.ts
10
+ var tokenRefresh = (token) => __async(void 0, null, function* () {
11
+ const discovery = getDiscovery();
12
+ const config = getConfig();
13
+ if (!discovery || !config) {
14
+ return;
15
+ }
16
+ return yield token.refreshAsync(config, discovery);
17
+ });
18
+
19
+ export {
20
+ tokenRefresh
21
+ };
@@ -0,0 +1,123 @@
1
+ import {
2
+ PublicClientApplication
3
+ } from "./chunk-WQQ3TZZU.js";
4
+ import {
5
+ getMadAccount,
6
+ getMadAuthenticationResult
7
+ } from "./chunk-7SOSXNKP.js";
8
+ import {
9
+ __async
10
+ } from "./chunk-WEAGW6MQ.js";
11
+
12
+ // src/Expo-AuthSession/authenticationHandler/web/authWeb.ts
13
+ var pca = null;
14
+ function _getMsalAccount() {
15
+ return __async(this, null, function* () {
16
+ if (!pca) {
17
+ throw new Error("Unable to authenticate, pca is null");
18
+ }
19
+ const accounts = yield pca.getAccounts();
20
+ if (accounts.length > 0) {
21
+ return accounts[0];
22
+ }
23
+ return null;
24
+ });
25
+ }
26
+ function _getMadAccountFromMSAL() {
27
+ return __async(this, null, function* () {
28
+ const msalAccount = yield _getMsalAccount();
29
+ if (msalAccount)
30
+ return getMadAccount(msalAccount);
31
+ return null;
32
+ });
33
+ }
34
+ function initiateAuthenticationClientWeb({
35
+ clientId,
36
+ redirectUri,
37
+ authority = "https://login.microsoftonline.com/statoilsrm.onmicrosoft.com/"
38
+ }) {
39
+ if (authenticationClientExistsWeb())
40
+ return;
41
+ const config = {
42
+ auth: {
43
+ authority,
44
+ clientId,
45
+ redirectUri
46
+ },
47
+ cache: { cacheLocation: "localStorage" }
48
+ };
49
+ pca = new PublicClientApplication(config);
50
+ pca.init();
51
+ }
52
+ function authenticationClientExistsWeb() {
53
+ return !!pca;
54
+ }
55
+ function authenticateInteractivelyWeb(scopes) {
56
+ return __async(this, null, function* () {
57
+ if (!pca) {
58
+ throw new Error("Unable to authenticate, authentication client does not exist");
59
+ }
60
+ if (!scopes) {
61
+ throw new Error("Unable to authenticate, scopes are not defined");
62
+ }
63
+ const result = yield pca.acquireToken({
64
+ scopes
65
+ });
66
+ if (!result)
67
+ return null;
68
+ return getMadAuthenticationResult(result);
69
+ });
70
+ }
71
+ function getAccountWeb() {
72
+ return __async(this, null, function* () {
73
+ return _getMadAccountFromMSAL();
74
+ });
75
+ }
76
+ function authenticateSilentlyWeb(scopes) {
77
+ return __async(this, null, function* () {
78
+ if (!pca) {
79
+ throw new Error("Unable to authenticate, authentication client does not exist");
80
+ }
81
+ const msalAccount = yield _getMsalAccount();
82
+ if (msalAccount && scopes) {
83
+ const params = {
84
+ account: msalAccount,
85
+ scopes,
86
+ forceRefresh: false
87
+ };
88
+ const result = yield pca.acquireTokenSilent(params).catch((e) => {
89
+ console.log("Error while fetching token silently", e);
90
+ }).then((res) => res);
91
+ if (!result)
92
+ return null;
93
+ return getMadAuthenticationResult(result);
94
+ }
95
+ return null;
96
+ });
97
+ }
98
+ function signOutWeb() {
99
+ return __async(this, null, function* () {
100
+ if (!pca) {
101
+ throw new Error("Unable to authenticate, authentication client does not exist");
102
+ }
103
+ const account = yield _getMsalAccount();
104
+ if (account) {
105
+ const success = yield pca.removeAccount(account);
106
+ return success;
107
+ }
108
+ return false;
109
+ });
110
+ }
111
+ function _resetWeb() {
112
+ pca = null;
113
+ }
114
+
115
+ export {
116
+ initiateAuthenticationClientWeb,
117
+ authenticationClientExistsWeb,
118
+ authenticateInteractivelyWeb,
119
+ getAccountWeb,
120
+ authenticateSilentlyWeb,
121
+ signOutWeb,
122
+ _resetWeb
123
+ };
@@ -1,9 +1,9 @@
1
1
  import {
2
2
  getAccount
3
- } from "./chunk-UT6IGOV7.js";
3
+ } from "./chunk-TTVDYDVO.js";
4
4
  import {
5
5
  __async
6
- } from "./chunk-763B4HQC.js";
6
+ } from "./chunk-WEAGW6MQ.js";
7
7
 
8
8
  // src/hooks/useAccount.ts
9
9
  import { useEffect, useState } from "react";
@@ -0,0 +1,17 @@
1
+ // src/_internal/translationLayer.ts
2
+ var getMadAccount = (account) => {
3
+ var _a;
4
+ return {
5
+ username: account.username,
6
+ name: (_a = account.claims) == null ? void 0 : _a.name,
7
+ identifier: account.identifier
8
+ };
9
+ };
10
+ var getMadAuthenticationResult = (result) => {
11
+ return { account: getMadAccount(result.account), accessToken: result.accessToken };
12
+ };
13
+
14
+ export {
15
+ getMadAccount,
16
+ getMadAuthenticationResult
17
+ };
@@ -3,10 +3,10 @@ import {
3
3
  authenticateSilently,
4
4
  authenticationClientExists,
5
5
  initiateAuthenticationClient
6
- } from "./chunk-UT6IGOV7.js";
6
+ } from "./chunk-TTVDYDVO.js";
7
7
  import {
8
8
  __async
9
- } from "./chunk-763B4HQC.js";
9
+ } from "./chunk-WEAGW6MQ.js";
10
10
 
11
11
  // src/hooks/useAuthenticate.ts
12
12
  import { useEffect, useState } from "react";
@@ -0,0 +1,17 @@
1
+ // src/Expo-AuthSession/utils/decodeToken.ts
2
+ import { jwtDecode } from "jwt-decode";
3
+ var decodeToken = (token) => {
4
+ if (!token)
5
+ return void 0;
6
+ const decoded = jwtDecode(token);
7
+ const account = {
8
+ name: decoded.name,
9
+ username: decoded.unique_name,
10
+ identifier: decoded.onprem_sid
11
+ };
12
+ return account;
13
+ };
14
+
15
+ export {
16
+ decodeToken
17
+ };
@@ -0,0 +1,87 @@
1
+ import {
2
+ getItem,
3
+ removeItem,
4
+ setItem
5
+ } from "./chunk-5WASXW2G.js";
6
+
7
+ // src/Expo-AuthSession/store/authStore.ts
8
+ import { TokenResponse } from "expo-auth-session";
9
+ import { create } from "zustand";
10
+ import { createJSONStorage, devtools, persist } from "zustand/middleware";
11
+ var useAuth = create()(
12
+ devtools(
13
+ persist(
14
+ (set) => ({
15
+ setToken: (token) => {
16
+ set({ token });
17
+ },
18
+ setUserData: (account) => {
19
+ set({ userData: account });
20
+ },
21
+ setDiscovery: (discovery) => {
22
+ set({ discovery });
23
+ },
24
+ setConfig: (config) => {
25
+ set({ config });
26
+ },
27
+ resetToken: () => {
28
+ set({ token: void 0 });
29
+ },
30
+ resetUserData: () => {
31
+ set({ userData: void 0 });
32
+ },
33
+ resetDiscovery: () => {
34
+ set({ discovery: void 0 });
35
+ },
36
+ resetConfig: () => {
37
+ set({ config: void 0 });
38
+ }
39
+ }),
40
+ {
41
+ partialize: (state) => Object.fromEntries(
42
+ Object.entries(state).filter(
43
+ ([key]) => ["token", "userData"].includes(key)
44
+ )
45
+ ),
46
+ name: "storage",
47
+ storage: createJSONStorage(() => ({
48
+ getItem,
49
+ setItem,
50
+ removeItem
51
+ }))
52
+ }
53
+ ),
54
+ { name: "core/auth" }
55
+ )
56
+ );
57
+ var getToken = () => {
58
+ const tokenConfig = useAuth.getState().token;
59
+ return tokenConfig ? new TokenResponse(tokenConfig) : void 0;
60
+ };
61
+ var getUserData = () => useAuth.getState().userData;
62
+ var getDiscovery = () => useAuth.getState().discovery;
63
+ var getConfig = () => useAuth.getState().config;
64
+ var setToken = (token) => useAuth.getState().setToken(token);
65
+ var setUserData = (userData) => useAuth.getState().setUserData(userData);
66
+ var setDiscovery = (discovery) => useAuth.getState().setDiscovery(discovery);
67
+ var setConfig = (config) => useAuth.getState().setConfig(config);
68
+ var resetToken = () => useAuth.getState().resetToken();
69
+ var resetUserData = () => useAuth.getState().resetUserData();
70
+ var resetDiscovery = () => useAuth.getState().resetDiscovery();
71
+ var resetConfig = () => useAuth.getState().resetConfig();
72
+
73
+ export {
74
+ useAuth,
75
+ getToken,
76
+ getUserData,
77
+ getDiscovery,
78
+ getConfig,
79
+ setToken,
80
+ setUserData,
81
+ setDiscovery,
82
+ setConfig,
83
+ resetToken,
84
+ resetUserData,
85
+ resetDiscovery,
86
+ resetConfig
87
+ };