Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to combine AD B2C(MSAL) and CosmosDB

I'm using appcenter Auth and Data in my Xamarin forms Application, but microsoft are shutting down these services so i now need to do it myself. Atm these two allowed me to verify my users with ADB2C and then grant them to access there own and shared content in the Cosmos Database.

What i have atm: I can log in via MSAL to my AD B2C. I can access my DB with Microsoft.Azure.DocumentDB.Core.

What i need is: I need to be able to generate Ressource Token and configure the Database so only the User can access their documents.(Only found outdated and poorly described Tutorials)

Or as an alternative: How is it possible to create Azure functions that only User which are logged in via msal can call? And then i would need the user id in the Azure function to check against the db.(All the Tutorials handle the user verification on the api call, this is not possible when calling from application)

like image 765
Olias Avatar asked Mar 02 '23 20:03

Olias


1 Answers

You cannot use the AAD B2C issued user token to access Cosmos DB resource.

Try this link - you will need to pass the B2C token to a AAD B2C protected API which then makes the API call on behalf of the user using client_credentials (AAD service account).
https://codemilltech.com/adding-azure-ad-b2c-authentication-to-azure-functions/

like image 94
Jas Suri - MSFT Avatar answered Mar 21 '23 10:03

Jas Suri - MSFT