4

I have a few middlewares before the OAuth Middleware and a few after it.

app.Use<Middleware1>
app.Use<Middleware2>
app.UseOAuthBearerTokens(OAuthOptions)
app.Use<Middleware3>
app.Use<Middleware4>
app.Use<Middleware5>

If I set something in the CallContext in Middleware1 or in Middleware2, it isn't available in Middleware3 or 4 or in any of the API controllers; whereas, if I set something in the CallContext in Middleware3 or 4, it's available in all the succeeding middlewares and the API controllers.

I guess UseOAuthBearerTokens is resetting or creating a new CallContext?? Has anyone encountered this?

I can get away from it by taking one of these approaches: 1. Use OwinContext instead of CallContext. Drawback - need to reference OWIN in all the projects that need the value set in the context. 2. In Middleware1, I can set the value in OwinContext, and in the middleware that follows the OAuth middleware, I can retrieve the value from OwinContext and reset it in CallContext

Let me know a proper solution for this.

Gokulnath
  • 1,166
  • 15
  • 29
  • I hit this too. I don't know the reason why but I've 2 workarounds. 1. Move the m/w(s) before `UseOAuthBearerTokens()`, if possible. 2. Move the required logic into an `XxxToCallContextMiddleware`, and put it before and after `UseOAuthBearerTokens()`. :shrug: – hIpPy Feb 23 '22 at 08:13

0 Answers0