Dropbox - 使用 token_from_oauth1 将 oauth1 迁移到 oauth2
Dropbox - Migrating oauth1 to oauth2 using token_from_oauth1
我通过 Sharpbox 工具包使用 Dropbox 已有一段时间了。它基于 oAuth1,所以我有一个数据库,里面装满了我的用户的 oAuth1 访问令牌。
我想转换到基于 oAuth2 的新 Dropbox API。我看到 Dropbox 的 v1 规范中有一个 "token_from_oauth1" 端点(参考 here),但我不知道如何成功连接到该端点以升级用户的现有令牌。 (我正在使用 C#/.NET)。
任何人都可以指出一些示例代码来说明如何创建经过正确身份验证的调用来执行此操作吗?我认为问题在于尝试正确 authenticate/sign 请求。 (我现有的所有保管箱调用都是由 Sharpbox 库完成的,所以我看不到它是如何进行身份验证的)。
谢谢!
有一个用于 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);
您可以使用一个简单的休息客户端(如 RestSharp)并像这样进行调用来获得它
我目前正在 xamarin 应用程序中执行此操作,我使用 xamarin 保管箱核心 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;
我通过 Sharpbox 工具包使用 Dropbox 已有一段时间了。它基于 oAuth1,所以我有一个数据库,里面装满了我的用户的 oAuth1 访问令牌。
我想转换到基于 oAuth2 的新 Dropbox API。我看到 Dropbox 的 v1 规范中有一个 "token_from_oauth1" 端点(参考 here),但我不知道如何成功连接到该端点以升级用户的现有令牌。 (我正在使用 C#/.NET)。
任何人都可以指出一些示例代码来说明如何创建经过正确身份验证的调用来执行此操作吗?我认为问题在于尝试正确 authenticate/sign 请求。 (我现有的所有保管箱调用都是由 Sharpbox 库完成的,所以我看不到它是如何进行身份验证的)。
谢谢!
有一个用于 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);
您可以使用一个简单的休息客户端(如 RestSharp)并像这样进行调用来获得它
我目前正在 xamarin 应用程序中执行此操作,我使用 xamarin 保管箱核心 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;