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

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

问题描述

解析服务器提供 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、注册这个认证委托

// 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.logInWithAuthType(inBackground: "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天全站免登陆