GithubHelp home page GithubHelp logo

ehtick / active-directory-b2c-dotnet-uwp Goto Github PK

View Code? Open in Web Editor NEW

This project forked from azure-samples/active-directory-b2c-dotnet-uwp

0.0 0.0 0.0 65 KB

Sample showing how a Windows Universal Platform (UWP) application can sign in a user using Azure AD B2C, get an access token using MSAL.NET and call an API. http://aka.ms/aadb2c

License: MIT License

C# 100.00%

active-directory-b2c-dotnet-uwp's Introduction

page_type languages products description urlFragment
sample
csharp
azure
This simple sample demonstrates how to use the Microsoft Authentication Library (MSAL) for .NET to get an access token and call an API.
active-directory-b2c-dotnet-uwp

Universal Windows Platform (UWP) application signing in users with Azure Active Directory B2C and calling an API

This simple sample demonstrates how to use the Microsoft Authentication Library (MSAL) for .NET to get an access token and call an API secured by Azure AD B2C.

This sample is very similar to the active-directory-b2c-dotnet-desktop sample except that it's implemented for the UWP plaform instead of WPF.

How To Run This Sample

To run this sample you will need:

  • Visual Studio 2015
  • An Internet connection
  • At least one of the following accounts:
  • An Azure AD B2C tenant

If you don't have an Azure AD B2C tenant, you can follow those instructions to create one. If you just want to see the sample in action, you don't need to create your own tenant as the project comes with some settings associated to a test tenant and application; however it is highly recommend that you register your own app and experience going through the configuration steps below.

Step 1: Clone or download this repository

From your shell or command line:

git clone https://github.com/Azure-Samples/active-directory-b2c-dotnet-uwp.git

[OPTIONAL] Step 2: Create an Azure AD B2C application

You can run the sample as is with its current settings, or you can optionally register it as a new application under your own developer account. Creating your own app is highly recommended.

IMPORTANT: if you choose to perform one of the optional steps, you have to perform ALL of them for the sample to work as expected.

You can find detailed instructions on how to create a new mobile / native app on this page Make sure to:

  • Copy down the Application Id assigned to your app, you'll need it in the next optional steps.
  • Copy down the Redirect URI you configure for your app.

[OPTIONAL] Step 3: Create your own policies

This sample requires your B2C app to the following policy types "Sign Up or Sign In", "Edit Profile" and "Reset Password". You can follow the instructions in this tutorial to create them. Once created, replace the following value in the App.xaml.cs file with your own policy name. All B2C policies should begin with b2c_1_.

public static string PolicySignUpSignIn = "b2c_1_susi";

[OPTIONAL] Step 4: Create your own API

Our sample calls the Web API produced by the following sample https://github.com/Azure-Samples/active-directory-b2c-javascript-nodejs-webapi (and pre-hosted in Azure). See the README.md file for that sample to understand better how to create your own Web API.

[OPTIONAL] Step 5: Configure the Visual Studio project with your app coordinates

  1. Open the solution in Visual Studio 2015 or 2017.
  2. Open the App.xaml.cs file.
  3. Find the assignment for public static string ClientID and replace the value with the Application ID from Step 2.
  4. Find the assignment for each of the policies public static string PolicyX and replace the names of the policies you created in Step 3.
  5. Find the assignment for the scopes public static string[] Scopes and replace the scopes with those you created in Step 4.

[OPTIONAL] Step 6: Enable Windows Integrated Authentication when using a federated Azure AD tenant

Out of the box, this sample is not configured to work with Windows Integrated Authentication (WIA) when used with a federated Azure Active Directory domain. To work with WIA the application manifest must enable additional capabilities. These are not configured by default for this sample because applications requesting the Enterprise Authentication or Shared User Certificates capabilities require a higher level of verification to be accepted into the Windows Store, and not all developers may wish to perform the higher level of verification. To enable Windows Integrated Authentication, in Package.appxmanifest, in the Capabilities tab, enable:

  1. Enterprise Authentication
  2. Private Networks (Client & Server)
  3. Shared User Certificates

Also, in the constructor of the application in App.xaml.cs, add the following line of code: authContext.UseCorporateNetwork = true;

Step 7: Run the sample

  1. Clean the solution, rebuild the solution, and run it.
  2. Click the sign-in button at the top of the application screen. The sample works exactly in the same way regardless of the account type you choose, apart from some visual differences in the authentication and consent experience. Upon successful sign in, the application screen will list some basic profile info for the authenticated user and show buttons that allow you to edit your profile, call an API and sign out.
  3. Close the application and reopen it. You will see that the app retains access to the API and retrieves the user info right away, without the need to sign in again.
  4. Sign out by clicking the Sign out button and confirm that you lose access to the API until the exit interactive sign in.

More information

For more information on Azure B2C, see the Azure AD B2C documentation homepage.

active-directory-b2c-dotnet-uwp's People

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.