How to access "first_name" permission with Facebook SDK 4+ and Parse - ios

How do I access the read permissions within the PFFacebookUtils login method? I've upgraded to Parse 1.7.3 and am using the ParseFacebookUtilsV4 framework as well. I updated the method to loginInBackgroundWithReadPermissions() and below I have the following code:
// Login through Facebook IBAction
PFFacebookUtils.logInInBackgroundWithReadPermissions(permissions, (appUser: PFUser?, error: NSError?) -> Void in
if let appUser = appUser {
let request = FBRequest.requestForMe()
request.startWithCompletionHandler { (request, user, error) -> Void in
if error == nil {
// Get Facebook user's "first_name" and set it to the newly created PFUser's "name" variable
var name = user.objectForKey("first_name") as! String
appUser["name"] = name
appUser.saveInBackgroundWithBlock({ (Bool, error: NSError!) -> Void in
})
}
}
})
I'm getting a compile-time error on FBRequest.requestForMe() saying
Use of unresolved identifier 'FBRequest'
What should I be replacing this with so that I can access the "first_name" property of the Facebook user and set it to the Parse user's "name" property I have set up?

Have you imported the Facebook SDK in your project? When you use the Parse utils, you still need to import/link it.
Also; what version of the SDK are you using? The FBRequest class is part of the 3.x series; I would advise to use the latest SDK which is in the 4.x version numbers now. Please make sure that the Parse Framework version you use matches the iOS framework used.

Instead of using FBRequest, you now use the FBSDKGraphRequest. To sure to import FBSDKCoreKit. See Parse's tutorial on github for an example request.
https://github.com/ParsePlatform/ParseUI-iOS/wiki/Integrate-Login-with-Facebook

Related

Get user attributes AWS Amplify iOS SDK

I'm building an iOS app with the SDK Amplify so I have my users registered on AWS.
I already have my sign in/sign up flow working but the problem is that with the newest version of the SDK I have absolutely no idea of how can I get attributes of a registered user like his family name, email address etc...
With this new SDK everything seems to work around the AWSMobileClientclass but I see nothing from this class that can help me to get what I want.
The official documentation is anemic and doesn't cover or even point to my use case.
If somebody can give me some hint or even some good ressources I'll be very thankful!
Hi YoanGJ and future guests,
Based on your comment you were looking for some sample code.
AWSMobileClient.sharedInstance().getUserAttributes { (attributes, error) in
if let attributes = attributes {
XCTAssertTrue(attributes.count == 3, "Expected 3 attributes for user.")
XCTAssertTrue(attributes["email_verified"] == "false", "Email should not be verified.")
}else if let error = error {
XCTFail("Received un-expected error: \(error.localizedDescription)")
}
getAttrExpectation.fulfill()
}
This excerpt shows how you could call getUserAttributes and it comes from the integration tests found here.
The method was missing from the initial release and has since been added. You can use the getUserAttributes with the following API in the latest SDK version 2.8.x:
public func getUserAttributes(completionHandler: #escaping (([String: String]?, Error?) -> Void))
You can find the source code here:
https://github.com/aws-amplify/aws-sdk-ios/blob/master/AWSAuthSDK/Sources/AWSMobileClient/AWSMobileClientExtensions.swift#L532
Thanks,
Rohan
For a note:
Make sure you did configure attribute read and write permission accordingly in your Cognito user pool App client to access your user attributes using getUserAttributes.
To configure attributes read and write permissions in user pool,
User pool -> General settings -> App clients -> Choose your app client
-> Show details -> Set attribute read and write permissions
Thanks!

Unable to access user details userName , imageURL after login using AWS SDK iOS version 2.6.1

I am trying to access the user name and user Image url after login using AWS SDK iOS but i am getting following error :
Value of type 'AWSIdentityManager' has no member 'identityProfile'
Although the same code was working fine in previous SDK(2.5.10),
please help me in getting the user details after login.
My current SDK version is 2.6.1
Here is my code :-
if let identityUserName = identityManager.identityProfile?.userName {
print("User ID\( identityManager.identityId!)")
print("User name\(identityUserName)")
}
if let imageURL = identityManager.identityProfile?.imageURL {
print(imageURL)
}
I have managed to access the user Name by using following code if i login with custom login , but if i try to login with Facebook or Gmail i get nil in response.
Code :-
let currUserPool = AWSCognitoIdentityUserPool.default()
let currUser = currUserPool.currentUser()
let username = currUser?.username
The Sample Application downloaded from AWS Mobile Hub had the IdentityProfile which helps you retrieve the username and imageURL. On 08/31, the IdentityProfile was removed from the Sample Application and the AWSIdentityManager was moved to an SDK library available as
pod 'AWSAuthCore', '~> 2.6' if you are using cocoapods.
For UserPools:
For retrieving the username from UserPoolsSignIn, you can do the following:
Add this import:
import AWSUserPoolsSignIn
AWSCognitoUserPoolsSignInProvider.sharedInstance().getUserPool().currentUser()?.username
For Facebook:
How to get user name and email id for Facebook SDK?
For Google:
https://developers.google.com/identity/sign-in/ios/people

Swift3 iOS -Firebase FIREmailPasswordAuthProvider Not Working

I just upgraded my Firebase Cocoapods from 3.15.0 to 4.0.4 and FirebaseAuth Cocoapods from 3.1.1 to 4.0.0.
I'm using email & password to authenticate users. When a user changes their email I was using this method below and everything was working fine:
FIREmailPasswordAuthProviderID.credential(withEmail: emailTextField.text!, password: passwordTextField.text!)
Now that I updated I get the error message
Value of type 'String' has no member 'credential'
I looked on the docs and it said to use the method below:
The problem is I get the same exact error:
FIREmailAuthProviderID.credential(withEmail: emailTextField.text!, password: passwordTextField.text!)
Value of type 'String' has no member 'credential'
My original code below
import Firebase
import FirebaseAuth
let user: User?
let credential = FIREmailPasswordAuthProviderID.credential(withEmail: emailTextField.text!, password: passwordTextField.text!)
if let user = user{
user.reauthenticate(with: credential, completion: {
(error) in
if error != nil{
//...do something
return
}
//...do something else
})
}
What am I doing wrong?
Hold up
FIREmailAuthProviderID is a constant that contains the auth providers id and is a string (which is EmailAuthProviderID in FB 4). There is no credential function which is why you are getting that error.
Here's a link to the Firebase 4 Migration Guide
The new format (and the correct function call) is
EmailAuthProvider.credential(withEmail email: String, password:
String) -> AuthCredential
20171014 Edit: updated link to latest migration guide.
I haven't used this feature of fireBase however it appears that this link may be helpful
https://firebase.google.com/docs/reference/ios/firebaseauth/api/reference/Classes/FIREmailAuthProvider
I think you needs use EmailAuthProviderID instead of FIREmailAuthProviderID. In the Firebase 4.0 no longer uses the FIR suffix.
Hope it help you :)

Parse Error Code 206: Cannot modify user (Parse Server)

I have migrated my iOS app (using Swift) to Parse Server and have integrated Facebook sign-up.
When a new user is created via the Facebook login, a new Session object is not created. Therefore, it does not allow the user to change their profile picture, etc. (when the user tried to update their user info, the error following is error is given:
*[Error]: cannot modify user ********** (Code: 206, Version: 1.14.2)*
Only after the Facebook user logs out and then logs back in again, the Session object is created.
How can I have it so that a Session object is created upon sign up for a new Facebook user so that they may update their user information, just like one is created via the regular standard parse login method?
Here's my code for the Facebook sign up. Note: I use the following method, update the newly created user, and then save the user:
PFFacebookUtils.logInInBackgroundWithReadPermissions(permissions) {
(user: PFUser?, error: NSError?) -> Void in
...
user.email = someEmail
user.username = someUsername
user["profilePicture"] = someFile
...
user.saveInBackgroundWithBlock({
(succeeded: Bool, error: NSError?) -> Void in
...
}
I even tried adding/removing the PFUser.enableRevocableSessionInBackground line of code in my AppDelegate.swift but nothing changed:
// *** Initialize Parse. ***
let config = ParseClientConfiguration(block: {
(ParseMutableClientConfiguration) -> Void in
ParseMutableClientConfiguration.applicationId = appKey;
ParseMutableClientConfiguration.clientKey = clientKey;
ParseMutableClientConfiguration.server = serverURL;
});
Parse.initializeWithConfiguration(config);
PFFacebookUtils.initializeFacebookWithApplicationLaunchOptions(launchOptions)
PFUser.enableRevocableSessionInBackground()
UPDATE: Updated my Parse Server from v2.2.11 TO v2.2.22 and it seems to have fixed this issue...

Error adding Firebase users Swift

By following the information on this link, I am currently working on trying to create a user using Firebase, as shown in the code below. However, it appears no user is created when the app is run. Any input is greatly appreciated. The Firebase URL was taken from my test database.
let ref = Firebase(url: "https://test-96df2.firebaseio.com")
ref.createUser("bobtony#example.com", password: "correcthorsebatterystaple",
withValueCompletionBlock: { error, result in
if error != nil {
// There was an error creating the account
print("error creating account")
} else {
let uid = result["uid"] as? String
print("Successfully created user account with uid: \(uid)")
}
})
Edit:
The propagated error is:
Error Code: AUTHENTICATION_DISABLED) Projects created at
console.firebase.google.com must use the new Firebase Authentication
SDKs available from firebase.google.com/docs/auth/
However, as shown below, the email/password authentication is enabled in the Firebase console.
You have already authorized the email registration as I can see in your screenshot. So the problem doesnt realies on AUTHENTICATION_DISABLED.
From your error message and the snippet code I can see that you have created a new project but you are trying to use the legacy firebase SDK and so you will have compatibility issues. Also, you are looking into the old firebase documentation.
First of all you will need to make sure you have configured your project as documented in new firebase start guide.
After, you can take a look at the documentation for creating a new user with the new sdk. You can find the 3.x create user call bellow.
FIRAuth.auth()?.createUserWithEmail(email, password: password) { (user, error) in
// ...
}

Resources