Git Product home page Git Product logo

berberich / active-directory-b2c-javascript-nodejs-webapi Goto Github PK

View Code? Open in Web Editor NEW

This project forked from azure-samples/active-directory-b2c-javascript-nodejs-webapi

0.0 1.0 0.0 59 KB

A small Node.js Web API for Azure AD B2C that shows how to protect your web api and accept B2C access tokens using Passport.js.

Home Page: http://aka.ms/aadb2c

License: MIT License

JavaScript 100.00%

active-directory-b2c-javascript-nodejs-webapi's Introduction

page_type languages products description urlFragment
sample
javascript
node.js
microsoft-identity-platform
azure-active-directory-b2c
A sample demonstrating how to protect a Node.js web API with Azure AD B2C using the Passport.js library.
active-directory-b2c-javascript-nodejs-webapi

Node.js Web API with Azure AD B2C

This sample demonstrates how to protect a Node.js web API with Azure AD B2C using the Passport.js library. The code here is pre-configured with a registered client ID. If you register your own app, replace the client ID.

To see how to call this web API from a client application, refer to this B2C Single Page Application sample.

Contents

File/folder Description
.gitignore Defines what to ignore at commit time.
CHANGELOG.md List of changes to the sample.
CODE_OF_CONDUCT.md Code of Conduct information.
config.js Contains configuration parameters for the sample.
CONTRIBUTING.md Guidelines for contributing to the sample.
index.js Main application logic resides here.
LICENSE The license for the sample.
package.json Package manifest for npm.
process.json Contains configuration parameters for logging via Morgan.
README.md This README file.
SECURITY.md Security disclosures.

Steps to run

  1. Clone this repository.
git clone https://github.com/Azure-Samples/active-directory-b2c-javascript-nodejs-webapi.git
  1. Install Node.js if you don't already have it.

  2. Install the Node dependencies:

npm install && npm update
  1. Run the Web API. By default, it runs on http://localhost:5000
npm start

Using your own Azure AD B2C tenant

To have a proper understanding of Azure AD B2C as a developer, follow the tutorials in the official Azure AD B2C documentation. In the rest of this guide, we summarize the steps you need to go through.

Step 1: Get your own Azure AD B2C tenant

You first need an Azure AD B2C tenant. If you don't already have one you can use for testing purposes, create your own by following the steps in Tutorial: Create an Azure Active Directory B2C tenant.

Step 2: Create your own policies

This sample uses a unified sign-up/sign-in policy. You can create your own unified sign-up/sign-in policy. You may choose to include as many or as few identity providers as you wish.

If you already have existing policies in your Azure AD B2C tenant, feel free to reuse those policies in this sample.

Step 3: Register your own web API with Azure AD B2C

Follow the steps in Protect and grant access to a Node.js web API to register the web API application in your tenant, define scopes, and grant a web application access to the API. By following the steps in the tutorial, you define the scopes that your single-page application will request access tokens for.

Step 4: Configure your application source code

You can now fill in the variables in the config.js file of the Node.js web API sample with the parameters you've obtained from the Azure portal by following the steps above.

Configure the following variables:

const clientID = "<Application (client) ID of your Node.js web API, e.g. 93733604-0000-0000-0000-87084dd55348>"
const b2cDomainHost = "<Domain name of your B2C authority, e.g. fabrikamb2c.b2clogin.com>";
const tenantId = "<Domain name of your B2C tenant, e.g. fabrikamb2c.onmicrosoft.com>";
const policyName = "<Name of your sign in / sign up policy. Example: B2C_1_SUSI>";

NOTE

Developers using the Azure China environment MUST use <your-tenant-name>.b2clogin.cn authority instead of login.chinacloudapi.cn.

To use <your-tenant-name>.b2clogin.*, you need set validateIssuer: false. Learn more about using b2clogin.com.

Step 5: Run the application

Lastly, to run your Node.js Web API, execute the following commands in your shell or terminal:

npm install && npm update
npm start

Your Node.js web API is now running on port 5000.

Questions & issues

Please file any questions or problems with the sample as a GitHub issue. You can also post on Stack Overflow with the tag azure-ad-b2c.

Contributing

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

Code of conduct

For details, see CODE_OF_CONDUCT.md.

active-directory-b2c-javascript-nodejs-webapi's People

Contributors

berberich avatar danieldobalian avatar derisen avatar gsacavdm avatar jennyf19 avatar jmprieur avatar microsoftopensource avatar mmacy avatar msftgits avatar navyasric avatar parakhj avatar supernova-eng 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.