azure-ad-login-authentication
v1.1.5
Published
To test azure AD authentication in React components
Downloads
18
Readme
Quickstart
Install the module with:
Register a web application
npm install azure-ad-login-authentication
Register your Application
- Sign in to the Azure portal.
- If you have access to multiple tenants, use the Directories + subscriptions filter in the top menu to switch to the tenant in which you want to register the application.
- Search for and select Azure Active Directory. Under Manage, select App registrations > New registration.
- When the Register an application page appears, enter a name for your application.
- Under Supported account types, select Accounts in any organizational directory and personal Microsoft accounts.
- Select Register. On the app Overview page, note the Application (client) ID value for later use.
- Under Manage, select Authentication.
- Under Platform configurations, select Add a platform. In the pane that opens select Single-page application.
- Set the Redirect URIs value to http://localhost:3000/. This is the default port NodeJS will listen on your local machine. We’ll return the authentication response to this URI after successfully authenticating the user.
- Select Configure to apply the changes.
- Under Platform Configurations expand Single-page application.
- Confirm that under Grant types Already configured Your Redirect URI is eligible for the Authorization Code Flow with PKCE.
Depedency Required
npm install react-router-dom --save
npm install @azure/msal-browser
Getting Started
Import Login to your React Page Component
import Login from '../node_modules/azure-ad-login-authentication/dist/component/Login'
Create .env file in your root folder, add values of registered app in .env file.
.env file
REACT_APP_APPID=<Enter your application ID here>
REACT_APP_BASE_URL=<Enter your base URL here on which application runs>
REACT_APP_SCOPES=<Enter scope here>
REACT_APP_AUTHORITY=<Enter authority here>
REACT_APP_LANDING_PAGE_PATH=<Enter path of landing page after login>
.env file Example
REACT_APP_APPID=605283c9-ed67-478e-b870-5fc1a84fr436
REACT_APP_BASE_URL=http://localhost:3000
REACT_APP_SCOPES=user.read
REACT_APP_AUTHORITY=https://login.microsoftonline.com/<organisation name>.com
REACT_APP_LANDING_PAGE_PATH=home
How to use
and then in your app.js file import component-
import Login from '../node_modules/azure-ad-login-authentication/dist/component/Login'
import { BrowserRouter, Route, Routes } from 'react-router-dom';
import Home from './component/home';
function App() {
return (
<BrowserRouter>
<Routes>
<Route path="/" element={<Login></Login>}/>
<Route path="/home" element={<Home></Home>}></Route>
</Routes>
</BrowserRouter>
);
}
Example
import Login from '../node_modules/azure-ad-login-authentication/dist/component/Login'
import { BrowserRouter, Route, Routes } from 'react-router-dom';
import Home from './component/home';
function App() {
return (
<BrowserRouter>
<Routes>
<Route path="/" element={<Login></Login>}/>
<Route path="/home" element={<Home></Home>}></Route>
</Routes>
</BrowserRouter>
);
}
export default App;