【问题标题】:How can I retrieve Oauth2 authorization code如何检索 Oauth2 授权码
【发布时间】:2021-06-16 23:24:37
【问题描述】:

我正在以编程方式尝试检索发布此 URL 时返回的授权代码。

https://login.microsoftonline.com/common/oauth2/v2.0/authorize?client_id=<client_id>&response_type=code&redirect_uri=https://xyzzy.portal.azure-api.net/docs/services/oauth-server-1/console/oauth2/authorizationcode/callback&response_mode=query&scope=api://qwerty/API.Read&state=12345

当我在邮递员中测试这个时,我有两个步骤。生成那个 URL 的那个,然后我在浏览器中发布一个帖子,我在 URL 地址中得到一个 response_type=somelongcodehere。 在 C# 中,我认为我可以做一些简单的事情

            var c2 = new RestClient(ResponseUri); //where ResponseUri is the URL address
            c2.Timeout = -1;
            var r2 = new RestRequest(Method.POST);
            IRestResponse v2 = c2.Execute(r2);

并且在响应中的某处我应该能够看到“代码”,然后能够继续。

我知道这不应该这么困难,而且我错过了一些非常明显的东西。 任何帮助将不胜感激。

谢谢,

【问题讨论】:

    标签: c# .net oauth-2.0


    【解决方案1】:

    您需要使用 HttpListener 类并等待响应。然后你得到完整的 url 并解析它。

    【讨论】:

      猜你喜欢
      • 2021-04-24
      • 2013-09-30
      • 2018-11-04
      • 2018-05-26
      • 1970-01-01
      • 2015-12-30
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多