How to authenticate a user in the Parse iOS SDK using OAuth?

Parse Server offers OAuth authentication. How can I use the predefined OAuth Parse Server modules, for example. Facebook to register a new user or log in to an existing user of class '_User'?

Parse Server docs provide examples of configuring OAuth modules. But how can I use it in an iOS project to log in or register a user?

+5
source share
1 answer

1, create a class that comes 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 the PFUser.logInWithAuthTypeInBackground method to store user information in _User

 // for google oauth, authData format will be // ["id":"PUT_USER_ID_HERE","accesstoken":"PUT_TOKEN_HERE"] PFUser.logInWithAuthTypeInBackground("google", authData:[.....]) 

4, you will see that the record is created in _User, only with the lens and authData p>

+6
source

All Articles