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-microsoft-login-obo

v2.0.1

Published

React component for easy OAuth with Microsoft services on client side.

Downloads

10

Readme

NOTE: Microsoft team created their @azure/msal-react and it can be used as a good official alternative to react-microsoft-login

react-microsoft-login

npm npm bundle size npm

React component for a simple login with Microsoft services, based on Official Microsoft Authentication Library for JavaScript.

DEMO HERE

🚀 Get started

  1. Install package:

    npm i react-microsoft-login
    # or
    yarn add react-microsoft-login
  2. 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} />
      );
    };
  3. 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.

📖 API

| 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 |

Sign out

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;

📝 License

MIT