Man*_*uel 5 ios parse-platform swift parse-server
Parse Server提供OAuth身份验证.如何使用Parse Server的预定义OAuth模块(例如Facebook)注册新用户或登录"_User"类的现有用户?
Parse Server 文档提供了有关如何配置OAuth模块的示例.但是如何在iOS项目中使用它来登录或注册用户?
小智 7
1,创建一个从NSObject和PFUserAuthenticationDelegate扩展的类.
class AuthDelegate:NSObject, PFUserAuthenticationDelegate {
func restoreAuthenticationWithAuthData(authData: [String : String]?) -> Bool {
return true
}
}
Run Code Online (Sandbox Code Playgroud)
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")
Run Code Online (Sandbox Code Playgroud)
3,使用PFUser.logInWithAuthTypeInBackground方法将用户信息存储到_User
// for google oauth, authData format will be
// ["id":"PUT_USER_ID_HERE","accesstoken":"PUT_TOKEN_HERE"]
PFUser.logInWithAuthTypeInBackground("google", authData:[.....])
Run Code Online (Sandbox Code Playgroud)
4,您将看到在_User中创建的记录,只有objectId和authData
| 归档时间: |
|
| 查看次数: |
1172 次 |
| 最近记录: |