Search code examples
fastapimsal

Azure AD B2C x FastAPI integration as a noob


I'm trying to build a fairly simple webapp with FastAPI. Besides some db query and check all it needs is authentication for the routes. I wanted to use az ad b2c for the authentication.

I'm quite inexperienced when it comes to the backend so maybe I'm just a complete failure in this case for now (Although I've implemented authentication with msal in an spa before).

I was trying to make it work in the past days but it almost burned me out completely.

If you happen to have a code sample or a "good" resource in the topic I would be more than grateful.

I tried to use msal and different third party libs too, but besides fastapi-azure-auth I couldn't make them work (but sadly fastapi-azure-auth worked once and then next morning it changed it's mind).

I know it's not a detailed explanation of what and how did I try.. but really all I ask for is a good resource (just please don't say to check the ms documentation, I consider it a big mess eg:https://github.com/AzureAD/microsoft-authentication-library-for-python/wiki/Roadmap)

Thanks in advance and hope you have a better day than me.


Solution

  • I was struggling with the same issue; I've since used this library and it's worked really well to remove the complexity: https://github.com/dudil/fastapi_msal