@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.
Files changed (55) hide show
  1. package/CHANGELOG.md +17 -0
  2. package/README.md +3 -24
  3. package/dist/Expo-AuthSession/authenticationHandler/auth.d.ts +2 -2
  4. package/dist/Expo-AuthSession/authenticationHandler/auth.js +4 -4
  5. package/dist/Expo-AuthSession/authenticationHandler/index.js +9 -9
  6. package/dist/Expo-AuthSession/authenticationHandler/web/authWeb.d.ts +2 -0
  7. package/dist/Expo-AuthSession/authenticationHandler/web/authWeb.js +6 -2
  8. package/dist/Expo-AuthSession/authenticationHandler/web/index.js +7 -3
  9. package/dist/Expo-AuthSession/authenticationHandler/web/publicClientApplication.d.ts +1 -1
  10. package/dist/Expo-AuthSession/authenticationHandler/web/publicClientApplication.js +1 -1
  11. package/dist/Expo-AuthSession/components/LoginButton.d.ts +12 -1
  12. package/dist/Expo-AuthSession/components/LoginButton.js +11 -11
  13. package/dist/Expo-AuthSession/hooks/useAccount.js +10 -10
  14. package/dist/Expo-AuthSession/hooks/useAuthenticate.d.ts +1 -1
  15. package/dist/Expo-AuthSession/hooks/useAuthenticate.js +10 -10
  16. package/dist/Expo-AuthSession/index.js +28 -14
  17. package/dist/Expo-AuthSession/store/authStore.d.ts +10 -2
  18. package/dist/Expo-AuthSession/store/authStore.js +16 -2
  19. package/dist/Expo-AuthSession/store/encryption.js +1 -1
  20. package/dist/Expo-AuthSession/types.d.ts +9 -2
  21. package/dist/Expo-AuthSession/utils/tokenRefresh.d.ts +1 -1
  22. package/dist/Expo-AuthSession/utils/tokenRefresh.js +3 -3
  23. package/dist/{chunk-WKE5IW37.js → chunk-AF7VKFEK.js} +20 -11
  24. package/dist/{chunk-52LAPG3S.js → chunk-B7COQI7U.js} +44 -16
  25. package/dist/{chunk-7KZL6S5R.js → chunk-CFY3FFVW.js} +4 -4
  26. package/dist/{chunk-UYO5Y6CJ.js → chunk-DDBEKLVA.js} +1 -1
  27. package/dist/{chunk-IU75T6GM.js → chunk-DDCMUW43.js} +3 -3
  28. package/dist/{chunk-ELBTMDOI.js → chunk-DSDORXK5.js} +3 -3
  29. package/dist/{chunk-W4CNNXDN.js → chunk-GRAW2VSL.js} +4 -1
  30. package/dist/{chunk-PETOX4KF.js → chunk-H623QQTI.js} +1 -1
  31. package/dist/{chunk-IEVUSC3Q.js → chunk-MA2UFH5G.js} +49 -7
  32. package/dist/{chunk-FETRYEKH.js → chunk-VQLMMK6U.js} +5 -2
  33. package/dist/{chunk-YVBJ5RPR.js → chunk-XYBA2PIE.js} +21 -7
  34. package/dist/{chunk-K34WGG6L.js → chunk-ZMR2HMDR.js} +60 -15
  35. package/dist/index.d.ts +0 -3
  36. package/dist/index.js +15 -43
  37. package/package.json +8 -8
  38. package/dist/auth.d.ts +0 -39
  39. package/dist/auth.js +0 -20
  40. package/dist/chunk-7A7RZF24.js +0 -52
  41. package/dist/chunk-DNMYY37N.js +0 -117
  42. package/dist/chunk-GUKC6UGZ.js +0 -0
  43. package/dist/chunk-HAB34YS7.js +0 -0
  44. package/dist/chunk-RBOUHIMW.js +0 -28
  45. package/dist/chunk-XENWB4ZX.js +0 -55
  46. package/dist/components/LoginButton.d.ts +0 -14
  47. package/dist/components/LoginButton.js +0 -10
  48. package/dist/components/index.d.ts +0 -1
  49. package/dist/components/index.js +0 -11
  50. package/dist/hooks/index.d.ts +0 -2
  51. package/dist/hooks/index.js +0 -14
  52. package/dist/hooks/useAccount.d.ts +0 -5
  53. package/dist/hooks/useAccount.js +0 -9
  54. package/dist/hooks/useAuthenticate.d.ts +0 -22
  55. package/dist/hooks/useAuthenticate.js +0 -9
package/dist/auth.d.ts DELETED
@@ -1,39 +0,0 @@
1
- import { MadAccount, MadAuthenticationResult } from "./types";
2
- export type InitiateAuthenticationClientConfig = {
3
- clientId: string;
4
- redirectUri: string;
5
- authority?: string;
6
- };
7
- /**
8
- * Initiate the authentication client
9
- * @param {InitiateAuthenticationClientConfig} config
10
- */
11
- export declare function initiateAuthenticationClient({ clientId, redirectUri, authority, }: InitiateAuthenticationClientConfig): Promise<void>;
12
- /**
13
- * Check if the authentication client exists
14
- * @returns {boolean} whether the authentication client exists
15
- */
16
- export declare function authenticationClientExists(): boolean;
17
- /**
18
- * Authenticate interactively. This will open an in-app browser, or the Microsoft Authenticator app if the
19
- * user has it installed
20
- * @param scopes an array of scopes
21
- * @returns {MadAuthenticationResult | null} an object containing the access token and the account, or null
22
- */
23
- export declare function authenticateInteractively(scopes: string[]): Promise<MadAuthenticationResult | null>;
24
- export declare function getAccount(): Promise<MadAccount | null>;
25
- /**
26
- * Authenticate silently.
27
- * @param scopes an array of scopes
28
- * @returns {MadAuthenticationResult | null} an object containing the access token and the account, or null
29
- */
30
- export declare function authenticateSilently(scopes: string[]): Promise<MadAuthenticationResult | null>;
31
- /**
32
- * Sign out the account.
33
- * @returns {boolean} whether we successfully signed out.
34
- */
35
- export declare function signOut(): Promise<boolean>;
36
- /**
37
- *
38
- */
39
- export declare function _reset(): void;
package/dist/auth.js DELETED
@@ -1,20 +0,0 @@
1
- import {
2
- _reset,
3
- authenticateInteractively,
4
- authenticateSilently,
5
- authenticationClientExists,
6
- getAccount,
7
- initiateAuthenticationClient,
8
- signOut
9
- } from "./chunk-DNMYY37N.js";
10
- import "./chunk-7SOSXNKP.js";
11
- import "./chunk-CWMXXUWU.js";
12
- export {
13
- _reset,
14
- authenticateInteractively,
15
- authenticateSilently,
16
- authenticationClientExists,
17
- getAccount,
18
- initiateAuthenticationClient,
19
- signOut
20
- };
@@ -1,52 +0,0 @@
1
- import {
2
- useAuthenticate
3
- } from "./chunk-XENWB4ZX.js";
4
- import {
5
- __objRest,
6
- __spreadValues
7
- } from "./chunk-CWMXXUWU.js";
8
-
9
- // src/components/LoginButton.tsx
10
- import React from "react";
11
- import { Button } from "@equinor/mad-components";
12
- var LoginButton = (_a) => {
13
- var _b = _a, {
14
- clientId,
15
- redirectUri,
16
- onAuthenticationSuccessful,
17
- onAuthenticationFailed,
18
- enableAutomaticAuthentication,
19
- scopes = [],
20
- title = "Log in"
21
- } = _b, rest = __objRest(_b, [
22
- "clientId",
23
- "redirectUri",
24
- "onAuthenticationSuccessful",
25
- "onAuthenticationFailed",
26
- "enableAutomaticAuthentication",
27
- "scopes",
28
- "title"
29
- ]);
30
- const { authenticate, authenticationInProgress, authenticationClientInitialized } = useAuthenticate({
31
- clientId,
32
- redirectUri,
33
- onAuthenticationSuccessful,
34
- onAuthenticationFailed,
35
- scopes,
36
- enableAutomaticAuthentication
37
- });
38
- const loginButtonIsDisabled = authenticationInProgress || authenticationClientInitialized == false;
39
- return /* @__PURE__ */ React.createElement(
40
- Button,
41
- __spreadValues({
42
- title,
43
- onPress: authenticate,
44
- loading: loginButtonIsDisabled,
45
- disabled: loginButtonIsDisabled
46
- }, rest)
47
- );
48
- };
49
-
50
- export {
51
- LoginButton
52
- };
@@ -1,117 +0,0 @@
1
- import {
2
- getMadAccount,
3
- getMadAuthenticationResult
4
- } from "./chunk-7SOSXNKP.js";
5
- import {
6
- __async
7
- } from "./chunk-CWMXXUWU.js";
8
-
9
- // src/auth.ts
10
- import PublicClientApplication from "react-native-msal";
11
- var pca = null;
12
- function _getMsalAccount() {
13
- return __async(this, null, function* () {
14
- if (!pca) {
15
- throw new Error("Unable to authenticate, pca is null");
16
- }
17
- const accounts = yield pca.getAccounts();
18
- if (accounts.length > 0) {
19
- const account = accounts[0];
20
- return account;
21
- }
22
- return null;
23
- });
24
- }
25
- function _getMadAccountFromMSAL() {
26
- return __async(this, null, function* () {
27
- const msalAccount = yield _getMsalAccount();
28
- if (msalAccount) return getMadAccount(msalAccount);
29
- return null;
30
- });
31
- }
32
- function initiateAuthenticationClient(_0) {
33
- return __async(this, arguments, function* ({
34
- clientId,
35
- redirectUri,
36
- authority = "https://login.microsoftonline.com/statoilsrm.onmicrosoft.com/"
37
- }) {
38
- if (authenticationClientExists()) return;
39
- const config = {
40
- auth: {
41
- authority,
42
- clientId,
43
- redirectUri
44
- },
45
- cache: { cacheLocation: "localStorage" }
46
- };
47
- pca = new PublicClientApplication(config);
48
- yield pca.init();
49
- });
50
- }
51
- function authenticationClientExists() {
52
- return !!pca;
53
- }
54
- function authenticateInteractively(scopes) {
55
- return __async(this, null, function* () {
56
- if (!pca) {
57
- throw new Error("Unable to authenticate, authentication client does not exist");
58
- }
59
- const result = yield pca.acquireToken({
60
- scopes
61
- });
62
- if (!result) return null;
63
- return getMadAuthenticationResult(result);
64
- });
65
- }
66
- function getAccount() {
67
- return __async(this, null, function* () {
68
- return _getMadAccountFromMSAL();
69
- });
70
- }
71
- function authenticateSilently(scopes) {
72
- return __async(this, null, function* () {
73
- if (!pca) {
74
- throw new Error("Unable to authenticate, authentication client does not exist");
75
- }
76
- const msalAccount = yield _getMsalAccount();
77
- if (msalAccount) {
78
- const params = {
79
- account: msalAccount,
80
- scopes,
81
- forceRefresh: false
82
- };
83
- const result = yield pca.acquireTokenSilent(params).catch((e) => {
84
- console.log("Error while fetching token silently", e);
85
- }).then((res) => res);
86
- if (!result) return null;
87
- return getMadAuthenticationResult(result);
88
- }
89
- return null;
90
- });
91
- }
92
- function signOut() {
93
- return __async(this, null, function* () {
94
- if (!pca) {
95
- throw new Error("Unable to authenticate, authentication client does not exist");
96
- }
97
- const account = yield _getMsalAccount();
98
- if (account) {
99
- const success = yield pca.removeAccount(account);
100
- return success;
101
- }
102
- return false;
103
- });
104
- }
105
- function _reset() {
106
- pca = null;
107
- }
108
-
109
- export {
110
- initiateAuthenticationClient,
111
- authenticationClientExists,
112
- authenticateInteractively,
113
- getAccount,
114
- authenticateSilently,
115
- signOut,
116
- _reset
117
- };
File without changes
File without changes
@@ -1,28 +0,0 @@
1
- import {
2
- getAccount
3
- } from "./chunk-DNMYY37N.js";
4
- import {
5
- __async
6
- } from "./chunk-CWMXXUWU.js";
7
-
8
- // src/hooks/useAccount.ts
9
- import { useEffect, useState } from "react";
10
- var useAccount = () => {
11
- const [account, setAccount] = useState();
12
- useEffect(() => {
13
- const getAndSetAccount = () => __async(void 0, null, function* () {
14
- try {
15
- const account2 = yield getAccount();
16
- setAccount(account2);
17
- } catch (e) {
18
- throw new Error("Unable to get account", { cause: e });
19
- }
20
- });
21
- void getAndSetAccount();
22
- }, []);
23
- return account;
24
- };
25
-
26
- export {
27
- useAccount
28
- };
@@ -1,55 +0,0 @@
1
- import {
2
- authenticateInteractively,
3
- authenticateSilently,
4
- authenticationClientExists,
5
- initiateAuthenticationClient
6
- } from "./chunk-DNMYY37N.js";
7
- import {
8
- __async
9
- } from "./chunk-CWMXXUWU.js";
10
-
11
- // src/hooks/useAuthenticate.ts
12
- import { useEffect, useState } from "react";
13
- var useAuthenticate = ({
14
- onAuthenticationSuccessful,
15
- onAuthenticationFailed,
16
- clientId,
17
- redirectUri,
18
- scopes,
19
- enableAutomaticAuthentication
20
- }) => {
21
- const [authenticationInProgress, setAuthenticationInProgress] = useState(false);
22
- const [authenticationClientInitialized, setAuthenticationClientInitialized] = useState(false);
23
- const withAuthenticationPromiseHandler = (promise, type) => __async(void 0, null, function* () {
24
- setAuthenticationInProgress(true);
25
- try {
26
- const res = yield promise;
27
- if (res) onAuthenticationSuccessful(res, type);
28
- } catch (e) {
29
- if (type === "MANUAL") onAuthenticationFailed(e);
30
- } finally {
31
- setAuthenticationInProgress(false);
32
- }
33
- });
34
- useEffect(() => {
35
- const initiateClientAndMaybeAuthenticateSilently = () => __async(void 0, null, function* () {
36
- yield initiateAuthenticationClient({
37
- clientId,
38
- redirectUri
39
- });
40
- if (authenticationClientExists()) setAuthenticationClientInitialized(true);
41
- if (enableAutomaticAuthentication)
42
- void withAuthenticationPromiseHandler(authenticateSilently(scopes), "AUTOMATIC");
43
- });
44
- void initiateClientAndMaybeAuthenticateSilently();
45
- }, []);
46
- return {
47
- authenticationInProgress,
48
- authenticate: () => void withAuthenticationPromiseHandler(authenticateInteractively(scopes), "MANUAL"),
49
- authenticationClientInitialized: authenticationClientExists() && authenticationClientInitialized
50
- };
51
- };
52
-
53
- export {
54
- useAuthenticate
55
- };
@@ -1,14 +0,0 @@
1
- import React from "react";
2
- import { ButtonProps } from "@equinor/mad-components";
3
- import { AuthenticationType } from "../hooks/useAuthenticate";
4
- import { MadAuthenticationResult } from "../types";
5
- export type LoginButtonProps = Omit<ButtonProps, "onPress" | "loading" | "disabled" | "title"> & {
6
- clientId: string;
7
- redirectUri: string;
8
- onAuthenticationSuccessful: (res: MadAuthenticationResult, type: AuthenticationType) => void;
9
- onAuthenticationFailed: (error: unknown) => void;
10
- title?: ButtonProps["title"];
11
- scopes?: string[];
12
- enableAutomaticAuthentication?: boolean;
13
- };
14
- export declare const LoginButton: ({ clientId, redirectUri, onAuthenticationSuccessful, onAuthenticationFailed, enableAutomaticAuthentication, scopes, title, ...rest }: LoginButtonProps) => React.JSX.Element;
@@ -1,10 +0,0 @@
1
- import {
2
- LoginButton
3
- } from "../chunk-7A7RZF24.js";
4
- import "../chunk-XENWB4ZX.js";
5
- import "../chunk-DNMYY37N.js";
6
- import "../chunk-7SOSXNKP.js";
7
- import "../chunk-CWMXXUWU.js";
8
- export {
9
- LoginButton
10
- };
@@ -1 +0,0 @@
1
- export * from "./LoginButton";
@@ -1,11 +0,0 @@
1
- import "../chunk-HAB34YS7.js";
2
- import {
3
- LoginButton
4
- } from "../chunk-7A7RZF24.js";
5
- import "../chunk-XENWB4ZX.js";
6
- import "../chunk-DNMYY37N.js";
7
- import "../chunk-7SOSXNKP.js";
8
- import "../chunk-CWMXXUWU.js";
9
- export {
10
- LoginButton
11
- };
@@ -1,2 +0,0 @@
1
- export * from "./useAccount";
2
- export * from "./useAuthenticate";
@@ -1,14 +0,0 @@
1
- import "../chunk-GUKC6UGZ.js";
2
- import {
3
- useAccount
4
- } from "../chunk-RBOUHIMW.js";
5
- import {
6
- useAuthenticate
7
- } from "../chunk-XENWB4ZX.js";
8
- import "../chunk-DNMYY37N.js";
9
- import "../chunk-7SOSXNKP.js";
10
- import "../chunk-CWMXXUWU.js";
11
- export {
12
- useAccount,
13
- useAuthenticate
14
- };
@@ -1,5 +0,0 @@
1
- import { MadAccount } from "../types";
2
- /**
3
- * get the authenticated account.
4
- */
5
- export declare const useAccount: () => MadAccount | null | undefined;
@@ -1,9 +0,0 @@
1
- import {
2
- useAccount
3
- } from "../chunk-RBOUHIMW.js";
4
- import "../chunk-DNMYY37N.js";
5
- import "../chunk-7SOSXNKP.js";
6
- import "../chunk-CWMXXUWU.js";
7
- export {
8
- useAccount
9
- };
@@ -1,22 +0,0 @@
1
- import { MadAuthenticationResult } from "../types";
2
- export type UseAuthenticateProps = {
3
- onAuthenticationSuccessful: (res: MadAuthenticationResult, type: AuthenticationType) => void;
4
- onAuthenticationFailed: (error: unknown) => void;
5
- redirectUri: string;
6
- clientId: string;
7
- scopes: string[];
8
- enableAutomaticAuthentication?: boolean;
9
- };
10
- export type AuthenticationType = "AUTOMATIC" | "MANUAL";
11
- type UseAuthenticateResult = {
12
- authenticate: () => void;
13
- authenticationInProgress: boolean;
14
- authenticationClientInitialized: boolean;
15
- };
16
- /**
17
- * initialize the authentication client, and authenticate the user
18
- * @param {UseAuthenticateProps} params params for client initialization and authentication flow
19
- * @returns authenticate function, and some helper variables
20
- */
21
- export declare const useAuthenticate: ({ onAuthenticationSuccessful, onAuthenticationFailed, clientId, redirectUri, scopes, enableAutomaticAuthentication, }: UseAuthenticateProps) => UseAuthenticateResult;
22
- export {};
@@ -1,9 +0,0 @@
1
- import {
2
- useAuthenticate
3
- } from "../chunk-XENWB4ZX.js";
4
- import "../chunk-DNMYY37N.js";
5
- import "../chunk-7SOSXNKP.js";
6
- import "../chunk-CWMXXUWU.js";
7
- export {
8
- useAuthenticate
9
- };