Giter VIP home page Giter VIP logo

azure-ad-react-spa's Introduction

React single-page application built with MSAL React and Microsoft identity platform

This sample demonstrates how to use MSAL React to login, logout, conditionally render components to authenticated users, and acquire an access token for a protected resource such as Microsoft Graph.

Features

This sample demonstrates the following MSAL React concepts:

  • Configuration
  • Login
  • Logout
  • Conditionally rendering components for authenticated or unauthenticated users
  • Acquiring an access token and calling Microsoft Graph

Contents

File/folder Description
src Contains sample source files
styles Contains styling for the sample
components Contains ui components such as sign-in button, sign-out button and navbar
public Contains static content such as images and the base html
authConfig.js Contains configuration parameters for the sample.
App.jsx Contains MSAL React Components and main sample content
graph.js Provides a helper function for calling MS Graph API.
index.js Contains the root component and MsalProvider
.gitignore Define what to ignore at commit time.
CHANGELOG.md List of changes to the sample.
CONTRIBUTING.md Guidelines for contributing to the sample.
package.json Package manifest for npm.
README.md This README file.
LICENSE The license for the sample.

Note: This sample was bootstrapped using Create React App.

Getting Started

Prerequisites

Node.js must be installed to run this sample.

Setup

  1. 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.
  2. Clone this repository git clone https://github.com/Azure-Samples/ms-identity-javascript-react-spa.git
  3. Open the /src/authConfig.js file and provide the required configuration values.
  4. On the command line, navigate to the root of the repository, and run npm install to install the project dependencies via npm.

Running the sample

  1. Configure authentication and authorization parameters:
    1. Open src/authConfig.js
    2. Replace the string "Enter_the_Application_Id_Here" with your app/client ID on AAD Portal.
    3. Replace the string "Enter_the_Cloud_Instance_Id_HereEnter_the_Tenant_Info_Here" with "https://login.microsoftonline.com/common/" (note: This is for multi-tenant applications located on the global Azure cloud. For more information, see the documentation).
    4. Replace the string "Enter_the_Redirect_Uri_Here" with the redirect uri you setup on AAD Portal.
  2. Configure the parameters for calling MS Graph API: 2. Replace the string "Enter_the_Graph_Endpoint_Herev1.0/me" with "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)
  3. To start the sample application, run npm start.
  4. Finally, open a browser and navigate to http://localhost:3000.

Contributing

This project welcomes contributions and suggestions. Most contributions require you to agree to a Contributor License Agreement (CLA) declaring that you have the right to, and actually do, grant us the rights to use your contribution. For details, visit https://cla.opensource.microsoft.com.

When you submit a pull request, a CLA bot will automatically determine whether you need to provide a CLA and decorate the PR appropriately (e.g., status check, comment). Simply follow the instructions provided by the bot. You will only need to do this once across all repos using our CLA.

This project has adopted the Microsoft Open Source Code of Conduct. For more information see the Code of Conduct FAQ or contact [email protected] with any additional questions or comments.

azure-ad-react-spa's People

Contributors

dependabot[bot] avatar derisen avatar jasonnutter avatar microsoft-github-operations[bot] avatar microsoftopensource avatar salman90 avatar tnorling avatar trondal avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.