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.
- Xamarin for Visual Studio 2015
From your shell or command line:
git clone https://github.com/KaiWalter/B2C-NativeClient-Xamarin.git
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
Create these policies and copy/paste names generated by the Portal for use in steps 4+6
- sign-up attributes: Display Name, Email Address
- application claims: Display Name, Email Address, User's Object ID
- application claims: Display Name, Email Address, User's Object ID
- profile attributes: Display Name
- application claims: Display Name, Email Address, User's Object ID
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]" />
- Restore nuget packages for TodoListService project
- build TodoListService
- publish as App Service to Azure, Organizational Authentication is not needed
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]";
}
- Restore nuget packages for TodoListClient project
- build and run TodoListClient
- install-package Microsoft.Experimental.IdentityModel.Clients.ActiveDirectory -pre
- 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