react-native-msal2 1.0.14 → 1.0.15

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.
@@ -2,33 +2,35 @@ apply plugin: "com.android.library"
2
2
  apply plugin: "org.jetbrains.kotlin.android"
3
3
 
4
4
  def safeExtGet(prop, fallback) {
5
- rootProject.ext.has(prop) ? rootProject.ext.get(prop) : fallback
5
+ rootProject.ext.has(prop) ? rootProject.ext.get(prop) : fallback
6
6
  }
7
7
 
8
8
  android {
9
- namespace "com.reactnativemsal"
9
+ namespace "com.reactnativemsal"
10
10
 
11
- compileSdkVersion safeExtGet("compileSdkVersion", 34)
11
+ compileSdkVersion safeExtGet("compileSdkVersion", 34)
12
12
 
13
- defaultConfig {
14
- minSdkVersion safeExtGet("minSdkVersion", 21)
15
- targetSdkVersion safeExtGet("targetSdkVersion", 34)
16
- }
13
+ defaultConfig {
14
+ minSdkVersion safeExtGet("minSdkVersion", 21)
15
+ targetSdkVersion safeExtGet("targetSdkVersion", 34)
16
+ }
17
17
 
18
- compileOptions {
19
- sourceCompatibility JavaVersion.VERSION_1_8
20
- targetCompatibility JavaVersion.VERSION_1_8
21
- }
18
+ compileOptions {
19
+ sourceCompatibility JavaVersion.VERSION_1_8
20
+ targetCompatibility JavaVersion.VERSION_1_8
21
+ }
22
22
  }
23
23
 
24
24
  repositories {
25
- google()
26
- mavenCentral()
25
+ google()
26
+ mavenCentral()
27
27
  }
28
28
 
29
29
  dependencies {
30
- //noinspection UseTomlInstead
31
- compileOnly "com.facebook.react:react-android"
32
- //noinspection UseTomlInstead
33
- implementation "com.microsoft.identity.client:msal:8.2.1"
30
+ //noinspection UseTomlInstead
31
+ implementation "androidx.browser:browser:1.9.0"
32
+ //noinspection UseTomlInstead
33
+ compileOnly "com.facebook.react:react-android"
34
+ //noinspection UseTomlInstead
35
+ implementation "com.microsoft.identity.client:msal:8.2.3"
34
36
  }
@@ -1,9 +1,13 @@
1
1
  package com.reactnativemsal
2
2
 
3
+ import android.content.Intent
4
+ import android.content.pm.PackageInfo
3
5
  import android.content.pm.PackageManager
4
6
  import android.net.Uri
7
+ import android.os.Build
5
8
  import android.util.Base64
6
9
  import android.util.Log
10
+ import androidx.browser.customtabs.CustomTabsService
7
11
  import com.facebook.react.bridge.Arguments.createArray
8
12
  import com.facebook.react.bridge.Arguments.createMap
9
13
  import com.facebook.react.bridge.Arguments.fromArray
@@ -27,6 +31,8 @@ import com.microsoft.identity.client.Prompt
27
31
  import com.microsoft.identity.client.PublicClientApplication
28
32
  import com.microsoft.identity.client.SilentAuthenticationCallback
29
33
  import com.microsoft.identity.client.exception.MsalException
34
+ import com.microsoft.identity.common.internal.broker.PackageHelper
35
+ import com.microsoft.identity.common.internal.ui.browser.AndroidBrowserSelector
30
36
  import org.json.JSONArray
31
37
  import org.json.JSONException
32
38
  import org.json.JSONObject
@@ -36,7 +42,6 @@ import java.security.MessageDigest
36
42
  import java.util.AbstractMap
37
43
  import java.util.regex.Matcher
38
44
  import java.util.regex.Pattern
39
- import com.microsoft.identity.common.internal.ui.browser.AndroidBrowserSelector
40
45
 
41
46
  class RNMSALModule(reactContext: ReactApplicationContext?) :
42
47
  ReactContextBaseJavaModule(reactContext) {
@@ -127,12 +132,96 @@ class RNMSALModule(reactContext: ReactApplicationContext?) :
127
132
 
128
133
  @ReactMethod
129
134
  fun getSelectedBrowser(promise: Promise) {
130
- publicClientApplication?.configuration?.browserSafeList?.let {
131
- AndroidBrowserSelector(reactApplicationContext).selectBrowser(it, null)?.let { browser ->
132
- promise.resolve("${browser.packageName} ${browser.version} ${if (browser.isCustomTabsServiceSupported) "CustomTab" else "NoCustomTab"}")
135
+ val safeList = publicClientApplication?.configuration?.browserSafeList
136
+
137
+ val browser = if (!safeList.isNullOrEmpty()) {
138
+ AndroidBrowserSelector(reactApplicationContext).selectBrowser(safeList, null)
139
+ } else null
140
+
141
+ //if (browser == null) {
142
+ val result = browser?.let {
143
+ "${it.packageName} ${it.version} ${it.signatureHashes} (${if (it.isCustomTabsServiceSupported) "CustomTab" else "NoCustomTab"})"
144
+ } ?: "Unknown"
145
+
146
+ promise.resolve(result)
147
+ }
148
+
149
+ @ReactMethod
150
+ fun getSafeCustomTabsBrowsers(promise: Promise) {
151
+ try {
152
+ val safeList = publicClientApplication?.configuration?.browserSafeList
153
+ if (safeList.isNullOrEmpty()) {
154
+ promise.resolve(createArray())
155
+ return
156
+ }
157
+
158
+ val pm = reactApplicationContext.packageManager
159
+
160
+ val customTabsIntent = Intent(CustomTabsService.ACTION_CUSTOM_TABS_CONNECTION)
161
+
162
+ val servicePackages = pm.queryIntentServices(customTabsIntent, 0)
163
+ .mapNotNull { it.serviceInfo?.packageName }
164
+ .distinct()
165
+ .sorted()
166
+
167
+ val safeEntriesByPackage = safeList.groupBy { it.packageName }
168
+
169
+ val result = createArray()
170
+
171
+ for (packageName in servicePackages) {
172
+ val safeEntries = safeEntriesByPackage[packageName].orEmpty()
173
+ if (safeEntries.isEmpty()) {
174
+ continue
175
+ }
176
+
177
+ val packageInfo = getPackageInfoCompat(pm, packageName) ?: continue
178
+ val version = packageInfo.versionName
179
+ ?: if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P) {
180
+ packageInfo.longVersionCode.toString()
181
+ } else {
182
+ @Suppress("DEPRECATION")
183
+ packageInfo.versionCode.toString()
184
+ }
185
+ val installedSignatures = PackageHelper.generateSignatureHashes(packageInfo)
186
+
187
+ val matchingSignature = installedSignatures.firstOrNull { installed ->
188
+ safeEntries.any { safeEntry ->
189
+ safeEntry.signatureHashes.any { safeHash ->
190
+ safeHash.equals(installed, ignoreCase = false)
191
+ }
192
+ }
193
+ } ?: continue
194
+
195
+ val signatures = createArray()
196
+ signatures.pushString(matchingSignature)
197
+ val item = createMap().apply {
198
+ putString("browser_package_name", packageName)
199
+ putString("browser_version_lower_bound", version)
200
+ putArray("browser_signature_hashes", signatures)
201
+ }
202
+ result.pushMap(item)
203
+ }
204
+
205
+ promise.resolve(result)
206
+ } catch (e: Exception) {
207
+ promise.reject("GET_SAFE_CUSTOM_TABS_BROWSERS_FAILED", e)
208
+ }
209
+ }
210
+
211
+ private fun getPackageInfoCompat(pm: PackageManager, packageName: String): PackageInfo? {
212
+ return try {
213
+ if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU) {
214
+ pm.getPackageInfo(
215
+ packageName,
216
+ PackageManager.PackageInfoFlags.of(PackageManager.GET_SIGNING_CERTIFICATES.toLong())
217
+ )
218
+ } else {
219
+ @Suppress("DEPRECATION")
220
+ pm.getPackageInfo(packageName, PackageManager.GET_SIGNATURES)
133
221
  }
222
+ } catch (_: Exception) {
223
+ null
134
224
  }
135
- promise.resolve ("Unknown")
136
225
  }
137
226
 
138
227
  @Throws(JSONException::class, IllegalArgumentException::class)
@@ -517,6 +606,6 @@ class RNMSALModule(reactContext: ReactApplicationContext?) :
517
606
 
518
607
  private val aadAuthorityPattern: Pattern =
519
608
  Pattern.compile("https://login\\.microsoftonline\\.com/([^/]+)")
520
- private val b2cAuthorityPattern: Pattern = Pattern.compile("https://([^/]+)/([^/]+)/.+")
609
+ private val b2cAuthorityPattern: Pattern = Pattern.compile("https://([^/]+)(/\S*)?")
521
610
  }
522
611
  }
package/dist/index.js CHANGED
@@ -48,6 +48,13 @@ var PublicClientApplication = class {
48
48
  default: async () => "N/A"
49
49
  })();
50
50
  }
51
+ async getSafeCustomTabsBrowsers() {
52
+ this.validateIsInitialized();
53
+ return await Platform.select({
54
+ android: async () => [await RNMSAL.getSafeCustomTabsBrowsers()],
55
+ default: async () => []
56
+ })();
57
+ }
51
58
  validateIsInitialized() {
52
59
  if (!this.isInitialized) {
53
60
  throw new Error(
package/dist/index.js.map CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
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 getSelectedBrowser(): Promise<string>\n}\n\nconst RNMSAL: RNMSALNativeModule = NativeModules.RNMSAL\n\n// export 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 public async getSelectedBrowser() {\n this.validateIsInitialized()\n return await Platform.select({\n android: async () => await RNMSAL.getSelectedBrowser(),\n default: async () => 'N/A',\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 /**\n * Returns the browser that will be used for interactive authentication.\n * NOTE: Android only. On iOS this will always return 'N/A'.\n * @return Promise resolving to the package name and version of the browser that will be used\n * for interactive authentication.\n * @platform android\n */\n getSelectedBrowser(): Promise<string>\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;AAa9B,IAAM,SAA6B,cAAc;AAI1C,IAAM,0BAAN,MAAkE;AAAA,EAGvE,YAA6B,QAA2B;AAA3B;AAAA,EAA4B;AAAA,EAFjD,g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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;;;AC3TZ,IAAO,6BAAQ;",
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 MSALAndroidPreferredBrowser,\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 getSelectedBrowser(): Promise<string>\n getSafeCustomTabsBrowsers(): Promise<MSALAndroidPreferredBrowser>\n}\n\nconst RNMSAL: RNMSALNativeModule = NativeModules.RNMSAL\n\n// export 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 public async getSelectedBrowser() {\n this.validateIsInitialized()\n return await Platform.select({\n android: async () => await RNMSAL.getSelectedBrowser(),\n default: async () => 'N/A',\n })()\n }\n\n async getSafeCustomTabsBrowsers() {\n this.validateIsInitialized()\n return await Platform.select({\n android: async () => [await RNMSAL.getSafeCustomTabsBrowsers()],\n default: async () => [],\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 /**\n * Returns the browser that will be used for interactive authentication.\n * NOTE: Android only. On iOS this will always return 'N/A'.\n * @return Promise resolving to the package name and version of the browser that will be used\n * for interactive authentication.\n * @platform android\n */\n getSelectedBrowser(): Promise<string>\n\n /**\n * Returns a array of installed browsers found in the configured safe list that support customTab.\n * NOTE: Android only. On iOS this will always return N/A.\n * @return Promise resolving to an array of installed browsers that support customTab\n * @platform android\n */\n getSafeCustomTabsBrowsers(): Promise<MSALAndroidPreferredBrowser[]>\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 MSALAndroidPreferredBrowser {\n browser_package_name: string;\n browser_signature_hashes: string[];\n browser_version_lower_bound?: string;\n browser_version_upper_bound?: string;\n}\n\nexport interface MSALAndroidConfigOptions {\n authorization_user_agent?: 'DEFAULT' | 'BROWSER' | 'WEBVIEW'\n broker_redirect_uri_registered?: boolean\n preferred_browser?: MSALAndroidPreferredBrowser;\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;AAazB,SAAS,qBAAqB;AAc9B,IAAM,SAA6B,cAAc;AAI1C,IAAM,0BAAN,MAAkE;AAAA,EAGvE,YAA6B,QAA2B;AAA3B;AAAA,EAA4B;AAAA,EAFjD,gBAAyB;AAAA,EAIjC,MAAa,OAAO;AAClB,QAAI,CA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EQ,wBAAwB;AAC9B,QAAI,CAAC,KAAK,eAAe;AACvB,YAAM,IAAI;AAAA,QACR;AAAA,MACF;AAAA,IACF;AAAA,EACF;AACF;;;ACmEO,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;;;AC3UZ,IAAO,6BAAQ;",
6
6
  "names": ["MSALPromptType", "Ios_ModalPresentationStyle", "Ios_MSALWebviewType"]
7
7
  }
@@ -1,4 +1,4 @@
1
- import type { MSALConfiguration, MSALInteractiveParams, MSALSilentParams, MSALAccount, MSALSignoutParams, IPublicClientApplication, MSALResult } from './types';
1
+ import type { MSALConfiguration, MSALInteractiveParams, MSALSilentParams, MSALAccount, MSALSignoutParams, IPublicClientApplication, MSALResult, MSALAndroidPreferredBrowser } from './types';
2
2
  export declare class PublicClientApplication implements IPublicClientApplication {
3
3
  private readonly config;
4
4
  private isInitialized;
@@ -11,5 +11,6 @@ export declare class PublicClientApplication implements IPublicClientApplication
11
11
  removeAccount(account: MSALAccount): Promise<boolean>;
12
12
  signOut(params: MSALSignoutParams): Promise<boolean>;
13
13
  getSelectedBrowser(): Promise<string>;
14
+ getSafeCustomTabsBrowsers(): Promise<MSALAndroidPreferredBrowser[]>;
14
15
  private validateIsInitialized;
15
16
  }
@@ -51,6 +51,13 @@ export interface IPublicClientApplication {
51
51
  * @platform android
52
52
  */
53
53
  getSelectedBrowser(): Promise<string>;
54
+ /**
55
+ * Returns a array of installed browsers found in the configured safe list that support customTab.
56
+ * NOTE: Android only. On iOS this will always return N/A.
57
+ * @return Promise resolving to an array of installed browsers that support customTab
58
+ * @platform android
59
+ */
60
+ getSafeCustomTabsBrowsers(): Promise<MSALAndroidPreferredBrowser[]>;
54
61
  }
55
62
  export interface MSALConfiguration {
56
63
  auth: {
@@ -80,9 +87,16 @@ export interface MSALConfiguration {
80
87
  */
81
88
  androidConfigOptions?: MSALAndroidConfigOptions;
82
89
  }
90
+ export interface MSALAndroidPreferredBrowser {
91
+ browser_package_name: string;
92
+ browser_signature_hashes: string[];
93
+ browser_version_lower_bound?: string;
94
+ browser_version_upper_bound?: string;
95
+ }
83
96
  export interface MSALAndroidConfigOptions {
84
97
  authorization_user_agent?: 'DEFAULT' | 'BROWSER' | 'WEBVIEW';
85
98
  broker_redirect_uri_registered?: boolean;
99
+ preferred_browser?: MSALAndroidPreferredBrowser;
86
100
  browser_safelist?: {
87
101
  browser_package_name: string;
88
102
  browser_signature_hashes: string[];
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "react-native-msal2",
3
- "version": "1.0.14",
3
+ "version": "1.0.15",
4
4
  "license": "MIT",
5
5
  "description": "MSAL React Native wrapper for iOS and Android",
6
6
  "homepage": "https://github.com/bittu/react-native-msal2#readme",
@@ -8,6 +8,7 @@ import type {
8
8
  MSALSignoutParams,
9
9
  IPublicClientApplication,
10
10
  MSALResult,
11
+ MSALAndroidPreferredBrowser,
11
12
  } from './types'
12
13
 
13
14
  import { NativeModules } from 'react-native'
@@ -21,6 +22,7 @@ type RNMSALNativeModule = {
21
22
  removeAccount(account: MSALAccount): Promise<boolean>
22
23
  signout(params: MSALSignoutParams): Promise<boolean>
23
24
  getSelectedBrowser(): Promise<string>
25
+ getSafeCustomTabsBrowsers(): Promise<MSALAndroidPreferredBrowser>
24
26
  }
25
27
 
26
28
  const RNMSAL: RNMSALNativeModule = NativeModules.RNMSAL
@@ -81,6 +83,14 @@ export class PublicClientApplication implements IPublicClientApplication {
81
83
  })()
82
84
  }
83
85
 
86
+ async getSafeCustomTabsBrowsers() {
87
+ this.validateIsInitialized()
88
+ return await Platform.select({
89
+ android: async () => [await RNMSAL.getSafeCustomTabsBrowsers()],
90
+ default: async () => [],
91
+ })()
92
+ }
93
+
84
94
  private validateIsInitialized() {
85
95
  if (!this.isInitialized) {
86
96
  throw new Error(
package/src/types.ts CHANGED
@@ -57,6 +57,14 @@ export interface IPublicClientApplication {
57
57
  * @platform android
58
58
  */
59
59
  getSelectedBrowser(): Promise<string>
60
+
61
+ /**
62
+ * Returns a array of installed browsers found in the configured safe list that support customTab.
63
+ * NOTE: Android only. On iOS this will always return N/A.
64
+ * @return Promise resolving to an array of installed browsers that support customTab
65
+ * @platform android
66
+ */
67
+ getSafeCustomTabsBrowsers(): Promise<MSALAndroidPreferredBrowser[]>
60
68
  }
61
69
 
62
70
  export interface MSALConfiguration {
@@ -88,9 +96,17 @@ export interface MSALConfiguration {
88
96
  androidConfigOptions?: MSALAndroidConfigOptions
89
97
  }
90
98
 
99
+ export interface MSALAndroidPreferredBrowser {
100
+ browser_package_name: string;
101
+ browser_signature_hashes: string[];
102
+ browser_version_lower_bound?: string;
103
+ browser_version_upper_bound?: string;
104
+ }
105
+
91
106
  export interface MSALAndroidConfigOptions {
92
107
  authorization_user_agent?: 'DEFAULT' | 'BROWSER' | 'WEBVIEW'
93
108
  broker_redirect_uri_registered?: boolean
109
+ preferred_browser?: MSALAndroidPreferredBrowser;
94
110
  browser_safelist?: {
95
111
  browser_package_name: string
96
112
  browser_signature_hashes: string[]