question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

How to use OAuth 2.0 with @azure/msal-react package?

See original GitHub issue

Library

  • msal@1.x.x or @azure/msal@1.x.x
  • @azure/msal-browser@2.x.x
  • @azure/msal-node@1.x.x
  • @azure/msal-react@1.x.x
  • @azure/msal-angular@0.x.x
  • @azure/msal-angular@1.x.x
  • @azure/msal-angular@2.x.x
  • @azure/msal-angularjs@1.x.x

Description

Hi All,

After successfully imposing MSAL to my page, I was asked to add an OAuth2 into my application.

Isn’t @azure/msal-react capable of it? Thanks.

Reference of my index.js


import React from 'react';
import ReactDOM from 'react-dom';
import 'index.css';
import App from 'App';
import * as serviceWorker from 'serviceWorker';
import { createStore } from 'redux'
import { Provider } from 'react-redux'
import reducer from 'store/reducer'

import { MsalProvider, MsalAuthenticationTemplate  } from "@azure/msal-react";
import { Configuration,  PublicClientApplication, InteractionType } from "@azure/msal-browser";


//, window.__REDUX_DEVTOOLS_EXTENSION__ && window.__REDUX_DEVTOOLS_EXTENSION__()
const store = createStore(reducer);

const config = {
  auth: {
    clientId: '***********************',
    authority: 'https://login.microsoftonline.com/***********************' **// <-- isn't replacing the OAuth 2 endpoint here?**
    },
  cache: {
    cacheLocation: "sessionStorage", // This configures where your cache will be stored
    storeAuthStateInCookie: false, // Set this to "true" if you are having issues on IE11 or Edge
  }
};

const pca = new PublicClientApplication(config);


ReactDOM.render(
<Provider store={store}>
  {/* <React.StrictMode> */}
  <MsalProvider instance={pca}>
    <MsalAuthenticationTemplate
      interactionType={InteractionType.Redirect}>
        <App/>
        </MsalAuthenticationTemplate>
    </MsalProvider>
   </Provider>,

  document.getElementById('root')
);

serviceWorker.unregister();

Source

  • Internal (Microsoft)
  • Customer request

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:7 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
pkanher617commented, Feb 26, 2021

@wy10cheng this is done for you by the library. The library abstracts the protocol away from the application and exposes APIs to acquire the ID and access tokens needed for your app to function. Please go through the docs and samples for msal-browser and msal-react, it should make it more apparent how to use this library.

1reaction
pkanher617commented, Feb 26, 2021

@wy10cheng I’m not sure what you are asking. OAuth 2.0 is the protocol implemented by MSAL.js libraries. Specifically, msal-react and msal-browser are implementing the OAuth 2.0 authorization code flow with PKCE. If you’d like to read more about what the OAuth 2.0 protocol describes you can read more here.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Tutorial: Create a React single-page app that uses auth code ...
In the Redirect URI: MSAL.js 2.0 with auth code flow step, enter http://localhost:3000 , the default location where create-react-app will serve ...
Read more >
@azure/msal-react - npm
Start using @azure/msal-react in your project by running `npm i ... This version of the library uses the OAuth 2.0 Authorization Code Flow ......
Read more >
Using MSAL.js to integrate React Single-page ... - YouTube
This month's in-depth topic: Deep dive on using MSAL.js to integrate React Single-page applications with Azure Active Directory.
Read more >
Calling Microsoft Graph using @azure/msal-react from PCF ...
MSAL 2.x – Implements OAuth 2.0 Authorization Code Flow with PKCE ... the @azure/msal-react npm package to call Microsoft Graph to do a ......
Read more >
@azure/msal-react examples - CodeSandbox
Learn how to use @azure/msal-react by viewing and forking ... React single-page application calling Microsoft Graph API using MSAL.js (w/ AAD v2 endpoint)....
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found