【问题标题】:Oauth with Box SDK (C# MVC .NET)Oauth 与 Box SDK (C# MVC .NET)
【发布时间】:2017-12-16 10:11:58
【问题描述】:

我目前正在尝试使用 Box SDK for .NET 为 MVC Web 应用程序构建登录。 不过,我终其一生都无法绕开 Oauth 登录过程。我觉得我已经接近了,但实际的 POST 操作让我感到困惑。

这是我试图遵循的过程: https://developers.box.com/oauth/ 我被困在“第一条腿”部分。

我传递我的 uri 和数据属性以按预期发布

var data = new List<KeyValuePair<string, string>>
        {
            new KeyValuePair<string, string>("response_type", "code"),
            new KeyValuePair<string, string>("client_id", client_id),
            new KeyValuePair<string, string>("box_login", account_email)
        };

        HttpResponseMessage values = await Post("https://app.box.com/api/oauth2/authorize", data);

使用自定义 Post() 方法包装器:

public static async Task<HttpResponseMessage> Post(string uri, List<KeyValuePair<string, string>> pairs)
    {
        using (HttpClient client = new HttpClient())
        {
            var content = new FormUrlEncodedContent(pairs);
            var response = await client.PostAsync(uri, content);
            return response;
        }

    }

但是“值”内容与 Box 授权页面的 html 一起返回。假设我应该重定向到这个页面......我真的不知道这样做的最佳方法(然后返回)。

我觉得这一切可能归结为我对 POST 工作原理的误解。我错过了什么明显而简单的事情?

【问题讨论】:

    标签: c# asp.net-mvc-4 oauth sdk box


    【解决方案1】:

    OAuth 表示外部身份验证。您必须将用户重定向到 Box OAuth 页面,而不是发送 Post 请求。您的应用程序中的重定向 URL 将决定将授权令牌发回的位置,然后您可以获取该授权代码并使用 Box .NET SDK 或使用自定义请求将其与访问和刷新令牌交换。

    OAuth 的第一阶段不是 SDK 的一部分。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2013-04-10
      • 1970-01-01
      • 2013-08-24
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-01-09
      相关资源
      最近更新 更多