【问题标题】:Dropbox - Migrating oauth1 to oauth2 using token_from_oauth1Dropbox - 使用 token_from_oauth1 将 oauth1 迁移到 oauth2
【发布时间】:2016-08-05 02:54:22
【问题描述】:

我通过 Sharpbox 工具包使用 Dropbox 已经有一段时间了。它基于 oAuth1,因此我有一个为我的用户提供的充满 oAuth1 访问令牌的数据库。

我想转换为基于 oAuth2 的新 Dropbox API。我看到 Dropbox 的 v1 规范中有一个“token_from_oauth1”端点(参考 here),但我不知道如何成功连接到该端点以升级用户的现有令牌。 (我使用的是 C#/.NET)。

谁能给我一些示例代码,展示如何创建一个经过适当身份验证的调用来执行此操作?我认为问题在于尝试正确验证/签署请求。 (我现有的所有 Dropbox 调用都是由 Sharpbox 库完成的,所以我看不到它是如何进行身份验证的)。

谢谢!

【问题讨论】:

标签: c# oauth dropbox


【解决方案1】:

您可以使用简单的休息客户端(如 RestSharp)并像这样调用

我目前在 xamarin 应用程序中执行此操作,我使用 xamarin dropbox 核心 api 登录,并获取 oauth_token、oauth_consumer_key 和 oauth_signature。如果您使用 c# 管理 oauth1 流程,那么很容易获得 oauth2 令牌。

            var rclient = new RestSharp.RestClient("https://api.dropboxapi.com/1/");
            var rrequest = new RestSharp.RestRequest("oauth2/token_from_oauth1", Method.POST);
            rrequest.AddHeader("Authorization", "OAuth oauth_version=\"1.0\", oauth_signature_method=\"PLAINTEXT\"");

            rrequest.AddParameter("oauth_consumer_key", store.GetConsumerKey());
            rrequest.AddParameter("oauth_token", store.GetAccessToken());
            rrequest.AddParameter("oauth_signature", String.Concat(App.DropboxAppSecret, "&", store.GetAccessTokenSecret()));

            var rresponse = rclient.Execute(rrequest);
            string content = rresponse.Content;

【讨论】:

    【解决方案2】:

    有一个用于 Twitter oAuth 1.0 的库(请参阅http://www.voiceoftech.com/swhitley/?p=681),实际上可以轻松地进行 oAuth 1.0 身份验证调用。所以下面的代码对我来说似乎工作得很好:

    oAuthTwitter oat = new oAuthTwitter();
    oat.Token = <oauth 1.0 token>;
    oat.TokenSecret = <oauth 1.0 secret>;
    oat.ConsumerKey = <application key>;
    oat.ConsumerSecret = <application secret>;
    string resultJSON = oat.oAuthWebRequest(oAuthTwitter.Method.POST, "https://api.dropboxapi.com/1/oauth2/token_from_oauth1", null);
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2014-04-25
      • 1970-01-01
      • 2014-01-26
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-12-29
      相关资源
      最近更新 更多