rn-ad-auth
A React Native Component which provides complete Authentication flow for Azure AD.
Installation
npm install rn-ad-auth
This package is dependent on React Native Webview package which is internally used in the package. You can read the installation steps from here.
App Registration
First, you will need to register your application with Microsoft Azure Portal. This will give you an Application ID for your application, as well as enable it to receive tokens.
- Sign in to the Microsoft Azure Portal.
- First you need to find the App Registration Service. You could just type in the service name in the search bar on the middle top of the window and select it or do like following:
- Click on All services in the left panel
- Then select from the shown in bold categories the Identity
- Click on the star sign near the App registration service name to add it to favorites
- Now you can easily access the service using the left portal panel
- After selecting App registration service click New registration
- Enter a friendly name for the application
- Select account type that should be supported by your app. The default choice "Accounts in any organizational directory and personal Microsoft accounts" is the widest one.
- Now you need to add Redirect URI
- Select Public client (mobile & desktop) from dropdown
- Type
https://azure-ad-login-3606b.web.app/
here.
- Click Register to create the app registration record.
- Find the Application (client) ID value in Overview section, copy and save the value in a safe location.
- You don't need to set API Permissions. It is meant for admin consent only.
- Now select Authentication from the left menu
- Select checkbox ID tokens in the Implicit grant section - it is needed for OpenID Connect. The library will still use authorization grant and not imlicit.
- Click Save button above to save changes.
Usage:-
import AuthModal from "rn-ad-auth";
const config = {
tenant_id: "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxx",
client_id: "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxx",
scope: "openid",
};
<!--Handle Login or Logout Success-->
const onSuccess = (response) => {
console.log("response", response);
};
<!--Handle Login or Logout Failure-->
const onFailure = (error) => {
console.error("error", error);
};
<!--Handle Login or Logout authentication cancel-->
const onClose = () => {
console.log('Authentication Cancelled');
};
<AuthModal
config={config}
action={"login"}
open={modalOpen}
onClose={onClose}
onSuccess={onSuccess}
onFailure={onFailure}
/>;
Component props:-
Key | Usage | RightAccepted Values |
---|
config | Configugration Object | Object with (tenant_id, client_id, scope) |
action | Action to Perform | 'login' OR 'logout' |
onClose | Emits when modal is closed | Function to perform next operation |
onSuccess | Emits when Auth is successful | Function to handle success |
onFailure | Emits when Auth is failed | Function to handle error |