O365 / python-o365

A simple python library to interact with Microsoft Graph and Office 365 API
Apache License 2.0
1.65k stars 419 forks source link

User Provided Authentication #987

Open PvanHengel opened 1 year ago

PvanHengel commented 1 year ago

Hi,

This library looks great, and the way it is plugged into langchain is super cool. Question: our users are already authenticated interactively through the front end of our app, and we have the access token required, is there a way we can bypass all the authentication logic, and just give the token? Ive been trying to fool it in the Account Setup, by passing a custom token backend seeded with the token, but pydantic and other places, do not allow it to work unless we call the authenticate function, which has a good amount of rigidity in its checks to get the user in various ways, but none let an external token /session to be provided. Any guidance would be great!

alejcas commented 1 year ago

Yep you can either use the default tokenbackend and store the token as json in a file or define your own tockendbacked that get and sets the token somehow (environment, databade, etc). There are some already done tockendbackends like firebase and more.

PvanHengel commented 1 year ago

agreed yes we can easily use different token stores, my issue is around how the token is acquired we have a react front end that does all the work and want to be able to pass the token to the python back end, basically no token store needed, the current flows as I understand it do not allow for the access token to be provided externally

alejcas commented 1 year ago

To acquire the token (if you are authenticating on behalf of a user) check:

https://github.com/O365/python-o365#different-authentication-interfaces

There's is an example on how to do it using a web app interface

PvanHengel commented 1 year ago

Thanks yea I saw that this flow assumes we are doing three legged and the back end, we are using pkce on front end so the token is maintained there using the msal library, we can pass the current token to the api on the back end when we make the request. This flow assumes the redirect and codes exchange for the token.

djk1983 commented 10 months ago

I am trying to achieve a similar thing. I have a Streamlit application that users sign in via MSAL so a token is already held.

From there I am struggling to ascertain how to pass the existing token to call O365 functions without directly authenticating via O365.

alejcas commented 10 months ago

It should be possible to load the msal token info into a O364 token class. It’s just json with the token info

i can look into it if you can extract this token info from msal

djk1983 commented 10 months ago

That would be very helpful. I can access the token, which is currently held in memory. I would like to avoid writing to disk as I have not yet created secure storage.

alejcas commented 9 months ago

I didn't have time for this. But if you have access to the msal token you can extract the token info and load it into a token class then use it in O365

akesh1235 commented 6 months ago

I have already authenticated my app with the Azur App Directory and obtained the necessary credentials. CLIENT_ID and CLIENT_SECRET. But, When I am trying to connect LangChain by specifying credentials, I am getting ERROR: AADSTS900971: No reply address provided.