Replicate cURL Command Using Redirect and Cookies in .Net Core 3.1

回眸只為那壹抹淺笑 提交于 2020-04-18 05:37:02

问题


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:

  1. Loads the provided url (https://idp.domain.net/oauth2/authorize....)
  2. Gets a 302 response to redirect to https://idp.domain.net/iwa-kerberos?state=state_guid_here
    • Because the -L option is there, it follows the redirect
  3. The redirect responds with a 401 (Unauthorized) with a www-authenticate:Negotiate header.
  4. cURL sees the www-authenticate:Negotiate header and gets a Kerberos token from the operating system (because of the --negotiate and -u options).
  5. 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>.
  6. 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 -b option, the cookie is picked up by cURL.
  7. 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.
  8. 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 -b option.)
  9. The redirect to https://idp.domain.net/oauth2/authorize?sessionDataKey=session_key_guid_here is followed with the added cookies.
  10. Another 302 redirect is returned to https://localhost:5001/?code=code_guid_here&session_state=session_state_here (with an added cookie).
  11. cURL folows the redirect to https://localhost:5001/?code=code_guid_here&session_state=session_state_here with the added cookie.
  12. 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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!