Search code examples
reactjsazureazure-active-directory

Azure AD Authentication and Authorization React.js


I have a requirement of using Azure AD for authentication in React.js. This can be done using NPM package but the react.js application is calling API to get/update data.

I want to allow API to only return data when user is authenticated means if someone has direct URI of API it should not return data instead show authentication error.

As react.js only works at front end, how to use that authentication for calling API?


Solution

  • If you are using React.Js or any other Javascript front end technology , Then to authenticate Azure Active Directory you can use Implicit Grand Flow and it isrecomended to use your app as a single page application as per documents.

    The libreary which can help you is MSAL.js and you can find MSAL.js code sample here.