在c#

时间:2015-10-24 13:41:40

标签: c# box-api boxapiv2

我有一个问题,我想访问一个包含代码的方框:

using (var request1 = new HttpRequestMessage() { RequestUri = new Uri("https://www.box.com/api/oauth2/token"), Method = HttpMethod.Post })
        {
            HttpContent content = new FormUrlEncodedContent(new[] 
            { 
             new KeyValuePair<string, string>("grant_type", "authorization_code"), 
             //new KeyValuePair<string, string>("code", boxAccessCode),
             new KeyValuePair<string, string>("client_id", boxClientId),
             new KeyValuePair<string, string>("client_secret", boxClientSecret)

            }


            );
        }

但我不知道我可以获得&#34;代码&#34;,而不会进入网络 http://127.0.0.1/?state=security_token%3DKnhMñlkjasdasnM0nHlZA&code=RCaBKsE681239OPyYLLWwutg9Nwmmk

我如何通过c#获取此代码?

1 个答案:

答案 0 :(得分:1)

有关Box中OAuth2流程的详细文档: Live demo

流程首先将浏览器/ webview导航到身份验证页面 - 该页面应以https://box-content.readme.io/#oauth-2开头。我不确定你的问题末尾的URL代表什么,但如果它是重定向网址,通常不鼓励使用环回网址。

简而言之,一旦您成功登录,您必须使用适当的参数(例如客户端ID /密码,重定向URL)导航到授权页面,框会将您的webview重定向到提供的重定向URL,其中auth代码将是作为查询字符串参数提供。使用C#这可能意味着您需要启动某种类型的Web视图。

C#SDK中有一个WPF示例,用于执行整个OAuth流程: https://app.box.com/api/oauth2/authorize