问题
This one seems a long shot. But I have seen several answers that indicate that HttpClient (and similar) should be used when cURL is needed in a .Net Core Application.
I have the following cURL command (that works perfectly):
curl -v -L --negotiate -u : -b ~/cookiejar.txt "https://idp.domain.net/oauth2/authorize?scope=openid&response_type=code&redirect_uri=https://localhost:5001&client_id=client_id_here"
The flow of this command goes like this:
- Loads the provided url (https://idp.domain.net/oauth2/authorize....)
- Gets a 302 response to redirect to https://idp.domain.net/iwa-kerberos?state=state_guid_here
- Because the
-Loption is there, it follows the redirect
- Because the
- The redirect responds with a 401 (Unauthorized) with a
www-authenticate:Negotiateheader. - cURL sees the
www-authenticate:Negotiateheader and gets a Kerberos token from the operating system (because of the--negotiateand-uoptions). - cURL calls the redirect url (https://idp.domain.net/iwa-kerberos?state=state_guid_here) with an additional header of
Authorization: Negotiate <kerberos token here>. - A response of 302 returned redirecting to https://idp.domain.net/commonauth?state=state_guid_here&iwaauth=1 with an added cookie
- Because of the
-boption, the cookie is picked up by cURL.
- Because of the
- cURL calls the redirect url (https://idp.domain.net/commonauth?state=state_guid_here&iwaauth=1) with the cookie returned in the 302 of the previous step.
- Another 302 redirect is returned. Redirecting to https://idp.domain.net/oauth2/authorize?sessionDataKey=session_key_guid_here with more cookies. (Again picked up because of the
-boption.) - The redirect to https://idp.domain.net/oauth2/authorize?sessionDataKey=session_key_guid_here is followed with the added cookies.
- Another 302 redirect is returned to https://localhost:5001/?code=code_guid_here&session_state=session_state_here (with an added cookie).
- cURL folows the redirect to https://localhost:5001/?code=code_guid_here&session_state=session_state_here with the added cookie.
- Contents of https://localhost:5001/?code=code_guid_here&session_state=session_state_here are returned to the cURL command line.
Writing this all out, it seems like a serious undertaking to get this to work in a .Net Application. But I figured I would ask in case it is built in to the framework somewhere.
Is there a .Net Core Framework class (or similar) that can allow me to reproduce this cURL command in C# code?
来源:https://stackoverflow.com/questions/60998324/replicate-curl-command-using-redirect-and-cookies-in-net-core-3-1