Giter Club home page Giter Club logo

b2c-dotnet-webapp-and-webapi's Introduction

services platforms author
active-directory-b2c
dotnet
parakhj

Azure AD B2C: Call a .NET web API from a .NET web app

This sample has a solution file that contains two projects: TaskWebApp and TaskService. TaskWebApp is a "To-do" MVC web application that the user interacts with. TaskService is the app's back-end web API that stores each user's to-do list. You can use this sample to quickly get started with building a .NET web app, web api, and calling the api from the web app.

The sample also covers:

  • Calling an OpenID Connect identity provider (Azure AD B2C)
  • Acquiring a token from Azure AD B2C using MSAL

See our detailed documentation on:

Getting started

Our sample is configured to use the policies and client ID of our demo tenant. To use our sample with your own configuration:

  1. Create an Azure AD B2C tenant.
  2. Register a web api.
  3. Register a web app.
  4. Set up policies.
  5. Grant the web app permissions to use the web api.

Note: The client application and web API must use the same Azure AD B2C directory.

Update the Azure AD B2C configuration

Open web.config in the TaskService project and replace the values for

  • ida:Tenant with your tenant name
  • ida:ClientId with your web api application ID
  • ida:SignUpSignInPolicyId with your "Sign-up or Sign-in" policy name

Open web.config in the TaskWebApp project and replace the values for

  • ida:Tenant with your tenant name
  • ida:ClientId with your web app application ID
  • ida:ClientSecret with your web app secret key
  • ida:SignUpSignInPolicyId with your "Sign-up or Sign-in" policy name
  • ida:EditProfilePolicyId with your "Edit Profile" policy name
  • ida:ResetPasswordPolicyId with your "Reset Password" policy name

Run the sample

Build and run both the apps. Sign up and sign in, and create tasks for the signed-in user. Sign out and sign in as a different user. Create tasks for that user. Notice how the tasks are stored per-user on the API, because the API extracts the user's identity from the token it receives. Also try playing with the scopes. Remove the permission to "write" and then try adding a task. Just make sure to sign out each time you change the scope.

Next Steps

Customize your user experience further by supporting more identity providers. Checkout the docs belows to learn how to add additional providers:

Microsoft

Facebook

Google

Amazon

LinkedIn

Questions & Issues

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

b2c-dotnet-webapp-and-webapi's People

Contributors

microsoftopensource avatar gsacavdm avatar msftgits avatar parakhj avatar

Watchers

James Cloos 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.