【问题标题】:How to authenticate a user in Parse iOS SDK using OAuth?如何使用 OAuth 在 Parse iOS SDK 中对用户进行身份验证?
【发布时间】: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


    【解决方案1】:

    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

    【讨论】:

    • 我找不到任何有关使用解析的第三方登录的有用信息。我想知道我是否也可以与 Spotify 登录集成?
    • @KesongXie 你可以在这里看到支持的提供者github.com/parse-community/parse-server/tree/master/src/…
    • 如何在 logInWithAuthType 函数完成时获得回调?我读到here 它返回“如果链接成功,则解析为@YES 的BFTask。”但是,这是什么意思?我该如何使用它?
    • Nvm,我找到了一个例子here
    • @Jacolack 如果您仍在寻找,请查看此示例代码,该示例代码显示了它是如何处理的。 github.com/back4app/SignInWithApple/blob/master/Swift/app/…
    猜你喜欢
    • 1970-01-01
    • 2016-03-28
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-02-04
    • 1970-01-01
    • 2015-08-30
    • 1970-01-01
    相关资源
    最近更新 更多