Configuring Microsoft Graph bindings for Azure Functions with B2C

Create an App Registration with proper user

App Registration Relationship

Create a new B2C user

Create a new admin account. Go to Azure Active Directory > Users > All users > New user. You need to create a user as admin. Then Login Azure using the new user.

Create a new user with admin

Creating App Registration by the B2C user

Login as a B2C user (on the example, chirs account) on Azure. Go to Azure Active Directory > App registrations > New application registration

Create an App Registration by the B2C user
Create a new app registrations
Select “Windows Azure Active Directory” permission
Grant permissions to the App Registration

Get the Application ID and Password

You need to create a key on the App Registration page. Go to Settings > Keys and create a key (password). Then get the Application ID

ApplicationID and Key

Configure Function App

Then configure the Function App to fetch the token for the Graph API of B2C. Re-login at the original user to Azure and create a function app. Then Go to Authentication / Authorization on the Platform features

Authentication / Authorization settings
Azure Active Directory
Active Directory Authentication (Advanced)

Writing an Azure Functions using Graph Bindings

Binding code is quite easy, all you need to do is define the Token. This is the binding part to fetch the token.

public static async Task<IActionResult> RunAsync([HttpTrigger(AuthorizationLevel.Function, "get", "post", Route = null)]HttpRequest req,            
[Token(Identity = TokenIdentityMode.ClientCredentials, Resource = "https://graph.windows.net")]string token,
TraceWriter log)
request.RequestUri = new System.Uri("https://graph.windows.net/someorganication.onmicrosoft.com/users?api-version=1.6");            request.Headers.Authorization = new System.Net.Http.Headers.AuthenticationHeaderValue("Bearer", token);            var client = await httpClient.SendAsync(request);

Resource

Special Thanks

Thank you for the hackfest team mate. Especially, Naohiro Fujie for teaching me about the B2C settings and Chris Gillum for the writing bindings.

The hackfest team

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store