带有Box SDK的Oauth(C#MVC .NET)

问题描述 投票:1回答:1

我目前正在尝试使用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个回答
0
投票

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

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

© www.soinside.com 2019 - 2024. All rights reserved.