-
Notifications
You must be signed in to change notification settings - Fork 145
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
How can this sample be modified to be used in a serverless environment? #54
Comments
On a high level, yes. The actual cache persistence layer has to be determined by your app's architecture. And this topic is not just about token cache. When your app is serverless or stateless, you would need to use a different way to persist your session data, regardless of whether your app requires authentication. Once you have your session mechanism ready, the current sample will automatically work again, piggybacking your chosen session solution. From a tactical perspective, this sample currently uses a 3rd-party library, Alternatively, you can also choose to encrypt and then store session on client side. The downside is the cookie size may become larger.
This part is purely your implementation detail. You may inherit |
Hi @wolfit, Please be aware that client-side session cookies are size-limited and IIRC, storing the token cache client-side might fail due to hitting this limit. If your use-case doesn't need your access tokens automatically renewed by MSAL using refresh tokens for offline_access (e.g., continuous access to user's protected external resources when user is not on your app), you won't need to store the token cache anyway (i.e., you'd only need to store In such a scenario, for a currently-logged-in user, you simply pass |
Related to this discussion: I've created a branch that deploys this sample using Azure App Service as the host and Azure Cache for Redis as the session storage. Notable changes to app_config.py:
I use Bicep and the Azure Developer CLI to set those environment variables in App Service. A similar approach could be used for a MongoDB SESSION_TYPE (with Azure CosmosDB) or a SQLAlchemy SESSION_TYPE (with Azure PostgreSQL Flexible Server). |
When running Flask (or other webserver) in an Azure function (or similar) I guess the web session based cache in the sample can not be used because of the ephemeral nature of Cloud functions.
How to get this sample and this particular authorization flow work in a serverless environment?
Is it a matter of implementing your own cache where you store and handle the access token and refresh token?
In that case, would you suggest that cache implementation to inherit from SerializableTokenCache?
The text was updated successfully, but these errors were encountered: