Parse Log in With Twitter Initial Failure - ios

Currently I have a Twitter login that authenticates the user just fine, receiving all the appropriate information for the user necessary for confirming a complete login.
I then am calling the [PFTwitterUtils logInWithBlock:...] method in order to authenticate the user through Parse and populate a new user in _User.
(I am not using just this method to present the Twitter login dialog box as I could not get it to present itself).
Here is the strange part:
On the first time I launch the app, I sign in with Twitter, and then call the logInWithBlock method and receive the following error:
Something went wrong: The operation couldn’t be completed. (NSURLErrorDomain error -1012.)
The strange part is that this issue does not occur at all if I relaunch the app again. The only difference is that upon relaunch I believe the Twitter Account information that I had used before (via browser not accounts) is saved on the device. When I launch the app again, I have it set so that it reloads the previous session: this time the [PFTwitterUtils logInWithBlock:...] works like a charm, creates a new user, etc., without any issue.
NOTE: I have a valid URL saved as the Callback URL on my Twitter App's settings. Also, I hope it is clear that the setup was done correctly given that it works fine on second log in.
Here is the login code I am using:
// Login with Twitter through Parse
[PFTwitterUtils logInWithBlock:^(PFUser *user, NSError *error) {
if (error != nil) {
// Something went wrong
NSLog(#"Something went wrong: %#", [error localizedDescription]);
breakLogin = YES;
[self invalidateSignInTimer];
return;
}
else if (user.isNew){
userObjectID = user.objectId;
[user saveInBackground];
NSLog(#"New User");
}
else if (!user.isNew) {
userObjectID = user.objectId;
[user saveInBackground];
NSLog(#"Returning User. Welcome Back!");
}
}];
I am running out of patience and ideas on why this is happening. If anyone has any ideas please let me know - thanks!
UPDATE:
I noticed that the reason this seems to be happening is such:
The first time i attempt to login there is no PFUser, whereas the second time there seems to be a saved [PFUser currentUser], which allows the [PFTwitterUtils...] method to log in and create the new user.
Yet I am still not sure how to prevent the failure the first time without manually creating a new PFUser and then logging in with Twitter, then PFTwitterUtils...
UPDATE 2
I have resolved this issue with the answer I have provided below. I am leaving this up as I feel this is something that may help others out there in the future.

So after extraneous research, I seemed to have found a solution.
First I made sure that all of my framework files (SKDs, headers, etc) were up to date by removing all of their references from both the project and the library linking.
Second I made sure that all keys and secrets were remade and updated in my
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
Lastly I made double checked that I properly went through the set up for Twitter authentication through Parse's website.
BUT what I found to be the only solution rested in the Callback URL.
When specifying the Callback URL in your Twitter Application under "Settings", I had to uncheck the Lock Callback URL option, despite the recommendation by Twitter. (seen below)
I was a little unhappy that all of this trouble derived from something so mundane, however I was at least pleased that solution was in fact resolved without too much trouble. Hopefully this answer helps someone out there struggling with a similar issue.

Related

Firebase Auth iOS user Anonymously create but not showing in console

Suddenly this behaviour started to happen without changing anything. Basically, I'm able to create users Anonymously or even with Email/Password. I get no error whatsoever, actually I'm able to retrieve the userID. However, when I go to the users list in the console, its always empty.
Auth.auth().signInAnonymously() { user, error in
self.ifNoError(error) {
print("Signed In Anonymously \(user?.user.uid)")
}
}
Results:
Signed In Anonymously Optional("qQazZ3MX8LfQdnlz8F27QDxAT9U2")
Thank you in advance
Did you at any point delete anonymous users from the Firebase console before going live or something like that? That's what I did, not realizing that firebase keeps that user alive on your device...even if you delete the app from the device and re-install. Moreover, it will still work as an accepted anonymous user (even though deleted from the console) UNTIL you force a sign out on a given device. (Oops. TL;DR). Try this.
Sign out the user in your app delegate
FIRAuth *auth = [FIRAuth auth];
NSError *error;
[auth signOut:&error];
Create another anonymous user
[auth signInAnonymouslyWithCompletion:^(FIRAuthDataResult * _Nullable authResult, NSError * _Nullable error) {
NSLog(#"Error is %#", error);
NSLog(#"Auth result user id is %#", authResult.user.uid);
}];
In my case, my device now showed a new user UUID and that user shows up in the Firebase console.
Fun fact: This issue doesn't seem arise with Android. My Android app, which shares the same production firestore, happily created a new user after I deleted the app from the device and reinstalled.
I managed to solve the issue by creating a manual user email/password (manually on the console), sign in with it through code, delete it thorough code. Then change the code to sign in again Anonymously. This solved the problem!!

How do you log out of Firebase? (Objective-C)

I'm trying to log out users from my app. In the Firebase API, it says to use [ref unauth];
What exactly is the ref that I'm supposed to unauthorize? Is it a Firebase reference or the user's uid? I've used a Firebase reference, and it doesn't seem to do anything. How do I use this command? What exactly is it supposed to do? I haven't come across a good example.
NSError *signOutError;
BOOL status = [[FIRAuth auth] signOut:&signOutError];
if (!status) {
NSLog(#"Error signing out: %#", signOutError);
return;
}else{
NSLog(#"Successfully Signout");
}
Implement this code you must enjoy that it works for sign out.
The Firebase client manages the connection to its servers behind the scenes and authenticates on that connection instead of per Firebase object. This means that whenever you call for example ref authUser:#"jenny#example.com" password:#"correcthorsebatterystaple" on any Firebase reference, the user is authenticated on all references.
Similarly: when you call unauth on any Firebase reference, the user will be signed out of all references in your app.

Google SignIn fails when serverClientID specified

I've got a server that interacts with Google Calendar on behalf of user. To do this it should obtain one-time access token from iOS application. I've referred to documentation, but have some issues with sign in.
I have started from "SignIn" example app (pod test Google > Sign In), provided it with my credentials (GoogleServices-Info.plist, bundleId). Then I signed it with my provision and started on iPhone 6, everything works like a charm.
Then I have added
[GIDSignIn sharedInstance].serverClientID = #"<my-server-client-id>";
in ViewController:viewDidLoad. I have unauthorised in app, launched it again. It opened auth screen (youtube.app, 10.31.11670) again, I selected the same account, but this time it launched my app without displaying permissions screen, -signIn:didSignInForUser:withError: method was called, but GIDGoogleUser was nil. Error stated
Error Domain=com.google.GIDSignIn Code=-1 "A potentially recoverable error occured. You may try again." UserInfo=0x17026af80 {NSLocalizedDescription=A potentially recoverable error occured. You may try again.}
I have tried several times, but each time I have received the same result. But if I comment ...serverClientID... it begins to work again.
Then I have launched this app in simulator and it authorised successfully using WebView and I received user.serverAuthCode.
I decided that problem was in YouTube.app, I uninstalled it from device, but the same problem happened with other Google applications.
Could you point me what is wrong with my singIn implementation?
PS
Finally I decided to use workaround and rewrote -canOpenUrl: in UIApplication subclass this way:
- (BOOL)canOpenURL:(NSURL *)url
{
if ([[url scheme] hasPrefix:#"com-google-gidconsent"] || [[url scheme] hasPrefix:#"com.google.gppconsent"]) {
return NO;
}
return [super canOpenURL:url];
}
And now it uses WebView authorisation and I can receive my one-time token. But this approach is crappy of course.

iOS app expected behavior after the user removes the previously added authorization from the Facebook app?

I'm successfully posting to Facebook from our Unity iOS game by initializing at game launch then posting message by first checking the session validity and triggering the login if needed.
At first call, I authorize the game from the Facebook app.
Trying to start the process again, I go to the Facebook app prefs and delete the app authorization.
Now when I try to post again from the game, the post message completion handler has no errors but the post does not appear on the user's wall.
What is the process to correct this? Is there a way to check that the game is authorized before posting, and ask for a new authorization if it's not?
Or is the user decision final and they need to reinstall the app to reset everything?
Even though I'm using Prime31's Facebook plugin for Unity, I'm interested in an iOS SDK answer to this question.
Thank you!
You will get an exception, that you need to handle.
- (void)request:(FBRequest *)request didFailWithError:(NSError *)error{
NSLog(#"didFailWithError : %#",[error description]);
NSDictionary* userinfo=[error userInfo];
NSString *type=[[userinfo valueForKey:#"error"]valueForKey:#"type"];
if([type isEqualToString:#"OAuthException"]){
NSLog(#"Exception from oauth let's take new token");
[facebook authorize:_permissions delegate:self];
}
}
Use this delegate function to handle exception.

Facebook IOS SDK: Error in Publish Story Dialog

I've successfully set up the "DemoApp" project from the Facebook IOS SDK to use my "OKC ThunderCast" Facebook application. I have also configured another "Tester" application from scratch to successfully use the Facebook SDK and publish stories to my news feed. However, in my production application, I always get this result when calling the "dialog" method. The full description of the error message is "Error on line 52 at column 17: Opening and ending tag mismatch: div line 0 and body"
Here's a detailed walkthrough of all of my code to make sure nothing is missed.
1) A UIViewController calls the "authorize" method
NSArray *fbPerms = [NSArray arrayWithObjects:#"read_stream", #"offline_access", nil];
[[FacebookSingleton sharedInstance].facebook authorize:fbPerms delegate:self];
Note: The FacebookSingleton is a class I wrote that always returns a single instance of the "Facebook" class. I am using it successfully in other applications.
2) Safari is opened and the user is successfully authenticated and authorized
3) The application is called back and the "handleOpenUrl" method is called, which calls the "fbDidLogin" method of the UIViewController
- (BOOL)application:(UIApplication *)application handleOpenURL:(NSURL *)url
{
Facebook *fb = [FacebookSingleton sharedInstance].facebook;
return [fb handleOpenURL:url];
}
4) The same UIViewController handles the "fbDidLogin" event, and calls the "dialog" method
- (void)fbDidLogin
{
[[FacebookSingleton sharedInstance].facebook dialog:#"feed" andDelegate:self];
}
I also have the necessary "URL Schemes" and "URL Types" entries in the .plist file. To my eyes, I am using exactly the same code in the "DemoApp", "Tester", and production applications. But while the DemoApp and Tester work, I always see this HTML error in the feed dialog in my production application. Has anyone seen a similar issue? Could it be related to the Facebook "Bundle ID" setting in the Facebook application settings? Is there some build or .plist setting that is different?
I have invested a great deal of time into troubleshooting with no success in several weeks. Thanks in advance...
The cause of the problem was setting a value to the key "User-Agent" in the NSUserDefaults dictionary. I wanted to specify my own User-Agent to uniquely identify my iOS app. But somehow setting this value caused the problem above. When I simply renamed this key to "OKCTC-User-Agent" the error was immediately resolved.
I did log an issue on the GitHub site for the Facebook-IOS-SDK. Hopefully this will help others who have encountered similar problems.

Resources