Azure-Samples / ms-identity-python-webapp

A Python web application calling Microsoft graph that is secured using the Microsoft identity platform
MIT License
298 stars 143 forks source link

QUESTION: Port Example to FastAPI Framework? #72

Open dignifi-richard opened 2 years ago

dignifi-richard commented 2 years ago

Has anyone ported this exact example to FastAPI as an MVC app (as opposed to just API)? Seems like a super simple example and it works great in Flask but it's giving me fits in FastAPI. I can get it to log in but having issues accepting the token at the call back URI. Does anyone have an example of this in FastAPI, or willing to put a quick example together? I'd be grateful.

pamelafox commented 1 year ago

Hi @dignifi-richard, We're just going through old issues, sorry for the lack of response. Did you end up porting it to FastAPI? The code for this sample is actually a lot simpler now, as it's using a higher level package, identity, instead of msal.

dignifi-richard commented 1 year ago

Yes, thank you @pamelafox. We ported to FastAPI with the msal package. I'd like to see the updated code that you mention. Can you point me in the right direction?

pamelafox commented 1 year ago

Great to hear you were able to get it working on FastAPI!

The change is here in the master branch of this repo:

https://github.com/Azure-Samples/ms-identity-python-webapp/blob/master/app.py

The configuration is the same, but the identity package handles underlying msal commands.

pamelafox commented 1 year ago

I also just found someone published their FastAPI msal sample a few years ago, linking it here for anyone who finds this issue: https://github.com/AzureAD/microsoft-authentication-library-for-python/issues/448

Also potentially useful, this msal plugin for FastAPI: https://github.com/dudil/fastapi_msal