How to swap authentication types #375
-
I'm writing a webapi service that enables a react frontend to authenticate users using cookies and session data. I would like to proxy requests to internal microservices swapping the authentication for bearer tokens. Can you provide a good sample for this? |
Beta Was this translation helpful? Give feedback.
Replies: 5 comments 7 replies
-
Honestly we haven't designed that flow yet, we're waiting for feedback on what people need. For your flow:
As JWTs are signed, you also have the question for how to share those signing keys with the destination server. |
Beta Was this translation helpful? Give feedback.
-
@Tratcher I was able to do just like the sample you linked me to, thanks so much!
|
Beta Was this translation helpful? Give feedback.
-
We've been using HTTP Headers to do Auth/Authz at the proxy and propagate identity downstream as HTTP headers. This implies there is implicit transport security between proxy and final destination provided by the infrastructure, but this is now increasingly common with SDN, K8S, and use of reverse proxies in sidecar scenarios. I believe this is also a model that is applied by Azure AppService (they auto inject HTTP module to reconstruct .NET Principal from authentication headers). Consider offering this out of the box as it greatly simplifies downstream services processing identity without having to deal with any security blocks. We've been using this to offload Kerberos validation to the sidecar. The identity is extracted and 2 headers are sent downstream:
Alternatively repackaging identity into JWT can provide greater flexibility as it allows for the much richer expression of principal than plaintext headers above. For this option, it would be useful to have the ability to send both signed and unsigned tokens. Unsigned JWT tokens would lessen the burden of dealing with managing JWK that proxy would need to expose and downstream having to configure. Signed JWT should also be supported by exposing a JWK url at the proxy. This is to facilitate scenarios where security between proxy and destination cannot be enforced at the transport infrastructure level. Also, some JWT libraries don't support unsigned JWT tokens. There's also the concept of identity delegation. Consider downstream service wanting to make further downstream calls on behalf of user. OAuth2 supports this via token-exchange where the original incoming token is exchanged to acquire extract claims that the downstream service is implicitly authorized for without requiring user consent. Kerberos also supports this by either delegating TGT of the user (unconstrained delegation) or via similarly constrained delegation which is very similar to oauth2. In all of these cases, there is a desire to propagate the original token/ticket downstream for further use. |
Beta Was this translation helpful? Give feedback.
-
If the architecture utilizes Backend for Frontend (BFF) then the change in code is minimal as compared to what @divinebovine already posted. Within the
Thanks to @divinebovine for their post. It got me on the right track to figure this out. |
Beta Was this translation helpful? Give feedback.
-
Hey everyone, #703 has been completed and should help with this scenario. Check out the updated docs it includes and try changes in the daily builds. |
Beta Was this translation helpful? Give feedback.
Honestly we haven't designed that flow yet, we're waiting for feedback on what people need.
For your flow:
Step 1) Have you been through the auth docs to enforce cookie auth for the incoming requests?
Step 2) You would probobly write a proxy middleware to:
HttpContext.AuthenticateAsync(scheme)
)As JWTs are signed, you also have the question for how to share those signing keys with the destination server.