A Simple React App using OAuth2.0 via Microsoft MSAL library.
- Loging via Microsoft Authentication.
- Using Graph API to fetch user data.
Node.js must be installed to run this sample.
To get a local copy up and running, follow the given instructions below:
- Register a new application in the Azure Portal. Ensure that the application is enabled for the authorization code flow with PKCE. This will require that you redirect URI configured in the portal is of type
SPA
. - Clone this repository
git clone https://github.com/blackadi/msal_react.git
- Create
.env
file in the root of the repository. - On the command line, navigate to the root of the repository, and run
npm install
to install the project dependencies via npm.
- Configure authentication and authorization parameters:
- Open
.env
- Add
REACT_APP_CLIENT_ID:
, then add your app/client ID on AAD Portal. - Add
REACT_APP_AUTHORITY:
, then add"https://login.microsoftonline.com/common/"
(note: This is for multi-tenant applications located on the global Azure cloud. For more information, see the documentation). - Add
REACT_APP_REDIRECT_URL:
, then add the redirect uri you setup on AAD Portal. - Add
REACT_APP_GRAPH_ENDPOINT:
, after the:
add"https://graph.microsoft.com/v1.0/me"
(note: This is for MS Graph instance located on the global Azure cloud. For more information, see the documentation).
- Open
- To start the sample application, run
npm start
. - Finally, open a browser and navigate to http://localhost:3000.
docker run -it -p 3000:3000 blackadi2019/msal_spa