Giter Site home page Giter Site logo

b2c-nativeclient-xamarin's Introduction

Cross Platform Xamarin.Forms 2.0 ToDoList client with Azure AD B2C authentication sample

This sample is in terms of authentication adapted for B2C from https://blog.xamarin.com/put-adal-xamarin-forms/. The Web Api accessed by the app is secured with OAuth Bearer token processing.

How to use this sample

Prerequisites

  • Xamarin for Visual Studio 2015

Step 1 : download the sample code

From your shell or command line:

git clone https://github.com/KaiWalter/B2C-NativeClient-Xamarin.git

Step 2 : configure App in B2C tenant

Go to your B2C tenant and add a Native Client app.

  • Web App / Web API : No
  • Native client : Yes

Copy/paste Application Client ID for use in steps 4+6

Step 3 : configure policies in B2C tenant

Create these policies and copy/paste names generated by the Portal for use in steps 4+6

sign-up policy

  • sign-up attributes: Display Name, Email Address
  • application claims: Display Name, Email Address, User's Object ID

sign-in policy

  • application claims: Display Name, Email Address, User's Object ID

profile policy

  • profile attributes: Display Name
  • application claims: Display Name, Email Address, User's Object ID

Step 4 : configure settings in Web.Config

Open Visual Studio 2015 solution and navigate to Web.Config in the TodoList_Service projects root. Enter your tenant name and paste values created in steps 2+3.

    <add key="ida:Tenant" value="[Tenant name of your Azure AD B2C e.g. contoso.onmicrosoft.com]" />
    <add key="ida:ClientId" value="[Client ID of B2C App created in Portal e.g. ac12a187-c653-4236-970c-65807dc4413d]" />
    <add key="ida:PolicyId" value="[Sign in policy name as created in Portal e.g. B2C_1_todolist_signin]" />

Step 5 : build and publish service

  • Restore nuget packages for TodoListService project
  • build TodoListService
  • publish as App Service to Azure, Organizational Authentication is not needed

Step 6 : Configure settings in Globals.cs

Navigate to Globals.cs in TodoList_Client projects root. Enter your tenant name and paste values created in steps 2+3. Enter URL of TodoList service published in step 5.

    public static class Globals
    {
        // TODO: Replace these with your own configuration values
        public static string tenant = "[Tenant name of your Azure AD B2C e.g. contoso.onmicrosoft.com]";
        public static string clientId = "[Client ID of B2C App created in Portal e.g. ac12a187-c653-4236-970c-65807dc4413d]";
        public static string signInPolicy = "[Sign in policy name as created in Portal e.g. B2C_1_todolist_signin]";
        public static string signUpPolicy = "[Sign up policy name as created in Portal e.g. B2C_1_todolist_signup]";
        public static string editProfilePolicy = "[Edit profile policy name as created in Portal e.g. B2C_1_todolist_profile]";

        public static string aadInstance = "https://login.microsoftonline.com/";
        public static string redirectUri = "urn:ietf:wg:oauth:2.0:oob";

        public static string todoListBaseAddress = "[Base URL of ToDo List of service published to Azure App Service e.g. https://my-todolist-service.azurewebsites.net]";

    }

Step 7 : build and run Windows Phone app

  • Restore nuget packages for TodoListClient project
  • build and run TodoListClient

any other stuff

ADAL v4 for each project in solution

  • install-package Microsoft.Experimental.IdentityModel.Clients.ActiveDirectory -pre

GIT do not commit client/app settings

  • git update-index --assume-unchanged "TodoList_Client\TodoList_Client\Globals.cs"
  • git update-index --assume-unchanged "TodoList_Service\Web.config"
  • git update-index --assume-unchanged "TodoList_Service\Properties\PublishProfiles..."

use --no-assume-unchanged to reserve

b2c-nativeclient-xamarin's People

Contributors

kaiwalter avatar

Watchers

 avatar  avatar

Forkers

sjwaight

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.