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

react-native-msal-module

v0.1.3

Published

React Native module to cover iOS and Android client libraries

Downloads

7

Readme

react-native-msal-module

MSAL authorization library for React Native

Looking for the MSAL plugin for React Native, here you are

Based on great plugin but deprecated react-native-msal-plugin

Important!

Package has been tested only on React Native 0.59.9 and 0.60+.

Support

  • React Native 0.59.9 and 0.60+ ✅
  • iOS 13 (tested) ✅
  • AndroidX (tested) ✅
  • Typescript ✅

Instalation

$ npm install react-native-msal-module --save

Automatic linking is not tested. We recommend manual linking

iOS

Setting the plugin requires adding proper properties in Info.plist and AppDelegate.m . Here is the documentation of MSAL for iOS client. More in second point below.

  • We provide only Cocoapods linking. In your pod file add:
  ...
  # Lines below
  pod 'MSAL', '~> 1.0.3' # <~ This line 
  pod 'react-native-msal-module', :path => '../node_modules/react-native-msal-module' # <~  this line
  
  ...

  end
  • After that pod install

  • You need to implement Configuring MSAL step

    1. Make sure you have done Adding MSAL to your project (3 points)
    2. Make suer you have done iOS only steps (2 points)
    3. Add code below to your AppDelegate.m (3rd point of iOS only steps)
    #import <React/RCTBridge.h>
    #import <React/RCTBundleURLProvider.h>
    #import <React/RCTRootView.h>
    
    #import <MSAL/MSAL.h> // <~ add this line(header file from MSAL)
    
    ...
    
    // this section, starting from here
    - (BOOL)application:(UIApplication *)application
               openURL:(NSURL *)url
               options:(NSDictionary<UIApplicationOpenURLOptionsKey,id> *)options
    {
       return [MSALPublicClientApplication handleMSALResponse:url
                                            sourceApplication:options[UIApplicationOpenURLOptionsSourceApplicationKey]];
    }
    // ending here

That's all!

Android

First of all, according to the Android documentation and this plugin you should implement steps below:

  • Add file msal_config.json (draft) in assets directory in [your-project]/android/app/src/main

    • remember that redirect_uri includes YOUR_BASE64_URL_ENCODED_PACKAGE_SIGNATURE so you need BASE64 format of SIGNATURE parsed into URL. The same thing should be added in your Azure panel under redirect uris section

    • Also remember that your release signature differ with debug signature

  • Implement this step in your AndroidManifest.xml

  • Linking:

    • in [your-project]/android/app/build.gradle add:
    dependencies {
    ...
    implementation project(':react-native-msal-module') // <~ add this line
    ...
    }
    • in [your-project]/android/settings.gradle add:
    rootProject.name = '<NAME_OF_YOUR_PROJECT>'
    ...
    include ':react-native-msal-module' // <~ add this line
    project(':react-native-msal-module').projectDir = new File(rootProject.projectDir, '../node_modules/react-native-msal-module/android') // <~ add this line
    ...
      
    include ':app'

    If your project is based on RN v0.60+ you can omit step below as you will overwrite already automatically linked package

    • in [your-project]/android/app/src/main/java/com/[your-project]/MainApplication.java add:
    package <YOUR_APP_PACKAGE>
    ...
    import com.reactlibrary.RNMsalModulePackage; // <~ add this line
    ...
      
    public class MainApplication extends Application implements ReactApplication {
    
    ...
     @Override
      protected List<ReactPackage> getPackages() {
          return Arrays.<ReactPackage>asList(
              new MainReactPackage(),
              ...
              new RNMsalModulePackage(), // <~ add this line
              ...
          );
        }
    ...

That's all, you did it!

Usage

Initialization

import React from 'react';
import { View, Text } from 'react-native';
import MSAL from 'react-native-msal-module';

export class App extends React.Component {
    componentDidMount() {
        MSAL.init(<YOUR_CLIENT_ID>);
    }
    
    render() {
       <View>
            <Text>App</Text> 
       </View>
    }

};

Acquire token

    acquireTokenAsync: (scopes: string[]) => Promise<MSALResponse>;
import React from 'react';
import { View, Text } from 'react-native';
import MSAL from 'react-native-msal-module';

export class App extends React.Component {
    async componentDidMount() {
        // Acquire token can be executed only after successful initalization of MSAL
        // Pass needed scopes
        const msalResponse = await MSAL.acquireTokenAsync(scopes);
    }
    render() {
       <View>
            <Text>App</Text> 
       </View>
    }
}

MSAL reponse

| Parameter | type | | ---------------------- | :---: | | accessToken | String | | idToken | String | | userId | String | | expiresOn | String | | userInfo | MSALUser type |

MSALUser type

| Parameter | type | | ---------------------- | :---: | | username | String | | userIdentifier | String | | environment | String | | tenantId | String |

Acquire token silently

    acquireTokenSilentAsync: (scopes: string[], userIdentifier: string) => Promise<MSALResponse>;
import React from 'react';
import { View, Text } from 'react-native';
import MSAL from 'react-native-msal-module';

export class App extends React.Component {
    async componentDidMount() {
        // Acquire token silent can be executed only after successful initalization of MSAL
        // Pass userId retrieved from aqcuireToken and scopes
        const msalResponse = await MSAL.acquireTokenSilentAsync(scopes, userId);
    }
    render() {
       <View>
            <Text>App</Text> 
       </View>
    }
}

Example

In project you can find sample implementation for both platforms(iOS and Android). Example is built with RN v0.61.5. Example won't work without changes in config files.

Known issues

  • ~~idToken is currently unavailable in Android https://github.com/AzureAD/microsoft-authentication-library-for-android/issues/850~~
  • Sometimes webview in iOS has refreshing loop

Roadmap

It's unclear when official plugin will be released so for now:

  • [x] ~~Test on newest React Native version~~
  • [ ] Write tests
  • [x] ~~Add example~~
  • [ ] Implement methods for Single Account

License