如何使用OAuth在Parse iOS SDK中验证用户? [英] How to authenticate a user in Parse iOS SDK using OAuth?

查看:172
本文介绍了如何使用OAuth在Parse iOS SDK中验证用户?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Parse Server提供OAuth身份验证。如何使用Parse Server的预定义OAuth模块,例如Facebook,注册新用户或登录'_User'类的现有用户?

Parse Server offers OAuth authentication. How can I use the Parse Server's predefined OAuth modules, e.g. Facebook, to sign up a new user or login an existing user of the '_User' class?

解析服务器 docs 提供了有关如何配置OAuth模块的示例。但是如何在iOS项目中使用它来登录或注册用户呢?

The Parse Server docs give examples on how to configure the OAuth modules. But how do I use it in an iOS project to login or signup a user?

推荐答案

1,创建一个从两者扩展的类NSObject和PFUserAuthenticationDelegate。

1, create a class extends from both NSObject and PFUserAuthenticationDelegate.

class AuthDelegate:NSObject, PFUserAuthenticationDelegate {
    func restoreAuthenticationWithAuthData(authData: [String : String]?) -> Bool {
        return true
    }
}

2,注册此身份验证委托

2, register this authentication delegate

// parmeter 'forAuthType' is the name of file defined in 
// https://github.com/parse-community/parse-server/blob/master/src/Adapters/Auth/index.js
// such as: google, github, linkedin ......
PFUser.registerAuthenticationDelegate(AuthDelegate(), forAuthType: "google")

3,使用PFUser.logInWithAuthTypeInBackground方法将用户信息存储到_User

3, using PFUser.logInWithAuthTypeInBackground method to store user info to _User

// for google oauth, authData format will be
// ["id":"PUT_USER_ID_HERE","accesstoken":"PUT_TOKEN_HERE"]
PFUser.logInWithAuthTypeInBackground("google", authData:[.....])

4,你会看到在_User中创建了一条记录,只有objectId和authData

4, you will see a record is created in _User, with only objectId and authData

这篇关于如何使用OAuth在Parse iOS SDK中验证用户?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆