Reducing the cost of building a ClientApplication #681
-
ContextI am building a web app that logs a user in and that then accesses a protected web api. I have found that building a ConfidentialClientApplication is costly. Due to tenant discovery, atleast one get request is sent. This means that acquiring a token from the cache incurs this same cost. Ideally you would build the ClientApplication once, and reuse it. There is, however, some (standard) overhead involved:
The documentation offers no information on how to address these scenarios, especially now that the move to identity has been initiated. The only relevant information I found was: a comment in the code suggesting the CCA should be "long-lived", a mention in the new identity documentation that the instance is expected to be long-lived. QuestionsI hope you could clarify the following things in the documentation, for me and future developers:
I have done a lot of digging myself, and can identify some threading issues, but it would be nice to include them in the documentation. Lastly, there is also the question of async support. I see that this issue tracks the progress already, so I have excluded that from this discussion. |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments
-
Thanks for your input, Auke. You clearly did your homework. Good job.
OK, "long-lived" is not about a specific length of time. It is about suggesting you to reuse it. In general, any API that is designed in an Object-Oriented fashion, it kind of implies that you can construct an instance and then reuse it for as long as you possibly can, contrary to a function-based design which is clearly an one-off run for each function call.
A CCA in the web app context has its unique challenge, indeed. Rather than writing some lengthy how-to documentation (which not necessarily many people would read), we believe it is more efficient to build higher level samples and/or libraries which just implement it precisely right. You can find existing samples from the Scenarios section in MSAL Python documentation, where the blue icons are clickable. The web app sample there is what you need. It works and can be a good starting point for you to understand how it is done.
MSAL Python's token cache implementation already has a built-in threading lock. If you use your own TokenCache implementation, you can fully control threading issues by yourself. With your awareness of threading issues, you would probably do it well. |
Beta Was this translation helpful? Give feedback.
-
Thank you for your response, and your clear explanations. I am a documentation reader myself, but you make a strong case. I will do some more digging and experimentation myself! |
Beta Was this translation helpful? Give feedback.
Thanks for your input, Auke. You clearly did your homework. Good job.
OK, "long-lived" is not about a specific length of time. It is about suggesting you to reuse it. In general, any API that is designed in an Object-Oriented fashion, it kind of implies that you can construct an instance and then reuse it for as long as you possibly can, contrary to a function-based design which is clearly an one-off run for each function call.
A CCA in the web app context has its unique challenge, indeed. Rather than writing some lengthy h…