All Projects → alexandrtovmach → react-microsoft-login

alexandrtovmach / react-microsoft-login

Licence: MIT license
Microsoft services authorization with React.

Programming Languages

typescript
32286 projects
javascript
184084 projects - #8 most used programming language
shell
77523 projects

Projects that are alternatives of or similar to react-microsoft-login

react-native-msal
MSAL for React Native
Stars: ✭ 62 (-4.62%)
Mutual labels:  microsoft, msal
ms-identity-mobile-apple-swift-objc
An iOS sample in Swift that authenticates Microsoft Account and Azure AD users and calls the Graph API using OAuth 2.0
Stars: ✭ 61 (-6.15%)
Mutual labels:  microsoft, msal
node-eufy-api
A simple JavaScript API to control EufyHome (Anker) smart light bulbs, switches and plugs.
Stars: ✭ 22 (-66.15%)
Mutual labels:  npm-package
interview-prep
🤼 An aggregate of technical interview questions and testimonies.
Stars: ✭ 17 (-73.85%)
Mutual labels:  microsoft
js-mdict
*.mdx/*.mdd interpreter js implements
Stars: ✭ 91 (+40%)
Mutual labels:  npm-package
libemf2svg
Microsoft (MS) EMF to SVG conversion library
Stars: ✭ 75 (+15.38%)
Mutual labels:  microsoft
xp
💻 Windows XP All Editions Universal Product Keys Collection
Stars: ✭ 247 (+280%)
Mutual labels:  microsoft
micro-signals
A tiny typed messaging system inspired by js-signals that uses ES2015 sets
Stars: ✭ 39 (-40%)
Mutual labels:  npm-package
ansicolor
A JavaScript ANSI color/style management. ANSI parsing. ANSI to CSS. Small, clean, no dependencies.
Stars: ✭ 91 (+40%)
Mutual labels:  npm-package
eslint-plugin-vue-scoped-css
ESLint plugin for Scoped CSS in Vue.js
Stars: ✭ 58 (-10.77%)
Mutual labels:  npm-package
extensions-dependency-injection
Microsoft Extensions DependencyInjection for WCF, and asp.net classic projects
Stars: ✭ 18 (-72.31%)
Mutual labels:  microsoft
nba-stats-client
🏀 JavaScript Client for stats from NBA.com
Stars: ✭ 29 (-55.38%)
Mutual labels:  npm-package
ugql
🚀GraphQL.js over HTTP with uWebSockets.js
Stars: ✭ 27 (-58.46%)
Mutual labels:  npm-package
hydra-js
DOES NOT WORK WITH VERSIONS > 0.10.0 - A simple library to help you build node-based identity providers that work with Hydra.
Stars: ✭ 17 (-73.85%)
Mutual labels:  npm-package
2018-package-three-webpack-plugin
[ARCHIVED] Webpack plugin to use Three.js "examples" classes
Stars: ✭ 45 (-30.77%)
Mutual labels:  npm-package
npmlint
[DEPRECATED] Lint your npm package
Stars: ✭ 57 (-12.31%)
Mutual labels:  npm-package
stimulus-content-loader
A Stimulus controller to asynchronously load HTML from an url.
Stars: ✭ 39 (-40%)
Mutual labels:  npm-package
powerquery-parser
A parser for the Power Query / M formula language, written in TypeScript
Stars: ✭ 79 (+21.54%)
Mutual labels:  microsoft
fadable
Fade in elements as they move into view, at both the bottom and top of the viewport.
Stars: ✭ 16 (-75.38%)
Mutual labels:  npm-package
djb2a
DJB2a non-cryptographic hash function
Stars: ✭ 31 (-52.31%)
Mutual labels:  npm-package

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.

buttons

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

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].