Git Product home page Git Product logo

active-directory-javascript-graphapi-v2's Introduction

page_type languages products description urlFragment
sample
javascript
microsoft-identity-platform
azure-active-directory-v2
microsoft-graph-api
A simple JavaScript single-page application calling Microsoft Graph API using msal.js (w/ AAD v2 endpoint)
active-directory-javascript-graphapi-v2

MSAL JavaScript Sample Application

A simple vanilla JavaScript single-page application which demonstrates how to configure MSAL.JS Core to login, logout, protect a route, and acquire an access token for a protected resource such as Microsoft Graph API.

Note: A quickstart guide covering this sample can be found here.

Note: A more detailed tutorial covering this sample can be found here.

Contents

File/folder Description
AppCreationScripts Contains automation scripts for Powershell users (can be safely removed if desired).
JavaScriptSPA Contains sample source files.
authPopup.js Main authentication logic resides here (using Popup flow).
authRedirect.js Use this instead of authPopup.js for authentication with redirect flow.
authConfig.js Contains configuration parameters for the sample.
graph.js Provides a helper function for calling MS Graph API.
graphConfig.js Contains API endpoints for MS Graph.
ui.js Contains UI logic.
index.html Contains the UI of the sample.
.gitignore Defines what to ignore at commit time.
CHANGELOG.md List of changes to the sample.
CODE_OF_CONDUCT.md Code of Conduct information.
CONTRIBUTING.md Guidelines for contributing to the sample.
LICENSE The license for the sample.
package.json Package manifest for npm.
README.md This README file.
SECURITY.md Security disclosures.
server.js Implements a simple Node server to serve index.html.

Prerequisites

Node 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 implicit flow.
  2. Open the /JavaScriptSPA/authConfig.js file and provide the required configuration values.
  3. 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 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:
    1. Open graphConfig.js.
    2. Replace the string "Enter_the_Graph_Endpoint_Herev1.0/me" with "https://graph.microsoft.com/v1.0/me".
    3. Replace the string "Enter_the_Graph_Endpoint_Herev1.0/me/messages" with "https://graph.microsoft.com/v1.0/me/messages".
  3. To start the sample application, run npm start.
  4. Finally, open a browser to http://localhost:3000.

Key points

This sample demonstrates the following MSAL workflows:

  • How to configure application parameters.
  • How to sign-in with popup and redirect methods.
  • How to sign-out.
  • How to get user consent incrementally.
  • How to acquire an access token.
  • How to make an API call with the access token.

Contributing

If you'd like to contribute to this sample, see CONTRIBUTING.MD.

Code of Conduct

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.

active-directory-javascript-graphapi-v2's People

Contributors

aashiman avatar andretms avatar archieag avatar artemgurzhii avatar burkeholland avatar darylthayil avatar derisen avatar jmprieur avatar microsoftopensource avatar msftgits avatar navyasric avatar pkanher617 avatar plamber avatar sameerag avatar v-hearya avatar

Stargazers

 avatar

Watchers

 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.