npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@rnx-kit/react-native-test-app-msal

v5.0.1

Published

Microsoft Authentication Library (MSAL) module for react-native-test-app

Downloads

163

Readme

@rnx-kit/react-native-test-app-msal

Build npm version

Microsoft Authentication Library (MSAL) module for React Native Test App.

Install

Add @rnx-kit/react-native-test-app-msal as a dev dependency:

yarn add @rnx-kit/react-native-test-app-msal --dev

or if you're using npm:

npm add --save-dev @rnx-kit/react-native-test-app-msal

iOS/macOS

We need to set the deployment target for iOS and macOS to 14.0 and 11.0 (or higher) respectively, and add MSAL to Podfile:

+platform :ios, '14.0'    # If targeting iOS, discard the line below
+platform :macos, '11.0'  # If targeting macOS, discard the line above
+
 require_relative '../node_modules/react-native-test-app/test_app'

 workspace 'MyTestApp.xcworkspace'

+use_test_app! do |target|
+  target.app do
+    # We must use modular headers here otherwise Swift compiler will fail
+    pod 'MSAL', :modular_headers => true
+  end
+end

Usage

Add an entry for the account switcher in your app.json, e.g.:

 {
   "name": "MyTestApp",
   "displayName": "MyTestApp",
   "components": [
     {
       "appKey": "MyTestApp",
+    },
+    {
+      "appKey": "com.microsoft.reacttestapp.msal.MicrosoftAccountsActivity",
+      "displayName": "MicrosoftAccounts (Android)"
+    },
+    {
+      "appKey": "MicrosoftAccounts",
+      "displayName": "MicrosoftAccounts (iOS/macOS)"
     }
   ],
   "resources": {
     "android": ["dist/res", "dist/main.android.bundle"],
     "ios": ["dist/assets", "dist/main.ios.jsbundle"],
     "macos": ["dist/assets", "dist/main.macos.jsbundle"],
     "windows": ["dist/assets", "dist/main.windows.bundle"]
   }
 }

Register your app with a unique bundle identifier to get your Azure Active Directory client identifier and related scopes (quickstart here), then fill out the following fields in app.json:

 {
   "name": "MyTestApp",
   "displayName": "MyTestApp",
   "components": [
     {
       "appKey": "MyTestApp",
     },
     {
       "appKey": "com.microsoft.reacttestapp.msal.MicrosoftAccountsActivity",
       "displayName": "MicrosoftAccounts (Android)"
     },
     {
       "appKey": "MicrosoftAccounts",
       "displayName": "MicrosoftAccounts (iOS/macOS)"
     }
   ],
+  "android": {
+    "package": "com.contoso.MyTestApp"
+  },
+  "ios": {
+    "bundleIdentifier": "com.contoso.MyTestApp"
+  },
+  "macos": {
+    "bundleIdentifier": "com.contoso.MyTestApp"
+  },
+  "react-native-test-app-msal": {
+    "clientId": "4b0db8c2-9f26-4417-8bde-3f0e3656f8e0",
+    "msaScopes": ["user.read"],
+    "orgScopes": ["user.read"],
+    "signatureHash": "1wIqXSqBj7w+h11ZifsnqwgyKrY="
+  },
   "resources": {
     "android": ["dist/res", "dist/main.android.jsbundle"],
     "ios": ["dist/assets", "dist/main.ios.jsbundle"],
     "macos": ["dist/assets", "dist/main.macos.jsbundle"],
     "windows": ["dist/assets", "dist/main.windows.bundle"]
   }
 }

Getting a Token from Native Code

A token can be acquired from native code using the TokenBroker singleton.

Android

On Android, we will need the Context to retrieve the singleton, and the current Activity to acquire a token. We need the Activity in case we need to ask the user to log in:

import com.microsoft.reacttestapp.msal.TokenBroker

TokenBroker.getInstance(context).acquireToken(context.currentActivity, ...) { result, error ->
  // handle result here
}

iOS/macOS

On iOS/macOS, we will need the current UIViewController (iOS) or NSViewController (macOS) to acquire a token in case we need to ask the user to log in:

import ReactTestApp_MSAL

TokenBroker.shared.acquireToken(scopes: ..., sender: viewController) { result, error ->
  // handle result here
}