chainlit icon indicating copy to clipboard operation
chainlit copied to clipboard

Refreshing Azure OAuth2 access_tokens for long user sessions

Open fcestari opened this issue 1 year ago • 0 comments
trafficstars

Is your feature request related to a problem? Please describe. I'm facing an issue with handling OAuth2 tokens with the Azure azure-ad provider. When a user session extends beyond the lifetime of the access_token, the token expires, and it seems there is no built-in method in the library to handle the refresh of these tokens. This interrupts the user session and requires manual intervention to reauthorize.

Describe the solution you'd like Automatic handling of OAuth2 access tokens. For example, Azure has python SDKs like azure-identity and msal that automatically handle token cache and token refresh.

Describe alternatives you've considered I have created an additional class that inherits from base class AzureADOAuthProvider and overrode the methods get_token and get_user_info, as in my scenario I need to use on-behalf-of flow. I've utilized the azure-identitycredential classes for these methods, AuthorizationCodeCredential and OnBehalfOfCredential respectively, and tried to pass them and store in the user session to be used later on for external API requests towards Azure, but no good.

Additional context I'd very much appreciate if you can give directions on how to use the user session cl.user_session and the cl.oauth2_callback to always have refreshed access tokens towards Azure services.

fcestari avatar May 15 '24 08:05 fcestari