Giter VIP home page Giter VIP logo

react-native-ms-adal's Introduction

react-native-ms-adal

This is a port of the Active Directory Authentication Library (ADAL) plugin for Apache Cordova apps to work with React Native.

It provides all the basic authentication functions and keychain stuff as per the original cordova library.

See the Microsoft Azure Active Directory Authentication Library (ADAL) for iOS and OSX for full instructions on how to configure the keychain etc in xcode.

See the Microsoft Azure Active Directory Authentication Library (ADAL) for Android for full instructions on how to configure necessary permissions in Android.

Hopefully Microsoft will release an official version soon.

Prerequisites

  1. A working react native project. Tested on react-native 0.41 and above
  2. A working CocoaPods installation CocoaPods - Getting Started

Installation iOS

  1. Install from npm npm install --save react-native-ms-adal
  2. Add the ADAL ios library to your ios/Podfile file pod 'ADAL', '~> 2.3'. Create Podfile with pod init if required.
  3. Run pod install to pull the ios ADAL library down.
  4. In you react-native project root folder run react-native link react-native-ms-adal

Installation Android

  1. Install from npm npm install --save react-native-ms-adal
  2. In you react-native project root folder run react-native link react-native-ms-adal

Installation Windows UWP (Experimental)

  1. Install from npm npm install --save react-native-ms-adal
  2. Open windows/{projectname}.sln
  3. Add '../node_modules/react-native-ms-adal/uwp/ReactNativeMSAdal.csproj' to the solution
  4. Add new ReactNativeMSAdal.ReactNativeMSAdalPackage() to the packages list in MainPage.cs

Notes: the UWP implementation is a wrapper for WebAuthenticationCoreManager instead of ADAL and has therefore not implenented direct access to the tokenCache since that is not accessible from that API. MSAdalLogin() and MSAdalLogout() will therefor not work, use the msadal/AuthenticationContext.js directly instead: import AuthenticationContext from 'react-native-ms-adal/msadal/AuthenticationContext'

Installation Windows WPF (Experimental)

  1. Install from npm npm install --save react-native-ms-adal
  2. Open windows/{projectname}.sln
  3. Add '../node_modules/react-native-ms-adal/wpf/ReactNativeMSAdal.Net46.csproj' to the solution
  4. Add '''new ReactNativeMSAdal.ReactNativeMSAdalPackage()''' to the packages list in MainPage.cs

Usage Example

See Active Directory Authentication Library (ADAL) plugin for Apache Cordova apps for details on how to use the AuthenticationContext. This library renames this to MSAdalAuthenticationContext, which can be imported as follows

import {MSAdalAuthenticationContext} from "react-native-ms-adal";

There are also couple of promised based utility functions to provide login and logout functionality. The login method will first try using the acquireTokenSilentAsync function to login using the details stored in the keychain.

import {MSAdalLogin, MSAdalLogout} from "react-native-ms-adal";

const authority = "https://login.windows.net/common";
const resourceUri = "https://graph.windows.net";

const clientId = <your-client-id>;
const redirectUri = <your-redirect-uri>;

const msAdalPromise = MSAdalLogin(authority, clientId, redirectUri, resourceUri)
  .then(authDetails => {
    // Get the data from the server, using the Authorisation Header
    fetch("<your-url>", {
      headers: {
        "Cache-Control": "no-cache",
        Authorization: "Bearer " + authDetails.accessToken
      }
    })
      .then(response => {
        if (response.status === 200) {
          return response.json();
        } else {
          throw new Error(
            "Server returned status: " +
              response.status +
              ": " +
              response.statusText
          );
        }
      })
      .then(json => {
        // etc
      });
  })
  .catch(err => {
    if (err.code === "403") {
      // User has cancelled
      // We need to make sure the login button is displayed
    }
    console.log("Failed to authenticate: " + err);
  });

react-native-ms-adal's People

Contributors

bjartebore avatar kjerandp avatar samcolby avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

react-native-ms-adal's Issues

Your organization needs more information to secure

I have taken latest plugin and added all things as per document. I am trying to login it is taking username and password after that it is showing this message. But i have valid redirect uri and client id

'ADAL/ADAL.h' file not found.

Hi everyone,

Trying to make this work with:

  • react-native: 0.59.5, and the following pod file:

Screenshot 2019-11-05 at 14 15 42

iOS deployment target is set to 11.0 everywhere.

Cannot make it work because of the following error:
Screenshot 2019-11-05 at 14 13 10

Does anyone have an idea why this happens?

Token caching - different behaviour on iOS and Android

Firstly, thanks for providing this package. I have integrated this into an app with APIs protected by AzureAD and it works fine.

The issue I have observed in testing is with token caching. For example, on Android if I kill the app after authenticating and access it again the silent auth happens in the background as expected (i.e. I do not need to re-enter my credentials). However, on iOS, if I follow the same flow when I reopen the app I need to go through the process of entering my credentials again. Is this a known issue with iOS or is there something I have overlooked here in the setup steps needed on the iOS side?

Need 0.63 RN support

Hi @samcolby, We are not able to add the library for latest react version.

See more compilation issues, do you have any eta in library update

Unable to authenticate multiple resources

When trying to acquire token for multiple resources I am forced to run the full login process for each login. This seems to be because the promptBehaviour is set to "Always".

If this is changed to Auto the application could decide for itself whether or not it would have to show the login dialog. We need to run the requireTokenAsync for each resource before we are able to use the requireTokenSilentlyAsync for the resource.

getValidMSAdalToken should skip over cache entries with no accessToken

I'm seeing cases where the last token in the cache has accessToken set to nil.

I think the correct approach should be for getValidMSAdalToken to filter out cache entries with no accessToken value.

I'm not super confident how the token cache items should be treated but here's an example of code checking for an accessToken value and whether it's expired:
https://github.com/AzureAD/azure-activedirectory-library-for-objc/blob/20e97dba0a7ef0bd3ba86c1aa93a0be5dcff3b71/ADAL/src/request/ADAcquireTokenSilentHandler.m#L322

Issue with getting token

Hi,

I am trying to use this module to be able to get access to the Microsoft Graph API for Azure B2C. I can see the call going all the way to acquireTokenAsync in AuthenticationContext.js but then the application appears to crash after calling the RNAdalPlugin.

I'm running this on an Android device and was wondering if I had some setup/configuration missing?

Thanks for any help you can provide
Andy

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.