Dv_*_*_MH 6 twitter oauth twitter-oauth parse-platform xamarin
我使用了Xamarin.Auth 组件库中的OAuth1Authenticator类来允许用户通过Twitter登录.它正确验证并获得一个响应,其中包含以下内容:oauth_token,oauth_token_secret,user_id,screen_name,oauth_consumer_key,oauth_consumer_secret.
这是我的代码
OAuth1Authenticator twitterAuthenticator = new OAuth1Authenticator(Constants.Twitter.CONSUMER_KEY, Constants.Twitter.CONSUMER_SECRET, new Uri(Constants.Twitter.REQUEST_TOKEN_URL), new Uri(Constants.Twitter.AUTHORIZE_URL), new Uri(Constants.Twitter.ACCESS_TOKEN_URL), new Uri(Constants.Twitter.CALLBACK_URL));
twitterAuthenticator.Completed += async (sender, e) =>
{
if (!e.IsAuthenticated)
{
return;
}
string oauth_token = e.Account.Properties["oauth_token"].ToString();
Run Code Online (Sandbox Code Playgroud)
问题是我如何使用该响应来注册/签署解析用户?即我想通过Twitter令牌在解析数据库上创建一个ParseUser,并且会话应该得到处理,就像使用ParseFacebookUtils类在Facebook上签名一样
问题是Parse不支持在Xamarin中通过Twitter登录,但是,我相信parse确实支持任何类型的第三方认证,如下所示,但我不知道该怎么做.
这是最相对的链接
https://parse.com/tutorials/adding-third-party-authentication-to-your-web-app但此链接中的问题是它是作为网页按钮制作的,不知道如何在移动,它是GitHub不知道如何将它用于Twitter(Twitter只是OAuth1)
http://blog.parse.com/2013/12/03/bring-your-own-login/这正是我需要的,但它需要一个会话令牌,不能与twitter回复给我的oauth_tokens一起使用因此不知道如何使用链接中提到的方法
https://github.com/auth0/rules/blob/master/parse.md这看起来像解决方案,但是我不知道如何使用它,它确实显示了twitter图标所以它应该与twtiter一起使用但是如何我是否可以在.NET Update中使用它:我发现这个xamarin组件http://components.xamarin.com/view/Auth0Client让我更接近使用本段第一个链接中提到的方法,但是我我仍然输了,不知道如何将autho0与解析联系起来
总而言之,我迷失在迷宫中,真的希望有人能帮助我.
我没有 Twitter 帐户,所以我无法对此进行测试,但看起来您的 POST DTO 将是这样的:
public class TwitterAuthRequest
{
public AuthData authData { get; set; }
}
public class Twitter
{
public string id { get; set; }
public string screen_name { get; set; }
public string consumer_key { get; set; }
public string consumer_secret { get; set; }
public string auth_token { get; set; }
public string auth_token_secret { get; set; }
}
public class AuthData
{
public Twitter twitter { get; set; }
}
Run Code Online (Sandbox Code Playgroud)
响应 DTO 如下:
public class TwitterAuthResponse
{
public string username { get; set; }
public string createdAt { get; set; }
public string updatedAt { get; set; }
public string objectId { get; set; }
public string sessionToken { get; set; }
public AuthData authData { get; set; }
}
public class Twitter
{
public string id { get; set; }
public string screen_name { get; set; }
public string consumer_key { get; set; }
public string consumer_secret { get; set; }
public string auth_token { get; set; }
public string auth_token_secret { get; set; }
}
public class AuthData
{
public Twitter twitter { get; set; }
}
Run Code Online (Sandbox Code Playgroud)
不要忘记放入标题:
("X-Parse-Application-Id", ApplicationId)
("X-Parse-REST-API-Key", ApplicationKey)
Run Code Online (Sandbox Code Playgroud)
来源: https: //parse.com/docs/rest#users
编辑:
我已经创建了一份关于如何使用 DTO 的草案:
public static class TwitterLoginProvider
{
public static Task<ServiceResponse<TwitterAuthResponse>> Login(
Twitter twitterInfo,
string applicationId,
string apiKey,
IRestClient restClient)
{
var request = new TwitterAuthRequest ()
{
authData = new AuthData ()
{
twitter = twitterInfo
}
};
restClient.AddHeader ("X-Parse-Application-Id", applicationId);
restClient.AddHeader ("X-Parse-REST-API-Key", apiKey);
return restClient.PostAsync<TwitterAuthResponse>("https://api.parse.com/1/users", request, Format.Json);
}
}
Run Code Online (Sandbox Code Playgroud)
当您从 Xamarin.Auth 获得响应时,使用该信息创建 Twitter 对象并将其传递给 IRestClient。作为服务的响应,您将收到包含会话信息的响应。
IRestClient接口:https://github.com/sami1971/SimplyMobile/blob/master/Core/SimplyMobile.Web/IRestClient.cs
示例实现:https://github.com/sami1971/SimplyMobile/blob/master/Core/SimplyMobile.Web/RestClient.cs
或者,您可以使用 RestSharp: http: //restsharp.org/
| 归档时间: |
|
| 查看次数: |
2927 次 |
| 最近记录: |