TransportHandler.ProcessMessageAsync overwrites Authorization provided by a custom RequestHandler
See original GitHub issueDescribe the bug
When using ResourceTokens that may expire, I have a custom RequestHandler
that will pull an updated token and write it to the RequestMessage.Headers
. The TransportHandler.ProcessMessageAsync
does not check for an existing header before overwriting it with the expired value.
internal Task<DocumentServiceResponse> ProcessMessageAsync(
RequestMessage request,
CancellationToken cancellationToken)
{
if (request == null)
{
throw new ArgumentNullException(nameof(request));
}
DocumentServiceRequest serviceRequest = request.ToDocumentServiceRequest();
- //TODO: extrace auth into a separate handler
- string authorization = ((IAuthorizationTokenProvider)this.client.DocumentClient).GetUserAuthorizationToken(
- serviceRequest.ResourceAddress,
- PathsHelper.GetResourcePath(request.ResourceType),
- request.Method.ToString(),
- serviceRequest.Headers,
- AuthorizationTokenType.PrimaryMasterKey,
- payload: out _);
-
- serviceRequest.Headers[HttpConstants.HttpHeaders.Authorization] = authorization;
+ if (string.IsNullOrEmpty(serviceRequest.Headers[HttpConstants.HttpHeaders.Authorization]))
+ {
+ //TODO: extrace auth into a separate handler
+ string authorization = ((IAuthorizationTokenProvider)this.client.DocumentClient).GetUserAuthorizationToken(
+ serviceRequest.ResourceAddress,
+ PathsHelper.GetResourcePath(request.ResourceType),
+ request.Method.ToString(),
+ serviceRequest.Headers,
+ AuthorizationTokenType.PrimaryMasterKey,
+ payload: out _);
+
+ serviceRequest.Headers[HttpConstants.HttpHeaders.Authorization] = authorization;
+ }
IStoreModel storeProxy = this.client.DocumentClient.GetStoreProxy(serviceRequest);
if (request.OperationType == OperationType.Upsert)
{
return this.ProcessUpsertAsync(storeProxy, serviceRequest, cancellationToken);
}
else
{
return storeProxy.ProcessMessageAsync(serviceRequest, cancellationToken);
}
}
Environment summary SDK Version: Source OS Version (e.g. Windows, Linux, MacOSX)
Additional context Add any other context about the problem here (for example, complete stack traces or logs).
Issue Analytics
- State:
- Created 4 years ago
- Reactions:1
- Comments:6 (6 by maintainers)
Top Results From Across the Web
[Feature] CosmosClient multi-tenant enablement · Issue #651
This issue is trying to address the CosmosClient gaps only. Hence token generation gaps are out-of-scope. Possibilities. Authorization provider ...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
@ausfeldt will implementing a swap credentials be easier once the work is done for the auth fix you are working on?
I don’t see any reason to not support it in v3. It’s not a breaking change.
I think it should be both v3 and v4.