Implementing Facebook Login with conditional redirection in iOS SDK - ios

I have a requirement to integrate facebook login in my iOS app, everything is fine according to the instructions given at the below link
https://developers.facebook.com/docs/ios/getting-started
However I have a scenario where I need to implement a conditional redirection for facebook, such as
if (User is Not Logged In)
{
Then redirect to The Installed Facebook application and Get the details of user from the Facebook Application
}
else
{
// If user is logged in
Then Open a Webview to Enter Login
Credentials
}
my problem is due to placing the URL Schemes under URL types in info.plist I can open it in only one manner across the application,
Either I place The facebookId URL schema as the First Object and open the Installed facebook app, or Place it as second Object to open a Webview
Is there any way possible where I can check if the user is logged in then place the URL Schema at the top and not make it fallback to webview, but if not I Change it to be the first object in URL Types so it open the installed Facebook Application for Login

Related

Facebook iOS LoginButton SDK only uses Web or System Authentication; never uses FB app

I'm testing Facebook single sign on in the following scenarios
When an account is logged in via Settings\Facebook
When an account is logged in via Safari
When an account is logged in via the local app.
The last test, when the Facebook app is installed and has valid credentials, never seems to work.
The only options that seem to work is when Safari is logged out OR the settings\Facebook system isn't logged in either.
I don't want to cause the user to ever enter a password, especially into a Web browser (or something that looks like one).
Question
How do I get iOS SDK to authenticate using the installed, working Facebook app?
Research
I've tested all forms of Facebook authentication, where I set the loginButton to all loginBehaviors, and even a null parameter
loginButton = new LoginButton (new CGRect (48, 0, 218, 46)) {
// LoginBehavior =
// LoginBehavior.Browser // safari
// LoginBehavior.Native // safari
// LoginBehavior.Web // popup (doesn't feel secure)
//LoginBehavior.SystemAccount // SYSTEM, if fail then Safari... ignore app
};
Have you whitelisted Facebook apps in the info.plist file?
From Facebook Docs (https://developers.facebook.com/docs/ios/ios9):
If you use any of the Facebook dialogs (e.g., Login, Share, App
Invites, etc.) that can perform an app switch to Facebook apps, you
will need to update your application's plist to handle the changes to
canOpenURL described in
https://developer.apple.com/videos/wwdc/2015/?id=703.

Unable to Login as Different User After Logging out of iOS application

So here is my problem. I log in to my application, then log out of my application, but when I try to log in again, I get the screen in the link below.
Login Screen
As you can see, I don't get the opportunity to login with another user, which is what is intended.
What I tried to do was logout and then clear all the cookies in the logout using these following methods:
#IBAction func logout(sender: AnyObject) {
//Logged out here
let loginManager = FBSDKLoginManager()
loginManager.logOut()
//This is one method I tried
let appDomain = NSBundle.mainBundle().bundleIdentifier!
NSUserDefaults.standardUserDefaults().removePersistentDomainForName(appDomain)
//This is another method I tried
for key in NSUserDefaults.standardUserDefaults().dictionaryRepresentation().keys {
NSUserDefaults.standardUserDefaults().removeObjectForKey(key)
}
//And this is the last method I tried
var cookie: NSHTTPCookie
var storage: NSHTTPCookieStorage = NSHTTPCookieStorage.sharedHTTPCookieStorage()
for cookie in storage.cookies! {
var domainName: String = cookie.domain
var domainRange: Range = domainName.rangeOfString("facebook")
if domainRange.length > 0 {
storage.deleteCookie(cookie)
}
}
}
None of these seemed to solve my problem. The app is in "Development" mode in the Facebook Dev account so it might have something to do with this, but not totally sure. Does someone have any experience with this and know the solution to our problem, as shown in the image above.
The whole goal of Facebook login is to allow quick, seamless login into your Facebook account without having to re-enter credentials.
To achieve this, the Facebook SDK tries to leverage credentials that are already stored on the device, which may include:
login information from the Facebook app
cookies related to Facebook login in Safari (directly or via the SFSafariViewController)
system Facebook accounts
When you logout, you actually only have the Facebook SDK forget the credentials within the app (it clears the token). When you login again, it acts like the first time you did, and if it finds an existing user, it will use that (the Facebook SDK makes the — usually valid — assumption that there is a single person using the device, and they have a single Facebook account).
The current "favorite" path for the Facebook SDK (though that varies with SDK versions, iOS versions, and possibly other parameters) is SFSafariViewController, which shares cookies with Safari, not with your app.
If you want the user to completely log out on the device, they would then have to use the log out link within Facebook in Safari (or an SFSafariViewController).
If you want to do so programatically, you may open the following URL in Safari or an SFSafariViewController:
https://www.facebook.com/logout.php?next=[YourAppURL]&access_token=[ValidAccessToken]
You'll have to use a custom URL scheme to return to your app/exit the SFSafariViewController, though.
If you, as a user, want to see permissions request from Facebook again, you should remove the app from user's profile on Facebook.
When you are at settings screen, find your app and hit the cross button

Link to Ionic page from external website

I'm integrating an Ionic app with a 3rd party web authentication framework. The framework requires that the user visit a web page to authenticate and then receive several authentication token cookies.
I plan to open a link to the external login page, have the user authenticate, and then be redirected back to the Ionic app.
I need a URL to the homepage of my app so that the login page can redirect the user back after logging in. How do I generate a a URL for a location in the Ionic app?
why not just use the in app browsers plugin so that the user never has to leave the app in the first place.
https://github.com/apache/cordova-plugin-inappbrowser
Our app has a blog and we use this
$scope.readMore = function (index) {
$scope.link = $scope.articles[index].WebLink;
window.open($scope.link, '_blank', 'transitionstyle=crossdissolve,toolbarposition=top');
};
by using the option _blank we can have the user open up a webpage inside the app not have to have the navigate away from the app in order to access a url, i also looks way better than a iframe.

Facebook iOS SDK and Safari based authentication issue

I have used latest FB SKD in my iOS app so users can use facebook account to login. Application open the FB app and comes back to my app perfectly fine. However, in some place in the app, i have to show/pull some people facebook page (safari based using WebView), but even user already used the Facebook account to login into my native ios app, but the page still ask user to login again and when they click login, it shows them the annoying FB username/pass page.
Is there anyway, that the FB safari based page can authenticate the user since it's already logged into my app using FB integration? do i have to include query or something. Please give me details how to solve this problem since i'm new in this..
thanks again for your help...
pic: https://www.dropbox.com/s/rjlptu7ufpcq3vl/fb.png
When the user switches to Facebook app to authenticate, it doesn't create a cookie for your UIWebView which is why it's asking to login again. Have the user authenticate inside the UIWebView without switching to the Facebook app.
What you're talking about also sounds like a similar thing that happens with Facebook dialogs not knowing about the current Facebook session.
If you authenticate your user via Facebook, try saying the Facebook object itself as an instance variable somewhere in memory so you can access it again (a property on a singleton controller, perhaps?).
Spawning dialogs from an authenticated Facebook object appears to let them use the dialog without reauthenticating iff you have a [FBSession activeSession]. So you'd also have to maintain an active FB session. But I'm not sure if this kind of solution will work since you didn't show specific code for how you're doing your web-based FB fetches.
This question might also prove helpful:
Implement Login with Facebook in iOS 5 and 6

Facebook single sign on in iOS issue

I just run the demo app for the single sign on Facebook and I am getting the following:
And what I want is actually something like this:
I wanted it to not show as a web view, how do I do that?
Please see my answer here (which answers this question):
FaceBook API, login in-app
Please also note my caveat. OAuth was designed to authenticate outside of your application - but in this case, you can make it work inside (but it breaks a core principle of OAuth).
When an app requests authorization or login, the application gets the user's login information via the browser (as you showed in the second image) or, if you have the Facebook app installed, from the Facebook app. It looks like you have the Facebook app installed, so the app automatically pulled the user's information from that app.
Then, for any new app that a user uses, Facebook verifies with the user that the app's requested features are allowed by the user.
Since your device pulled the login info from the Facebook app, the email/password screen is not used and the permissions screen is shown first. Once you allow the features, you should not see that screen again, when you start the app again for that same user.
Modify your Facebook.m
- (void)authorize:(NSArray *)permissions {
self.permissions = permissions;
// with both options NO, authorization always happens in-app
[self authorizeWithFBAppAuth:NO safariAuth:NO];
}

Resources