Google SignIn fails when serverClientID specified - ios

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.

Related

LinkedIn sdk iOS error if already logged in to LinkedIn App

I'm using the iOS LinkedIn SDK to log into my App and retrieve basic profiles.
All works perfectly fine the first time I login, until either I log out, or I close my App.
On attempting to log back into my App with LinkedIn: the usual redirect to the LinkedIn app takes place, but the permissions screen for my app doesn't pop up, it just redirects straight back to my app with the following error:
Error Domain=LISDKAuthError Code=5 "(null)" UserInfo={errorDescription=The operation couldn’t be completed. Software caused connection abort, originalDomain=LISDKServerError, errorInfo=PARSING_ERROR}
I can only successfully log back in again if I first close the LinkedIn App, before reopening mine.
Does anyone have an idea of what's going on please?
-This doesn't occur on all of my test devices!
-On the device that it does occur on, I also receive the same error in that scenario when running the sample App provided with the LinkedIn SDK.
-The LinkedIn App is up to date.
-The App id, bundle ids etc etc are all set, hence login success half of the time!
-I've tried calling [LISDKSessionManager clearSession] in numerous locations.
Cheeky framework fix alert.
Uncomment out the lines in LISDKSession.h
This allows the correct use of [LISDKSessionManager hasValidSession]
Which is an improvement on what we were working with.
Not yet tested with iOS12...
I had a similar problem. It was mainly reproduced only on iOS 12. The problem is that when you already have a LinkedIn application running, you will not be able to log in through their SDK in your application. On iOS 11, the second time you try to log in after this error, the authorization worked fine.
I solved this issue by simply showing the user an alert with a message about what he needs to do to authorize.
Here you can check an example of my implementation in Swift 4:
LISDKSessionManager.createSession(withAuth: ["r_basicprofile"],
state: nil,
showGoToAppStoreDialog: true,
successBlock: { _ in
// Your actions in case of successful authorization
}, errorBlock: { error in
guard let nsError = error as NSError? else {
return
}
if #available(iOS 12.0, *),
nsError.code == LISDKErrorCode.SERVER_ERROR.rawValue {
// Show alert to user with text - "Please, shut down the LinkedIn app and try login again"
} else if nsError.code != LISDKErrorCode.USER_CANCELLED.rawValue {
// Handling when user tap on Cancel button in LinkedIn SDK
}
})
I've been battling for a fix for this with LinkedIn for months.
There 'solution' is to kill off the SDK.
Taken from their 'Important updates to the LinkedIn Developers program and APIs' email December 2018:
"Authentication, SDKs, and Plugins: We are also deprecating several obsolete or seldomly-used products and technologies."
"SDKs: Our JavaScript and Mobile Software Development Kits (SDKs) will stop working. Developers will need to migrate to using OAuth 2.0 directly from their apps."
Uncomment this two lines of code in LISDKSession.h
- (LISDKAccessToken *)getAccessToken;
- (void)setAccessToken:(LISDKAccessToken *)accessToken;

What is the equivalent of iOS applicationWillTerminate in IBM MobileFirst Hybrid app?

Scenario:
I want to call the logout function if the app is terminated. I'm able to do it using native code:
- (void)applicationWillTerminate:(UIApplication *)app
{
// Run Logout function
}
Problem:
How to do it in IBM mobilefirst hybrid app?
// ************************************************
Edited
First of all, user login in to the app, if the user key in the correct user id and password, it will add the userIdentity into "loginRealm".
WL.Server.setActiveUser("loginRealm", userIdentity);
Next, user closes the apps without logout. So, when the user login for the another time, MFP server will not return any feedback since it will hit this exception:
Cannot change identity of an already logged in user in realm
'loginRealm'. The application must logout first.
Hence, I have to logout the user from MFP server by setting the "loginRealm" to null in adapter;
WL.Server.setActiveUser("loginRealm", null);
The above line of code is in the logout function defined in authentication-config.xml.
The client side device runs this line of code and it will trigger the logout function. Besides, it will reload the App upon success:
WL.Client.logout('loginRealm', {
onSuccess: WL.Client.reloadApp
});
Steps that I've tried:
1) At WlcommonInit() I added WL.Client.updateUserInfo(); and if WL.Client.isUserAuthenticated("loginRealm") return true I will logout the user from server. However, WL.Client.isUserAuthenticated("loginRealm") will always return false. This is because, it needs to take sometime around (30seconds to 2 minutes) for the flag to turn true after WL.Client.updateUserInfo();. So my login still fail and hit the same error.
2) I tried to logout the users during the user click login button. But the app will refresh and return to login page again due to reloadApp. The logout code I get from IBM mobilefirst website. So user need to click and type 2 times in order to login into the main menu.
WL.Client.logout('loginRealm', {
onSuccess: WL.Client.reloadApp
});
Am I doing it wrongly? Or are there any other methods to get WL.Client.isUserAuthenticated("loginRealm") return true instantly after WL.Client.updateUserInfo(); ? Can we remove the reload app line of code in logout function?
I don't think this is doable, because that logout function (in MFP) will require server connectivity (request and response) and if the app is by then killed, I think it's going to cause unpredictable results.
Note though that it seems to be not recommended to use that function anyway? applicationWillTerminate when is it called and when not
What you should do perhaps in order to simulate it, is to logout-on-login, so that it would appear that the app is logged out when opening it. You can extend the duration of the splash screen so that the end-user will not see that s/he is logged in (in case the session was still alive between the closing and re-opening of the app), until really logged out and then you can display the login screen again or any other required screen.

Parse Log in With Twitter Initial Failure

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.

Forced to create a new Quickblox session every time iOS app is opened

I am using the Quickblox iOS SDK 2.0.12
I have been following the instructions on Quickblox Authentication and Authorization here.
I call QBRequest createSessionWithSuccessBlock:, and then call QBRequest signUp: inside it's completion block, and then I call QBRequest logInWithUserLogin: inside the next completion block.
According to the above link, I should now have a Quickblox User Session after doing all of this. This all works perfectly and all of the calls are successful and I can see that the user is now in the Quickblox Admin Panel.
After doing this, if I make Quickblox requests they work fine. The only weird thing is that [[QBSession currentSession] currentUser] NSLogs as (null).
Anyways, if I stop running the app on the simulator, and then run the app again 10 minutes later, I check for persisted custom data so I can see if the user has already signed up or not. When the user has signed up, then I take them into the app instead of them needing to signup or login again.
Now, if I try to make any requests to Quickblox, I get the following exception:
Terminating app due to uncaught exception 'BaseServiceException', reason: 'You have missed the authorization call.
Please insert following code inside your application
[QBRequest createSessionWithSuccessBlock:errorBlock:];
Before any other code, that uses our service, but after setup credentials. Thank you.'
I don't understand why it's saying I need to create a session when I already just created one when the user first signed up. I understand that the session expires every 2 hours, but I am testing this very quickly and I am always receiving this error.
If I NSLog [QBSession currentSession] I can see that there is currently a QBSession object, but if I try to NSLog any of it's properties like sessionDetails, sessionExpirationDate, or currentUser they all log as (null).
As I know, only if you use this method - (void)startSessionForUser:(QBUUser *)user withDetails:(QBASession *)session expirationDate:(NSDate *)sessionDate , you can use this property correct. But I didn't ever use it.
For recreating a session I use [QBConnection setAutoCreateSessionEnabled:YES] and for chat I keep QBUUser in my Manager, and after entering foreground I check XMPP connection [[QBChat instance] isLoggedIn]. Maybee it may help you.

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