GithubHelp home page GithubHelp logo

isabella232 / js-e2e-web-app-server-auth Goto Github PK

View Code? Open in Web Editor NEW

This project forked from azure-samples/js-e2e-web-app-server-auth

0.0 0.0 0.0 29 KB

JavaScript Express.js example using MSAL to authenticate users.

License: MIT License

JavaScript 75.90% HTML 0.03% CSS 0.81% EJS 23.26%

js-e2e-web-app-server-auth's Introduction

page_type languages name description products
sample
javascript
nodejs
Add Microsoft authentication to Express.js application
JavaScript end-to-end add Microsoft authentication with MSAL to Express.js application
azure
azure-portal
vs-code
msal-node
msal-js
microsoft-identity-web
identity
developer-tools
app-service

Add Microsoft authentication to Express.js application

For a complete tutorial, please use the Microsoft Documentation tutorial found here.

Express.js app

This sample illustrates how to integrate MSAL authentication for the Microsoft Identity provider into an Express.js app to provide:

  • Login/logout
  • Route restrictions
  • Query a restricted API, such as Graph

Usage

  1. Start by building the wrapper:

    npm install
  2. Then, configure required MSAL settings file in JSON (see: appSettings.json). The file looks like the following:

    "credentials": {
        "clientId": process.env.AD_CLIENT_ID || "REPLACE-WITH-YOUR-APP-CLIENT-ID",
        "tenantId": process.env.AD_TENANT_ID || "REPLACE-WITH-YOUR-APP-TENANT-ID",
        "clientSecret": process.env.AD_CLIENT_ID_SECRET || "REPLACE-WITH-YOUR-APP-CLIENT-ID-SECRET"
    },
  3. Run the project.

    npm start
  4. Open a browser at http://localhost:8080.

Remarks

Session support

Session support in this sample is provided by the express-session package. express-session is considered unfit for production, and you should either implement your own session solution or use a more suitable 3rd party library.

Persistent caching

MSAL Node has an in-memory cache by default. This sample also features a persistent cache plugin in order to save the cache to disk. This plugin is not meant to be production-ready. As such, you might want to implement persistent caching using a 3rd party library like redis.

More information

js-e2e-web-app-server-auth's People

Contributors

diberry avatar microsoft-github-operations[bot] avatar microsoftopensource 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.