Answer the question
In order to leave comments, you need to log in
Why is ClaimsPrincipal lost inside OWIN middleware?
Hello.
Faced the problem of losing the ClaimsPrincipal during the operation of OAuth2 middleware providers. Its essence is this:
For logging, I need to generate a Guid as an Activity Id. This guide is then used when calling different datasources so that all logs have a single ID within a single request. Since the OAuth middleare is registered first, it generates a new activity Id value and stores it in the claims:
public override Task GrantResourceOwnerCredentials(OAuthGrantResourceOwnerCredentialsContext context)
{
var claimsPrincipal = Thread.CurrentPrincipal as ClaimsPrincipal;
claimsPrincipal.Identities.First.AddClaim(new Claim("TestClaim", Guid.NewGuid().ToString()));
// много различных асинхронных вызовов датасорсов которые логируются, например:
await userDataSource.FindAsync(id);
await tenantDataSource.FindAsync(id);
//
}
await Grant().ConfigureAwait(true);
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question