iOS社交API能否用于通过Facebook或Twitter验证人们(让人们登录您的应用程序)?

3

澄清 如果您想仅使用iOS提供的社交API(账户框架),您可以让用户使用其Facebook或Twitter帐户登录您的应用吗?
如果可以,那么除了用户ID(或名称、Twitter名称、Facebook名称)之外,您还需要使用什么来确保(在服务器端)他们就是他们自己。

更详细的解释 我很难理解本地iOS(或Android)应用程序中第三方注册和登录集成的工作流程/逻辑, 因此,在iOS中,有一个中央存储库来保存用户的Twitter(或Facebook)凭据,应用程序可以调用API获取用户的Twitter ID,到目前为止都很好, 但是,如果我想与后端服务器通信并证明用户是他们所声称的人,仅拥有用户ID是不够的, 我错过了什么吗?

我的问题是 如果用户没有向您提供凭据,您如何验证用户的身份与您的后端服务器进行身份验证?


也许可以使用Oauth(2)?! - Till
iOS提供oAuth API吗?还是你的意思是说你不能使用iOS提供的API来验证用户,需要使用oAuth? - Ali
1个回答

0

您可以使用ACAccountStore进行身份验证。感谢http://blogs.captechconsulting.com/blog/eric-stroh/ios-6-tutorial-integrating-facebook-your-applications提供下面大部分代码。

self.accountStore = [[ACAccountStore alloc]init];
ACAccountType *FBaccountType= [self.accountStore accountTypeWithAccountTypeIdentifier:ACAccountTypeIdentifierFacebook];
NSString *key = @"987654"; //put your own key from FB here
NSDictionary *dictFB = //use the ACAccountStore ACFacebookPermissionsKey to help create your dictionary of permsission you'd like to request, such as the users email, writing on the wall, etc.
[self.accountStore requestAccessToAccountsWithType:FBaccountType options:dictFB completion: ^(BOOL granted, NSError *e) {
    if (granted) {
        NSArray *accounts = [self.accountStore accountsWithAccountType:FBaccountType];
        //it will always be the last object with SSO
        self.facebookAccount = [accounts lastObject];
    } else {
        //Fail gracefully...
        NSLog(@"error getting permission %@",e);
    } 
}];

此时,您可以访问帐户存储中的oauth令牌,并将其发送到您的服务器,以进行与Facebook的任何服务器端交互。


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接