如何从.NET中经过身份验证的Twitter oauth_令牌注册/登录解析用户?
我使用了来自的类来允许用户通过Twitter登录。它正确地进行身份验证并得到一个响应,该响应具有以下内容:oauth_令牌、oauth_令牌、用户id、屏幕名称、oauth_消费者密钥、oauth_消费者密钥 这是我的密码如何从.NET中经过身份验证的Twitter oauth_令牌注册/登录解析用户?,twitter,oauth,xamarin,twitter-oauth,parse-platform,Twitter,Oauth,Xamarin,Twitter Oauth,Parse Platform,我使用了来自的类来允许用户通过Twitter登录。它正确地进行身份验证并得到一个响应,该响应具有以下内容:oauth_令牌、oauth_令牌、用户id、屏幕名称、oauth_消费者密钥、oauth_消费者密钥 这是我的密码 OAuth1Authenticator twitterAuthenticator = new OAuth1Authenticator(Constants.Twitter.CONSUMER_KEY, Constants.Twitter.CONSUMER_SECRET, new
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();
问题是如何使用该响应注册/登录解析用户?i、 e.我希望通过Twitter令牌在parse数据库上创建一个ParseUser,会话应该得到处理,处理方式与它的工作方式相同
问题是Parse不支持在Xamarin中通过Twitter登录,但是,我相信Parse确实支持任何类型的第三方身份验证,如下所示,但我不知道如何做到这一点
以下是最相关的链接
但是这个链接的问题是,它是作为一个网页按钮制作的,不知道如何在手机上使用它,而且它是为GitHub设计的,不知道如何在Twitter上使用它(Twitter只是OAuth1)
这正是我所需要的,但它需要一个会话令牌,与twitter回复给我的oauth_令牌不兼容,因此不知道如何使用链接中提到的方法
这看起来像是解决方案,但我不知道如何使用它,它确实显示了twitter图标,因此它应该与twitter一起使用,但我如何使其在.NET更新中工作:我发现了这个xamarin组件,它使我更接近于使用本段第一个链接中提到的方法,但我仍然迷路了,不知道如何将autho0链接到解析
总而言之,我在这个迷宫中迷失了方向,真希望有人能帮助我。我没有Twitter帐户,所以我无法测试这一点,但看起来你的帖子应该是这样的:
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; }
}
响应如下:
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; }
}
别忘了在标题中加上:
("X-Parse-Application-Id", ApplicationId)
("X-Parse-REST-API-Key", ApplicationKey)
资料来源:
编辑:
我已经为您如何使用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);
}
}
公共静态类TwitterLoginProvider
{
公共静态任务登录(
推特推特信息,
字符串applicationId,
字符串apiKey,
IRestClient(restClient)
{
var request=new TwitterAuthRequest()
{
authData=新的authData()
{
twitter=twitterInfo
}
};
restClient.AddHeader(“X-Parse-Application-Id”,applicationId);
restClient.AddHeader(“X-Parse-REST-API-Key”,apiKey);
返回restClient.PostAsync(“https://api.parse.com/1/users,请求,格式为.Json);
}
}
当您从Xamarin.Auth获得响应时,使用该信息创建一个Twitter对象并将其传递给IRestClient。作为来自服务的响应,您将得到一个带有会话信息的响应
IRestClient接口:
示例实现:
或者,您可以使用RestSharp:如果有人需要任何澄清,请告诉我,我使用的是Parse.NET库而不是Parse REST API,我如何在c#中使用REST API?您的回答没有回答我的问题。我已经在C#中使用Xamarin.Auth库实现了这一点,我想要的是如何使用我得到的响应来注册/登录一个解析用户您将获得响应,然后使用响应中的“sessionToken”添加到您的请求中。对于RESTAPI,您可以使用自己的web客户端,或者使用类似RestSharp的东西。谢谢您的宝贵意见。关于使用Auth1类从Twitter得到的响应,我只得到以下oauth_令牌、oauth_令牌、用户id、屏幕名称、oauth_消费者密钥、oauth_消费者密钥。我从哪里得到sessionToken?我可以使用Xamarin.Auth类获得它吗?如果没有,那么我如何使用RESTAPI获得它呢?您可以使用Xamarin信息创建请求DTO,作为web调用的响应,您将获得响应DTO。见我的编辑上面。如果我有Twitter账号,我可以测试一个完整的实现,但我希望上面的内容能让你达到目的。在任何情况下,这都是一个更好地熟悉RESTAPI的好机会。