6

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?

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 Answer 1

9

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

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

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, 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, you will see a record is created in _User, with only objectId and authData

Sign up to request clarification or add additional context in comments.

5 Comments

I couldn't find any useful information regarding third party login with parse. I wonder whether i can integrate with Spotify login as well?
@KesongXie you can see the supported providers here github.com/parse-community/parse-server/tree/master/src/…
How could I get a callback for when the logInWithAuthType function finishes? I read here that it returns "A BFTask that is resolved to @YES if linking succeeds." But what does that mean? How can I use that?
Nvm, I found an example here
@Jacolack If you are still looking for then check this this sample code that shows how it is handled. github.com/back4app/SignInWithApple/blob/master/Swift/app/…

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.