首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >获取访问令牌和授权

获取访问令牌和授权
EN

Stack Overflow用户
提问于 2013-07-05 15:05:14
回答 2查看 6.9K关注 0票数 1

为此,我必须将文件上传到box.com,以便获得accesstoken和刷新令牌。我在c# asp.net中找不到任何代码,我想要使用c#和asp.net进行身份验证的代码,以及获取accesstoken和刷新令牌的代码。我尝试了下面的代码是错误的,因为页面再次过期请求。这是c# asp.net中的代码,我正在尝试使用Restsharp

代码语言:javascript
运行
复制
public void GetAccessToken(string code, string ClientId, string ClientSecret)
    {
        RestClient rs = new RestClient();
        string grant_type = "authorization_code";
        RestRequest request = new RestRequest(Method.POST);
        IRestRequest reuest = request;
        string strHeaders = null;
        RestResponse response = default(RestResponse);
        IRestResponse resp = response;
        string strResponse = null;

        try
        {
            rs.BaseUrl = "https://www.box.com/api/oauth2/token";
            request.Resource = "oauth2/token";
            strHeaders = string.Format("grant_type={0}&code={1}&client_id={2}&client_secret={3}", grant_type, code, clientId, Clientsecret);
            request.AddHeader("Authorization", strHeaders);
            resp = rs.Execute(reuest);
            strResponse = resp.Content;

            Label1.Text = strResponse;
        }
        catch (Exception ex)
        {
            throw ex;
        }
    }
EN

回答 2

Stack Overflow用户

发布于 2013-07-15 17:18:26

来自文档:https://developers.box.com/oauth/ (请参阅“获取访问令牌”)

当将auth代码交换为一组访问令牌和刷新令牌时,您需要向https://www.box.com/api/oauth2/token端点发出POST请求。

尝试将您正在添加的内容添加到标题的“授权”部分,并将其放入URL编码的POST正文中。

或者更好的是,尝试可用的.NET SDK,它将为您处理OAuth工作流的这一部分:https://github.com/box/box-windows-sdk-v2

票数 1
EN

Stack Overflow用户

发布于 2013-08-21 21:46:58

您还需要将编码设置为:

代码语言:javascript
运行
复制
request.RequestFormat = DataFormat.Xml;
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/17491941

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档