[core-http] Use an external token cache in BearerTokenAuthenticationPolicy#4174
[core-http] Use an external token cache in BearerTokenAuthenticationPolicy#4174daviwil merged 3 commits intoAzure:masterfrom
Conversation
There was a problem hiding this comment.
Out of curiosity, what part will manage the cache?
There was a problem hiding this comment.
The consuming policy, though right after sending this I realized that there's probably value in sharing token expiration logic in a more legitimate class instead of using a simple object that must be managed by the policy implementation. Thoughts?
There was a problem hiding this comment.
I agree that there's definitely value in centralizing token expiration management, otherwise we will end up with a bug somewhere, or at least different implementations to a small extent. I wonder what would be the benefits of distributed token expiration logic, if that route is decided.
|
An all-around better implementation for this could be the following:
I think that gives us a bit more flexibility and some code reuse since we're already going to be using an external cache with the current |
|
Now that I think about it, the |
b97bd76 to
2c18eea
Compare
ea9a438 to
9b57d66
Compare
9b57d66 to
3b86ee1
Compare
|
Redesigned the |
3b86ee1 to
0490c89
Compare
0490c89 to
1e01e71
Compare
|
Confirmed with @jonathandturner offline that this approach looks good for use in the challenge-based auth implementation. Merging this, thanks all! |
This change implements a simple
AccessTokencache in thebearerTokenAuthenticationPolicyfactory so that tokens will be cached correctly acrossBearerTokenAuthenticationPolicyinstances. This is needed becausecore-httpuses aRequestPolicyFactoryarray to create a fresh list of request policies for each request sent through the pipeline.The old caching behavior in
BearerTokenAuthenticationPolicyassumed that there would only ever be a single instance of that class per client, meaning that the existing token cache implementation is ineffective across multiple requests.This new behavior stores a simple object in the factory function's closure which gets used as an
AccessTokenCachefor everyBearerTokenAuthenticationPolicyinstance created by that factory, resulting in a per-client token cache.Questions for Reviewers
It seems that this interface needs to be exported through the public interface ofcore-httpso that anyone using theBearerTokenAuthenticationPolicyclass directly (not through the factory function) will be able to see the type. Does that sound like something we should be doing?Since this type of token cache will probably be needed for other authentication policies (like @jonathandturner'sChallengeBasedAuthenticationPolicyChallenge-based authentication #4141 ), should I move theAccessTokenCacheinto the newcore-authonce that comes online?