Azure-Samples / ms-identity-python-webapp

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

One cache per multiple users #68

Closed marchar91 closed 2 years ago

marchar91 commented 3 years ago

Hello, I am working on a project and I am using as starting point the provided application in this repo. The user need to authenticate first, then, using On Behalf Of flow, I get a second token that I use for getting data from a SQL database in Azure by using pass-through authentication. As of now, I have all expected result when testing with a single user but it doesn't work by testing with multiple users (not necessarily at the same exact time). Especially this is the wrong behavior:

The same happens the other way around, after cleaning the session: if I log in with the user that doesn't have any permission, I have an error (correctly in this case) but, if I log in with the user that should have permissions, from a fresh session, then I have the same error (wrong, the user has permissions). I suspect that the problem is that the provided example use a single cache for all the users, in fact, analysing the serialised cache value, after the first signin the corresponding dictionary has one user, but, after the second one, there are multiple users there, and they come from the cache serialisation. I would expect to have a proper management by having one cache per user or per session basically. Are my suspects correct? If so, how can I handle it? Thanks

rayluo commented 3 years ago

Sounds like your app somehow mixed the tokens among users. How does your app persist token cache?

Can you reproduce the issue with this sample? It persists the tokens into current session, so it shouldn't have this issue.

marchar91 commented 2 years ago

Sorry for the late reply, my issue was related to this implementation which was causing the reuse of the cache for multiple users. I removed the cache instance from the constructor and handle the cache management more similarly to your example and works properly