【发布时间】:2016-09-12 07:22:18
【问题描述】:
Parse Server 提供 OAuth 身份验证。如何使用 Parse Server 的预定义 OAuth 模块,例如Facebook,注册新用户或登录 '_User' 类的现有用户?
Parse Server docs 给出了如何配置 OAuth 模块的示例。但是如何在 iOS 项目中使用它来登录或注册用户呢?
【问题讨论】:
标签: ios swift parse-platform parse-server
Parse Server 提供 OAuth 身份验证。如何使用 Parse Server 的预定义 OAuth 模块,例如Facebook,注册新用户或登录 '_User' 类的现有用户?
Parse Server docs 给出了如何配置 OAuth 模块的示例。但是如何在 iOS 项目中使用它来登录或注册用户呢?
【问题讨论】:
标签: ios swift parse-platform parse-server
1、创建一个继承自 NSObject 和 PFUserAuthenticationDelegate 的类。
class AuthDelegate:NSObject, PFUserAuthenticationDelegate {
func restoreAuthenticationWithAuthData(authData: [String : String]?) -> Bool {
return true
}
}
2、注册这个认证委托
// 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
// for google oauth, authData format will be
// ["id":"PUT_USER_ID_HERE","accesstoken":"PUT_TOKEN_HERE"]
PFUser.logInWithAuthType(inBackground: "google", authData:[.....])
4、你会看到_User中创建了一条记录,只有objectId和authData
【讨论】: