获取c#中的授权码Box api

本文关键字:Box api 授权 获取 | 更新日期: 2023-09-27 18:19:00

我有一个问题,我想获得访问的代码框:

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)
            }

            );
        }

,但我不知道我可以得到"代码",没有进入网络http://127.0.0.1/?state=security_token%3DKnhMnlkjasdasnM0nHlZA&代码= RCaBKsE681239OPyYLLWwutg9Nwmmk

我如何用c#得到这个代码?

获取c#中的授权码Box api

这里有关于OAuth2流程的良好文档:https://box-content.readme.io/oauth 2

流程从导航浏览器/webview到身份验证页面开始——该页面应该以https://app.box.com/api/oauth2/authorize开头。我不确定你问题末尾的URL代表什么,但如果是重定向URL,一般不鼓励使用环回URL。

简而言之,您必须导航到具有适当参数的授权页面(例如:客户端id/secret,重定向url)一旦您成功登录,box将重定向您的webview到所提供的重定向url,其中的验证码将作为查询字符串参数提供。使用c#,这可能意味着你需要启动某种webview。

c# SDK中有一个WPF示例,它执行整个OAuth流程:https://github.com/box/box-windows-sdk-v2