react-native-msal2 1.0.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/README.md ADDED
@@ -0,0 +1,48 @@
1
+ # react-native-msal2
2
+
3
+ A plugin for React Native.
4
+
5
+ ## Installation
6
+
7
+ ```
8
+ npm i react-native-msal2
9
+ ```
10
+
11
+ ## Usage
12
+
13
+ ```jsx
14
+ import React from 'react'
15
+ import { Text } from 'react-native'
16
+ import { Msal2 } from 'react-native-msal2'
17
+
18
+ export () =>
19
+ <Msal2>
20
+ <Text>Hello Plugin</Text>
21
+ </Msal2>
22
+ ```
23
+
24
+ ## Development
25
+
26
+ ### Build
27
+
28
+ Run a single build with `npm run build` and find the output in `/dist`.
29
+
30
+ ### Tests
31
+
32
+ Tests configured for React Native can be run with `npm test` or `npm run test:watch` in watch mode.
33
+
34
+ ### Preview App
35
+
36
+ To test your plugin on a device run the following to create a React Native app using it.
37
+
38
+ ```
39
+ npm run app
40
+ cd app
41
+ npm run ios / npm run android
42
+ ```
43
+
44
+ The following command will automatically copy over changes made to the plugin to the app.
45
+
46
+ ```
47
+ npm run watch
48
+ ```
@@ -0,0 +1,3 @@
1
+ import { PublicClientApplication } from './src/publicClientApplication';
2
+ export default PublicClientApplication;
3
+ export * from './src/types';
package/dist/index.js ADDED
@@ -0,0 +1,92 @@
1
+ // src/publicClientApplication.ts
2
+ import { Platform } from "react-native";
3
+ import { NativeModules } from "react-native";
4
+ var RNMSAL = NativeModules.RNMSAL;
5
+ var PublicClientApplication = class {
6
+ constructor(config) {
7
+ this.config = config;
8
+ }
9
+ isInitialized = false;
10
+ async init() {
11
+ if (!this.isInitialized) {
12
+ await RNMSAL.createPublicClientApplication(this.config);
13
+ this.isInitialized = true;
14
+ }
15
+ return this;
16
+ }
17
+ async acquireToken(params) {
18
+ this.validateIsInitialized();
19
+ return await RNMSAL.acquireToken(params);
20
+ }
21
+ async acquireTokenSilent(params) {
22
+ this.validateIsInitialized();
23
+ return await RNMSAL.acquireTokenSilent(params);
24
+ }
25
+ async getAccounts() {
26
+ this.validateIsInitialized();
27
+ return await RNMSAL.getAccounts();
28
+ }
29
+ async getAccount(accountIdentifier) {
30
+ this.validateIsInitialized();
31
+ return await RNMSAL.getAccount(accountIdentifier);
32
+ }
33
+ async removeAccount(account) {
34
+ this.validateIsInitialized();
35
+ return await RNMSAL.removeAccount(account);
36
+ }
37
+ async signOut(params) {
38
+ this.validateIsInitialized();
39
+ return await Platform.select({
40
+ ios: async () => await RNMSAL.signout(params),
41
+ default: async () => await RNMSAL.removeAccount(params.account)
42
+ })();
43
+ }
44
+ validateIsInitialized() {
45
+ if (!this.isInitialized) {
46
+ throw new Error(
47
+ "PublicClientApplication is not initialized. You must call the `init` method before any other method."
48
+ );
49
+ }
50
+ }
51
+ };
52
+
53
+ // src/types.ts
54
+ var MSALPromptType = /* @__PURE__ */ ((MSALPromptType2) => {
55
+ MSALPromptType2[MSALPromptType2["SELECT_ACCOUNT"] = 0] = "SELECT_ACCOUNT";
56
+ MSALPromptType2[MSALPromptType2["LOGIN"] = 1] = "LOGIN";
57
+ MSALPromptType2[MSALPromptType2["CONSENT"] = 2] = "CONSENT";
58
+ MSALPromptType2[MSALPromptType2["WHEN_REQUIRED"] = 3] = "WHEN_REQUIRED";
59
+ MSALPromptType2[MSALPromptType2["DEFAULT"] = 3 /* WHEN_REQUIRED */] = "DEFAULT";
60
+ return MSALPromptType2;
61
+ })(MSALPromptType || {});
62
+ var Ios_ModalPresentationStyle = /* @__PURE__ */ ((Ios_ModalPresentationStyle2) => {
63
+ Ios_ModalPresentationStyle2[Ios_ModalPresentationStyle2["fullScreen"] = 0] = "fullScreen";
64
+ Ios_ModalPresentationStyle2[Ios_ModalPresentationStyle2["pageSheet"] = 1] = "pageSheet";
65
+ Ios_ModalPresentationStyle2[Ios_ModalPresentationStyle2["formSheet"] = 2] = "formSheet";
66
+ Ios_ModalPresentationStyle2[Ios_ModalPresentationStyle2["currentContext"] = 3] = "currentContext";
67
+ Ios_ModalPresentationStyle2[Ios_ModalPresentationStyle2["custom"] = 4] = "custom";
68
+ Ios_ModalPresentationStyle2[Ios_ModalPresentationStyle2["overFullScreen"] = 5] = "overFullScreen";
69
+ Ios_ModalPresentationStyle2[Ios_ModalPresentationStyle2["overCurrentContext"] = 6] = "overCurrentContext";
70
+ Ios_ModalPresentationStyle2[Ios_ModalPresentationStyle2["popover"] = 7] = "popover";
71
+ Ios_ModalPresentationStyle2[Ios_ModalPresentationStyle2["blurOverFullScreen"] = 8] = "blurOverFullScreen";
72
+ Ios_ModalPresentationStyle2[Ios_ModalPresentationStyle2["none"] = -1] = "none";
73
+ Ios_ModalPresentationStyle2[Ios_ModalPresentationStyle2["automatic"] = -2] = "automatic";
74
+ return Ios_ModalPresentationStyle2;
75
+ })(Ios_ModalPresentationStyle || {});
76
+ var Ios_MSALWebviewType = /* @__PURE__ */ ((Ios_MSALWebviewType2) => {
77
+ Ios_MSALWebviewType2[Ios_MSALWebviewType2["DEFAULT"] = 0] = "DEFAULT";
78
+ Ios_MSALWebviewType2[Ios_MSALWebviewType2["AUTHENTICATION_SESSION"] = 1] = "AUTHENTICATION_SESSION";
79
+ Ios_MSALWebviewType2[Ios_MSALWebviewType2["SAFARI_VIEW_CONTROLLER"] = 2] = "SAFARI_VIEW_CONTROLLER";
80
+ Ios_MSALWebviewType2[Ios_MSALWebviewType2["WK_WEB_VIEW"] = 3] = "WK_WEB_VIEW";
81
+ return Ios_MSALWebviewType2;
82
+ })(Ios_MSALWebviewType || {});
83
+
84
+ // index.tsx
85
+ var react_native_msal2_default = PublicClientApplication;
86
+ export {
87
+ Ios_MSALWebviewType,
88
+ Ios_ModalPresentationStyle,
89
+ MSALPromptType,
90
+ react_native_msal2_default as default
91
+ };
92
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../src/publicClientApplication.ts", "../src/types.ts", "../index.tsx"],
4
+ "sourcesContent": ["import { Platform } from 'react-native'\n\nimport type {\n MSALConfiguration,\n MSALInteractiveParams,\n MSALSilentParams,\n MSALAccount,\n MSALSignoutParams,\n IPublicClientApplication,\n MSALResult,\n} from './types'\n\nimport { NativeModules } from 'react-native'\n\ntype RNMSALNativeModule = {\n createPublicClientApplication(config: MSALConfiguration): Promise<void>\n acquireToken(params: MSALInteractiveParams): Promise<MSALResult | undefined>\n acquireTokenSilent(params: MSALSilentParams): Promise<MSALResult | undefined>\n getAccounts(): Promise<MSALAccount[]>\n getAccount(accountIdentifier: string): Promise<MSALAccount | undefined>\n removeAccount(account: MSALAccount): Promise<boolean>\n signout(params: MSALSignoutParams): Promise<boolean>\n}\n\nconst RNMSAL: RNMSALNativeModule = NativeModules.RNMSAL\n\nexport default RNMSAL\n\nexport class PublicClientApplication implements IPublicClientApplication {\n private isInitialized: boolean = false\n\n constructor(private readonly config: MSALConfiguration) {}\n\n public async init() {\n if (!this.isInitialized) {\n await RNMSAL.createPublicClientApplication(this.config)\n this.isInitialized = true\n }\n return this\n }\n\n public async acquireToken(params: MSALInteractiveParams) {\n this.validateIsInitialized()\n return await RNMSAL.acquireToken(params)\n }\n\n public async acquireTokenSilent(params: MSALSilentParams) {\n this.validateIsInitialized()\n return await RNMSAL.acquireTokenSilent(params)\n }\n\n public async getAccounts() {\n this.validateIsInitialized()\n return await RNMSAL.getAccounts()\n }\n\n public async getAccount(accountIdentifier: string) {\n this.validateIsInitialized()\n return await RNMSAL.getAccount(accountIdentifier)\n }\n\n public async removeAccount(account: MSALAccount) {\n this.validateIsInitialized()\n return await RNMSAL.removeAccount(account)\n }\n\n public async signOut(params: MSALSignoutParams) {\n this.validateIsInitialized()\n return await Platform.select({\n ios: async () => await RNMSAL.signout(params),\n default: async () => await RNMSAL.removeAccount(params.account),\n })()\n }\n\n private validateIsInitialized() {\n if (!this.isInitialized) {\n throw new Error(\n 'PublicClientApplication is not initialized. You must call the `init` method before any other method.',\n )\n }\n }\n}\n", "export interface IPublicClientApplication {\n /**\n * Acquire a token interactively\n * @param {MSALInteractiveParams} params\n * @return Result containing an access token and account identifier\n * used for acquiring subsequent tokens silently\n */\n acquireToken(params: MSALInteractiveParams): Promise<MSALResult | undefined>\n\n /**\n * Acquire a token silently\n * @param {MSALSilentParams} params - Includes the account identifer retrieved from a\n * previous interactive login\n * @return Result containing an access token and account identifier\n * used for acquiring subsequent tokens silently\n */\n acquireTokenSilent(params: MSALSilentParams): Promise<MSALResult | undefined>\n\n /**\n * Get all accounts for which this application has refresh tokens\n * @return Promise containing array of MSALAccount objects for which this application\n * has refresh tokens.\n */\n getAccounts(): Promise<MSALAccount[]>\n\n /**\n * Retrieve the account matching the identifier\n * @return Promise containing MSALAccount object\n */\n getAccount(accountIdentifier: string): Promise<MSALAccount | undefined>\n\n /**\n * Removes all tokens from the cache for this application for the provided\n * account.\n * @param {MSALAccount} account\n * @return A promise containing a boolean = true if account removal was successful\n * otherwise rejects\n */\n removeAccount(account: MSALAccount): Promise<boolean>\n\n /**\n * Removes all tokens from the cache for this application for the provided\n * account. Additionally, this will remove the account from the system browser.\n * NOTE: iOS only. On Android and web this is the same as `removeAccount`.\n * @param {MSALSignoutParams} params\n * @return A promise which resolves if sign out is successful,\n * otherwise rejects\n * @platform ios\n */\n signOut(params: MSALSignoutParams): Promise<boolean>\n}\n\nexport interface MSALConfiguration {\n auth: {\n /**\n * The client ID of the application, this should come from the app developer portal.\n */\n clientId: string\n /**\n * The authority the application will use to obtain tokens.\n */\n authority?: string\n /**\n * List of known authorities that the application should trust.\n */\n knownAuthorities?: string[]\n /**\n * The redirect URI of the application.\n *\n * If you are providing this property, you should probably use `Platform.select`,\n * because the redirect uris will be different for each platform.\n */\n redirectUri?: string\n }\n /**\n * Options as described here: {@link https://docs.microsoft.com/en-us/azure/active-directory/develop/msal-configuration}\n * @platform android\n */\n androidConfigOptions?: MSALAndroidConfigOptions\n}\n\nexport interface MSALAndroidConfigOptions {\n authorization_user_agent?: 'DEFAULT' | 'BROWSER' | 'WEBVIEW'\n broker_redirect_uri_registered?: boolean\n browser_safelist?: {\n browser_package_name: string\n browser_signature_hashes: string[]\n browser_use_customTab: boolean\n }[]\n http?: {\n connect_timeout?: number\n read_timeout?: number\n }\n logging?: {\n pii_enabled?: boolean\n log_level?: 'ERROR' | 'WARNING' | 'INFO' | 'VERBOSE'\n logcat_enabled?: boolean\n }\n multiple_clouds_supported?: boolean\n}\n\nexport interface MSALInteractiveParams {\n /**\n * Permissions you want included in the access token received in the result.\n * Not all scopes are guaranteed to be included in the access token returned.\n */\n scopes: string[]\n /**\n * The authority that MSAL will use to obtain tokens. If not included, authority from\n * MSALConfiguration will be used.\n */\n authority?: string\n /**\n * A specific prompt type for the interactive authentication flow.\n */\n promptType?: MSALPromptType\n /**\n * A loginHint (usually an email) to pass to the service at the beginning of the\n * interactive authentication flow. The account returned is not guaranteed to match\n * the loginHint.\n */\n loginHint?: string\n /**\n * Key-value pairs to pass to the /authorize and /token endpoints.\n */\n extraQueryParameters?: Record<string, string>\n /**\n * Permissions you want the account to consent to in the same authentication flow,\n * but won\u2019t be included in the returned access token.\n */\n extraScopesToConsent?: string[]\n /**\n * User Interface configuration that MSAL uses when getting a token interactively or\n * authorizing an end user.\n */\n webviewParameters?: MSALWebviewParams\n}\n\n/**\n * OIDC prompt parameter that specifies whether the Authorization Server prompts the\n * End-User for reauthentication and consent.\n */\nexport enum MSALPromptType {\n /**\n * If no user is specified the authentication webview will present a list of users\n * currently signed in for the user to select among.\n */\n SELECT_ACCOUNT,\n /**\n * Require the user to authenticate in the webview.\n */\n LOGIN,\n /**\n * Require the user to consent to the current set of scopes for the request.\n */\n CONSENT,\n /**\n * The SSO experience will be determined by the presence of cookies in the webview and\n * account type. User won\u2019t be prompted unless necessary. If multiple users are signed in,\n * select account experience will be presented.\n */\n WHEN_REQUIRED,\n /**\n * Default is MSALPromptType.WHEN_REQUIRED.\n */\n DEFAULT = WHEN_REQUIRED,\n}\n\nexport interface MSALSilentParams {\n /**\n * Permissions you want included in the access token received in the result.\n * Not all scopes are guaranteed to be included in the access token returned.\n */\n scopes: string[]\n /**\n * An account object for which tokens should be returned.\n */\n account: MSALAccount\n /**\n * The authority that MSAL will use to obtain tokens. If not included, authority from\n * MSALConfiguration will be used.\n */\n authority?: string\n /**\n * Ignore any existing access token in the cache and force MSAL to get a new access token\n * from the service.\n */\n forceRefresh?: boolean\n}\n\nexport interface MSALSignoutParams {\n /**\n * The account object for which to sign out of.\n */\n account: MSALAccount\n /**\n * Specifies whether signout should also open the browser and send a network request to the end_session_endpoint.\n * false by default.\n */\n signoutFromBrowser?: boolean\n /**\n * User Interface configuration that MSAL uses when getting a token interactively or\n * authorizing an end user.\n */\n webviewParameters?: MSALWebviewParams\n}\n\nexport interface MSALResult {\n /**\n * The Access Token requested, or empty string if no access token is returned in response\n */\n accessToken: string\n /**\n * The account object that holds account information.\n */\n account: MSALAccount\n /**\n * The time that the access token returned in the accessToken property ceases to be valid.\n * This value is calculated based on current UTC time measured locally and the value expiresIn returned from the service\n */\n expiresOn: number\n /**\n * The raw id token if it\u2019s returned by the service or undefined if no id token is returned.\n */\n idToken?: string\n /**\n * The scope values returned from the service.\n */\n scopes: string[]\n /**\n * Identifier for the directory where account is locally represented\n */\n tenantId?: string\n}\n\nexport interface MSALAccount {\n /**\n * Unique identifier for the account.\n */\n identifier: string\n /**\n * Host part of the authority string used for authentication based on the issuer identifier.\n */\n environment?: string\n /**\n * An identifier for the AAD tenant that the account was acquired from.\n */\n tenantId: string\n /**\n * Shorthand name by which the End-User wishes to be referred to at the RP, such as janedoe or j.doe.\n */\n username: string\n /**\n * ID token claims for the account. Can be used to read additional information about the account, e.g. name.\n */\n claims?: object\n}\n\n/**\n * Mostly, if not all, iOS webview parameters\n * See https://azuread.github.io/microsoft-authentication-library-for-objc/Classes/MSALWebviewParameters.html\n */\nexport interface MSALWebviewParams {\n /**\n * A Boolean value that indicates whether the ASWebAuthenticationSession should ask the\n * browser for a private authentication session.\n * For more info see here: https://developer.apple.com/documentation/authenticationservices/aswebauthenticationsession/3237231-prefersephemeralwebbrowsersessio?language=objc\n * @platform iOS 13+\n */\n ios_prefersEphemeralWebBrowserSession?: boolean\n /**\n * MSAL requires a web browser for interactive authentication.\n * There are multiple web browsers available to complete authentication.\n * MSAL will default to the web browser that provides best security and user experience for a given platform.\n * Ios_MSALWebviewType allows changing the experience by customizing the configuration to other options for\n * displaying web content\n * @platform iOS\n */\n ios_webviewType?: Ios_MSALWebviewType\n /**\n * Note: Has no effect when ios_webviewType === `Ios_MSALWebviewType.DEFAULT` or\n * ios_webviewType === `Ios_MSALWebviewType.AUTHENTICATION_SESSION`\n * @platform iOS\n */\n ios_presentationStyle?: Ios_ModalPresentationStyle\n}\n\n/**\n * See https://developer.apple.com/documentation/uikit/uimodalpresentationstyle\n */\nexport enum Ios_ModalPresentationStyle {\n fullScreen = 0,\n pageSheet,\n formSheet,\n currentContext,\n custom,\n overFullScreen,\n overCurrentContext,\n popover,\n blurOverFullScreen,\n none = -1,\n automatic = -2,\n}\n\n/**\n * See https://azuread.github.io/microsoft-authentication-library-for-objc/Enums/MSALWebviewType.html\n */\nexport enum Ios_MSALWebviewType {\n DEFAULT = 0,\n AUTHENTICATION_SESSION,\n SAFARI_VIEW_CONTROLLER,\n WK_WEB_VIEW,\n}\n", "import { PublicClientApplication } from './src/publicClientApplication'\nexport default PublicClientApplication\nexport * from './src/types'\n"],
5
+ "mappings": ";AAAA,SAAS,gBAAgB;AAYzB,SAAS,qBAAqB;AAY9B,IAAM,SAA6B,cAAc;AAI1C,IAAM,0BAAN,MAAkE;AAAA,EAGvE,YAA6B,QAA2B;AAA3B;AAAA,EAA4B;AAAA,EAFjD,gBAAyB;AAAA,EAIjC,MAAa,OAAO;AAClB,QAAI,CAAC,KAAK,eAAe;AACvB,YAAM,OAAO,8BAA8B,KAAK,MAAM;AACtD,WAAK,gBAAgB;AAAA,IACvB;AACA,WAAO;AAAA,EACT;AAAA,EAEA,MAAa,aAAa,QAA+B;AACvD,SAAK,sBAAsB;AAC3B,WAAO,MAAM,OAAO,aAAa,MAAM;AAAA,EACzC;AAAA,EAEA,MAAa,mBAAmB,QAA0B;AACxD,SAAK,sBAAsB;AAC3B,WAAO,MAAM,OAAO,mBAAmB,MAAM;AAAA,EAC/C;AAAA,EAEA,MAAa,cAAc;AACzB,SAAK,sBAAsB;AAC3B,WAAO,MAAM,OAAO,YAAY;AAAA,EAClC;AAAA,EAEA,MAAa,WAAW,mBAA2B;AACjD,SAAK,sBAAsB;AAC3B,WAAO,MAAM,OAAO,WAAW,iBAAiB;AAAA,EAClD;AAAA,EAEA,MAAa,cAAc,SAAsB;AAC/C,SAAK,sBAAsB;AAC3B,WAAO,MAAM,OAAO,cAAc,OAAO;AAAA,EAC3C;AAAA,EAEA,MAAa,QAAQ,QAA2B;AAC9C,SAAK,sBAAsB;AAC3B,WAAO,MAAM,SAAS,OAAO;AAAA,MAC3B,KAAK,YAAY,MAAM,OAAO,QAAQ,MAAM;AAAA,MAC5C,SAAS,YAAY,MAAM,OAAO,cAAc,OAAO,OAAO;AAAA,IAChE,CAAC,EAAE;AAAA,EACL;AAAA,EAEQ,wBAAwB;AAC9B,QAAI,CAAC,KAAK,eAAe;AACvB,YAAM,IAAI;AAAA,QACR;AAAA,MACF;AAAA,IACF;AAAA,EACF;AACF;;;AC6DO,IAAK,iBAAL,kBAAKA,oBAAL;AAKL,EAAAA,gCAAA;AAIA,EAAAA,gCAAA;AAIA,EAAAA,gCAAA;AAMA,EAAAA,gCAAA;AAIA,EAAAA,gCAAA,aAAU,yBAAV;AAvBU,SAAAA;AAAA,GAAA;AAoJL,IAAK,6BAAL,kBAAKC,gCAAL;AACL,EAAAA,wDAAA,gBAAa,KAAb;AACA,EAAAA,wDAAA;AACA,EAAAA,wDAAA;AACA,EAAAA,wDAAA;AACA,EAAAA,wDAAA;AACA,EAAAA,wDAAA;AACA,EAAAA,wDAAA;AACA,EAAAA,wDAAA;AACA,EAAAA,wDAAA;AACA,EAAAA,wDAAA,UAAO,MAAP;AACA,EAAAA,wDAAA,eAAY,MAAZ;AAXU,SAAAA;AAAA,GAAA;AAiBL,IAAK,sBAAL,kBAAKC,yBAAL;AACL,EAAAA,0CAAA,aAAU,KAAV;AACA,EAAAA,0CAAA;AACA,EAAAA,0CAAA;AACA,EAAAA,0CAAA;AAJU,SAAAA;AAAA,GAAA;;;AClTZ,IAAO,6BAAQ;",
6
+ "names": ["MSALPromptType", "Ios_ModalPresentationStyle", "Ios_MSALWebviewType"]
7
+ }
@@ -0,0 +1,25 @@
1
+ import type { MSALConfiguration, MSALInteractiveParams, MSALSilentParams, MSALAccount, MSALSignoutParams, IPublicClientApplication, MSALResult } from './types';
2
+ type RNMSALNativeModule = {
3
+ createPublicClientApplication(config: MSALConfiguration): Promise<void>;
4
+ acquireToken(params: MSALInteractiveParams): Promise<MSALResult | undefined>;
5
+ acquireTokenSilent(params: MSALSilentParams): Promise<MSALResult | undefined>;
6
+ getAccounts(): Promise<MSALAccount[]>;
7
+ getAccount(accountIdentifier: string): Promise<MSALAccount | undefined>;
8
+ removeAccount(account: MSALAccount): Promise<boolean>;
9
+ signout(params: MSALSignoutParams): Promise<boolean>;
10
+ };
11
+ declare const RNMSAL: RNMSALNativeModule;
12
+ export default RNMSAL;
13
+ export declare class PublicClientApplication implements IPublicClientApplication {
14
+ private readonly config;
15
+ private isInitialized;
16
+ constructor(config: MSALConfiguration);
17
+ init(): Promise<this>;
18
+ acquireToken(params: MSALInteractiveParams): Promise<MSALResult | undefined>;
19
+ acquireTokenSilent(params: MSALSilentParams): Promise<MSALResult | undefined>;
20
+ getAccounts(): Promise<MSALAccount[]>;
21
+ getAccount(accountIdentifier: string): Promise<MSALAccount | undefined>;
22
+ removeAccount(account: MSALAccount): Promise<boolean>;
23
+ signOut(params: MSALSignoutParams): Promise<boolean>;
24
+ private validateIsInitialized;
25
+ }
@@ -0,0 +1,297 @@
1
+ export interface IPublicClientApplication {
2
+ /**
3
+ * Acquire a token interactively
4
+ * @param {MSALInteractiveParams} params
5
+ * @return Result containing an access token and account identifier
6
+ * used for acquiring subsequent tokens silently
7
+ */
8
+ acquireToken(params: MSALInteractiveParams): Promise<MSALResult | undefined>;
9
+ /**
10
+ * Acquire a token silently
11
+ * @param {MSALSilentParams} params - Includes the account identifer retrieved from a
12
+ * previous interactive login
13
+ * @return Result containing an access token and account identifier
14
+ * used for acquiring subsequent tokens silently
15
+ */
16
+ acquireTokenSilent(params: MSALSilentParams): Promise<MSALResult | undefined>;
17
+ /**
18
+ * Get all accounts for which this application has refresh tokens
19
+ * @return Promise containing array of MSALAccount objects for which this application
20
+ * has refresh tokens.
21
+ */
22
+ getAccounts(): Promise<MSALAccount[]>;
23
+ /**
24
+ * Retrieve the account matching the identifier
25
+ * @return Promise containing MSALAccount object
26
+ */
27
+ getAccount(accountIdentifier: string): Promise<MSALAccount | undefined>;
28
+ /**
29
+ * Removes all tokens from the cache for this application for the provided
30
+ * account.
31
+ * @param {MSALAccount} account
32
+ * @return A promise containing a boolean = true if account removal was successful
33
+ * otherwise rejects
34
+ */
35
+ removeAccount(account: MSALAccount): Promise<boolean>;
36
+ /**
37
+ * Removes all tokens from the cache for this application for the provided
38
+ * account. Additionally, this will remove the account from the system browser.
39
+ * NOTE: iOS only. On Android and web this is the same as `removeAccount`.
40
+ * @param {MSALSignoutParams} params
41
+ * @return A promise which resolves if sign out is successful,
42
+ * otherwise rejects
43
+ * @platform ios
44
+ */
45
+ signOut(params: MSALSignoutParams): Promise<boolean>;
46
+ }
47
+ export interface MSALConfiguration {
48
+ auth: {
49
+ /**
50
+ * The client ID of the application, this should come from the app developer portal.
51
+ */
52
+ clientId: string;
53
+ /**
54
+ * The authority the application will use to obtain tokens.
55
+ */
56
+ authority?: string;
57
+ /**
58
+ * List of known authorities that the application should trust.
59
+ */
60
+ knownAuthorities?: string[];
61
+ /**
62
+ * The redirect URI of the application.
63
+ *
64
+ * If you are providing this property, you should probably use `Platform.select`,
65
+ * because the redirect uris will be different for each platform.
66
+ */
67
+ redirectUri?: string;
68
+ };
69
+ /**
70
+ * Options as described here: {@link https://docs.microsoft.com/en-us/azure/active-directory/develop/msal-configuration}
71
+ * @platform android
72
+ */
73
+ androidConfigOptions?: MSALAndroidConfigOptions;
74
+ }
75
+ export interface MSALAndroidConfigOptions {
76
+ authorization_user_agent?: 'DEFAULT' | 'BROWSER' | 'WEBVIEW';
77
+ broker_redirect_uri_registered?: boolean;
78
+ browser_safelist?: {
79
+ browser_package_name: string;
80
+ browser_signature_hashes: string[];
81
+ browser_use_customTab: boolean;
82
+ }[];
83
+ http?: {
84
+ connect_timeout?: number;
85
+ read_timeout?: number;
86
+ };
87
+ logging?: {
88
+ pii_enabled?: boolean;
89
+ log_level?: 'ERROR' | 'WARNING' | 'INFO' | 'VERBOSE';
90
+ logcat_enabled?: boolean;
91
+ };
92
+ multiple_clouds_supported?: boolean;
93
+ }
94
+ export interface MSALInteractiveParams {
95
+ /**
96
+ * Permissions you want included in the access token received in the result.
97
+ * Not all scopes are guaranteed to be included in the access token returned.
98
+ */
99
+ scopes: string[];
100
+ /**
101
+ * The authority that MSAL will use to obtain tokens. If not included, authority from
102
+ * MSALConfiguration will be used.
103
+ */
104
+ authority?: string;
105
+ /**
106
+ * A specific prompt type for the interactive authentication flow.
107
+ */
108
+ promptType?: MSALPromptType;
109
+ /**
110
+ * A loginHint (usually an email) to pass to the service at the beginning of the
111
+ * interactive authentication flow. The account returned is not guaranteed to match
112
+ * the loginHint.
113
+ */
114
+ loginHint?: string;
115
+ /**
116
+ * Key-value pairs to pass to the /authorize and /token endpoints.
117
+ */
118
+ extraQueryParameters?: Record<string, string>;
119
+ /**
120
+ * Permissions you want the account to consent to in the same authentication flow,
121
+ * but won’t be included in the returned access token.
122
+ */
123
+ extraScopesToConsent?: string[];
124
+ /**
125
+ * User Interface configuration that MSAL uses when getting a token interactively or
126
+ * authorizing an end user.
127
+ */
128
+ webviewParameters?: MSALWebviewParams;
129
+ }
130
+ /**
131
+ * OIDC prompt parameter that specifies whether the Authorization Server prompts the
132
+ * End-User for reauthentication and consent.
133
+ */
134
+ export declare enum MSALPromptType {
135
+ /**
136
+ * If no user is specified the authentication webview will present a list of users
137
+ * currently signed in for the user to select among.
138
+ */
139
+ SELECT_ACCOUNT = 0,
140
+ /**
141
+ * Require the user to authenticate in the webview.
142
+ */
143
+ LOGIN = 1,
144
+ /**
145
+ * Require the user to consent to the current set of scopes for the request.
146
+ */
147
+ CONSENT = 2,
148
+ /**
149
+ * The SSO experience will be determined by the presence of cookies in the webview and
150
+ * account type. User won’t be prompted unless necessary. If multiple users are signed in,
151
+ * select account experience will be presented.
152
+ */
153
+ WHEN_REQUIRED = 3,
154
+ /**
155
+ * Default is MSALPromptType.WHEN_REQUIRED.
156
+ */
157
+ DEFAULT = 3
158
+ }
159
+ export interface MSALSilentParams {
160
+ /**
161
+ * Permissions you want included in the access token received in the result.
162
+ * Not all scopes are guaranteed to be included in the access token returned.
163
+ */
164
+ scopes: string[];
165
+ /**
166
+ * An account object for which tokens should be returned.
167
+ */
168
+ account: MSALAccount;
169
+ /**
170
+ * The authority that MSAL will use to obtain tokens. If not included, authority from
171
+ * MSALConfiguration will be used.
172
+ */
173
+ authority?: string;
174
+ /**
175
+ * Ignore any existing access token in the cache and force MSAL to get a new access token
176
+ * from the service.
177
+ */
178
+ forceRefresh?: boolean;
179
+ }
180
+ export interface MSALSignoutParams {
181
+ /**
182
+ * The account object for which to sign out of.
183
+ */
184
+ account: MSALAccount;
185
+ /**
186
+ * Specifies whether signout should also open the browser and send a network request to the end_session_endpoint.
187
+ * false by default.
188
+ */
189
+ signoutFromBrowser?: boolean;
190
+ /**
191
+ * User Interface configuration that MSAL uses when getting a token interactively or
192
+ * authorizing an end user.
193
+ */
194
+ webviewParameters?: MSALWebviewParams;
195
+ }
196
+ export interface MSALResult {
197
+ /**
198
+ * The Access Token requested, or empty string if no access token is returned in response
199
+ */
200
+ accessToken: string;
201
+ /**
202
+ * The account object that holds account information.
203
+ */
204
+ account: MSALAccount;
205
+ /**
206
+ * The time that the access token returned in the accessToken property ceases to be valid.
207
+ * This value is calculated based on current UTC time measured locally and the value expiresIn returned from the service
208
+ */
209
+ expiresOn: number;
210
+ /**
211
+ * The raw id token if it’s returned by the service or undefined if no id token is returned.
212
+ */
213
+ idToken?: string;
214
+ /**
215
+ * The scope values returned from the service.
216
+ */
217
+ scopes: string[];
218
+ /**
219
+ * Identifier for the directory where account is locally represented
220
+ */
221
+ tenantId?: string;
222
+ }
223
+ export interface MSALAccount {
224
+ /**
225
+ * Unique identifier for the account.
226
+ */
227
+ identifier: string;
228
+ /**
229
+ * Host part of the authority string used for authentication based on the issuer identifier.
230
+ */
231
+ environment?: string;
232
+ /**
233
+ * An identifier for the AAD tenant that the account was acquired from.
234
+ */
235
+ tenantId: string;
236
+ /**
237
+ * Shorthand name by which the End-User wishes to be referred to at the RP, such as janedoe or j.doe.
238
+ */
239
+ username: string;
240
+ /**
241
+ * ID token claims for the account. Can be used to read additional information about the account, e.g. name.
242
+ */
243
+ claims?: object;
244
+ }
245
+ /**
246
+ * Mostly, if not all, iOS webview parameters
247
+ * See https://azuread.github.io/microsoft-authentication-library-for-objc/Classes/MSALWebviewParameters.html
248
+ */
249
+ export interface MSALWebviewParams {
250
+ /**
251
+ * A Boolean value that indicates whether the ASWebAuthenticationSession should ask the
252
+ * browser for a private authentication session.
253
+ * For more info see here: https://developer.apple.com/documentation/authenticationservices/aswebauthenticationsession/3237231-prefersephemeralwebbrowsersessio?language=objc
254
+ * @platform iOS 13+
255
+ */
256
+ ios_prefersEphemeralWebBrowserSession?: boolean;
257
+ /**
258
+ * MSAL requires a web browser for interactive authentication.
259
+ * There are multiple web browsers available to complete authentication.
260
+ * MSAL will default to the web browser that provides best security and user experience for a given platform.
261
+ * Ios_MSALWebviewType allows changing the experience by customizing the configuration to other options for
262
+ * displaying web content
263
+ * @platform iOS
264
+ */
265
+ ios_webviewType?: Ios_MSALWebviewType;
266
+ /**
267
+ * Note: Has no effect when ios_webviewType === `Ios_MSALWebviewType.DEFAULT` or
268
+ * ios_webviewType === `Ios_MSALWebviewType.AUTHENTICATION_SESSION`
269
+ * @platform iOS
270
+ */
271
+ ios_presentationStyle?: Ios_ModalPresentationStyle;
272
+ }
273
+ /**
274
+ * See https://developer.apple.com/documentation/uikit/uimodalpresentationstyle
275
+ */
276
+ export declare enum Ios_ModalPresentationStyle {
277
+ fullScreen = 0,
278
+ pageSheet = 1,
279
+ formSheet = 2,
280
+ currentContext = 3,
281
+ custom = 4,
282
+ overFullScreen = 5,
283
+ overCurrentContext = 6,
284
+ popover = 7,
285
+ blurOverFullScreen = 8,
286
+ none = -1,
287
+ automatic = -2
288
+ }
289
+ /**
290
+ * See https://azuread.github.io/microsoft-authentication-library-for-objc/Enums/MSALWebviewType.html
291
+ */
292
+ export declare enum Ios_MSALWebviewType {
293
+ DEFAULT = 0,
294
+ AUTHENTICATION_SESSION = 1,
295
+ SAFARI_VIEW_CONTROLLER = 2,
296
+ WK_WEB_VIEW = 3
297
+ }
package/package.json ADDED
@@ -0,0 +1,103 @@
1
+ {
2
+ "name": "react-native-msal2",
3
+ "version": "1.0.0",
4
+ "license": "MIT",
5
+ "description": "MSAL React Native wrapper for iOS and Android",
6
+ "homepage": "https://github.com/bittu/react-native-msal2#readme",
7
+ "author": "Sandeep Vemula <vsandeep414@gmail.com>",
8
+ "repository": {
9
+ "type": "git",
10
+ "url": "git+https://github.com/bittu/react-native-msal2.git"
11
+ },
12
+ "scripts": {
13
+ "app": "node create-app.js",
14
+ "app:install": "npm i --no-save $(npm pack . | tail -1) --prefix app",
15
+ "build": "esbuild index.tsx --outdir=dist --bundle --format=esm --sourcemap --external:react-native --external:react && tsc",
16
+ "watch": "npm-run-all --parallel build:watch copy",
17
+ "copy": "cpx 'dist/**/*' app/node_modules/react-native-msal2/dist --watch",
18
+ "build:watch": "esbuild index.tsx --watch --outdir=dist --bundle --format=esm --sourcemap --external:react-native --external:react",
19
+ "test": "jest",
20
+ "test:watch": "jest --watchAll",
21
+ "lint": "eslint . --fix --ext .js,.jsx,.ts,.tsx",
22
+ "format": "prettier \"{,!(app|dist)/**/}*.{ts,tsx}\" --write"
23
+ },
24
+ "devDependencies": {
25
+ "@react-native/babel-preset": "^0.74.0",
26
+ "@react-native/eslint-config": "^0.74.0",
27
+ "@react-native/typescript-config": "^0.74.0",
28
+ "@types/jest": "^29.5.11",
29
+ "@types/node": "^20.11.8",
30
+ "@types/react": "^18.2.48",
31
+ "@types/react-native": "^0.72.8",
32
+ "@types/react-test-renderer": "^18.0.7",
33
+ "babel-jest": "^29.7.0",
34
+ "cpx": "^1.5.0",
35
+ "esbuild": "^0.20.0",
36
+ "eslint": "^8.56.0",
37
+ "eslint-plugin-flowtype": "^8.0.3",
38
+ "eslint-plugin-prettier": "^5.1.3",
39
+ "jest": "^29.7.0",
40
+ "npm-run-all": "^4.1.5",
41
+ "prettier": "^3.2.4",
42
+ "react": "^18.2.0",
43
+ "react-native": "^0.73.2",
44
+ "react-test-renderer": "^18.2.0",
45
+ "typescript": "^5.3.3"
46
+ },
47
+ "peerDependencies": {
48
+ "react": ">= 18",
49
+ "react-native": ">= 0.70"
50
+ },
51
+ "type": "module",
52
+ "main": "./dist/index.js",
53
+ "exports": {
54
+ ".": {
55
+ "types": "./dist/index.d.ts",
56
+ "default": "./dist/index.js"
57
+ }
58
+ },
59
+ "types": "./dist/index.d.ts",
60
+ "files": [
61
+ "dist"
62
+ ],
63
+ "prettier": {
64
+ "printWidth": 100,
65
+ "semi": false,
66
+ "singleQuote": true
67
+ },
68
+ "eslintConfig": {
69
+ "extends": "@react-native",
70
+ "rules": {
71
+ "semi": 0
72
+ },
73
+ "ignorePatterns": [
74
+ "dist",
75
+ "app"
76
+ ],
77
+ "root": true
78
+ },
79
+ "jest": {
80
+ "moduleFileExtensions": [
81
+ "ts",
82
+ "tsx",
83
+ "js",
84
+ "jsx",
85
+ "json",
86
+ "node"
87
+ ],
88
+ "moduleNameMapper": {
89
+ "react-dom": "react-native",
90
+ "react-native-msal2": "<rootDir>"
91
+ },
92
+ "preset": "react-native",
93
+ "testPathIgnorePatterns": [
94
+ "/app/"
95
+ ],
96
+ "transformIgnorePatterns": [
97
+ "node_modules/(?!react-native|@react-native)"
98
+ ]
99
+ },
100
+ "publishConfig": {
101
+ "provenance": false
102
+ }
103
+ }