Security News
Node.js EOL Versions CVE Dubbed the "Worst CVE of the Year" by Security Experts
Critics call the Node.js EOL CVE a misuse of the system, sparking debate over CVE standards and the growing noise in vulnerability databases.
react-microsoft-login
Advanced tools
React component for easy OAuth with Microsoft services on client side.
React component for a simple login with Microsoft services, based on Official Microsoft Authentication Library for JavaScript.
Install package:
npm i react-microsoft-login
# or
yarn add react-microsoft-login
Import and configure component:
import React from "react";
import MicrosoftLogin from "react-microsoft-login";
export default (props) => {
const authHandler = (err, data) => {
console.log(err, data);
};
return (
<MicrosoftLogin clientId={YOUR_CLIENT_ID} authCallback={authHandler} />
);
};
YOUR_CLIENT_ID
is the key which you need to generate for your Microsoft app. How to create Microsoft app? When finished, on the app Overview page, note down the Application (client) ID value.
Parameter | Type | Default | Description |
---|---|---|---|
clientId | string | required | Application (client) ID |
authCallback | function | required | Callback function which takes three arguments (error, authData, msalInstance) |
graphScopes | array | ["user.read"] | Array of Graph API permission names. More about Graph API permissions. |
redirectUri | string | window.location.href | The redirect URI of the application, this should be same as the value in the application registration portal. |
postLogoutRedirectUri | string | You can configure the URI to which it should redirect after sign-out by setting postLogoutRedirectUri. This URI should also be registered as the logout URI in your application registration. | |
tenantUrl | string | A URL indicating a directory that MSAL can request tokens from. More about MSAL tenant auth. | |
prompt | enum("login", "select_account", "consent", "none") | Specify custom prompt behavior | |
buttonTheme | enum("dark_short", "light_short", "dark", "light") | "light" | Theme for button style that based on Official Microsoft brand design. |
withUserData | boolean | Boolean flag to make an additional request to GraphAPI to get user data. | |
forceRedirectStrategy | boolean | Boolean flag to force redirect login strategy for all browsers. This strategy used by default just for IE browsers to avoid issues. | |
useLocalStorageCache | boolean | You can set cookie storage to localStorage for persistent login between tabs and sessions. Session storage is used by default. More about SSO with MSAL. | |
debug | boolean | Boolean flag to enable detailed logs of authorization process. | |
className | string | Additional class name string. | |
children | ReactComponent | Alternative way to provide custom button element as a children prop instead of Official Microsoft brand design |
Since version 1.12.0 and higher msalInstance returned as third argument in callback function, after success auth. With this instance you can do many things and logout is one of them:
import React, { useState } from "react";
import MicrosoftLogin from "../../dist";
const ExamplePage = () => {
const [msalInstance, onMsalInstanceChange] = useState();
const loginHandler = (err, data, msal) => {
console.log(err, data);
// some actions
if (!err && data) {
onMsalInstanceChange(msal);
}
};
const logoutHandler = () => {
msalInstance.logout();
};
return msalInstance ? (
<button onClick={logoutHandler}>Logout</button>
) : (
<MicrosoftLogin clientId={clientId} authCallback={loginHandler} />
);
};
export default ExamplePage;
FAQs
React component for easy OAuth with Microsoft services on client side.
The npm package react-microsoft-login receives a total of 5,272 weekly downloads. As such, react-microsoft-login popularity was classified as popular.
We found that react-microsoft-login demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Critics call the Node.js EOL CVE a misuse of the system, sparking debate over CVE standards and the growing noise in vulnerability databases.
Security News
cURL and Go security teams are publicly rejecting CVSS as flawed for assessing vulnerabilities and are calling for more accurate, context-aware approaches.
Security News
Bun 1.2 enhances its JavaScript runtime with 90% Node.js compatibility, built-in S3 and Postgres support, HTML Imports, and faster, cloud-first performance.