Firebase Authentication using facebook and google signin not working when internet is turned off and turned back on - facebook

I have a strange issue with firebase authentication. SigninCredential callback never gets called when I turn off and turn back on the internet. Only after a few hours(probably after 4 hours) callback gets triggered
val mCredential = FacebookAuthProvider.getCredential(mAccesstoken!!.token)
mFirebaseAuth.signInWithCredential(mCredential)
.addOnCompleteListener(this) { it ->
if (it.isSuccessful) {
// Sign in success, update UI with the signed-in user's information
Log.d(TAG, "signInWithCredential:success")
getCurrentUser(mFirebaseAuth.currentUser)
} else {
// If sign in fails, display a message to the user.// unable to retrieve details of the user
Log.w(
TAG,
"signInWithCredential:failure:: FirebaseAuthentication failed even though accesstoken present",
it.exception
)
Toast.makeText(
baseContext, "Authentication failed.",
Toast.LENGTH_SHORT
).show()
}
}
If I do a fresh install of the app and perform a sign in it works properly provided that the internet is turned on while I try to login into the app

First check for internet connection before executing the above code.

I figured out the issue. I added an active internet condition before performing a login that fixed sign-in problem. check the internet available on the device then only perform the login
I did face another issue that is addOnCompleteListener never gets called because I was waiting on the main thread instead I used executor to perform the task on a background thread

Related

knpuniversity oauth2client expected state is null often

vendor/knpuniversity/oauth2-client-bundle/src/Client/OAuth2Client.php:
When I logout user and try to login with facebook again, often I get this exception - InvalidStateException. "User see Invalid state parameter passed in callback URL." Thats because there is no data in session. But why that can happen?
Using this bundle:
https://github.com/knpuniversity/oauth2-client-bundle
This is called from my facebook authenticator class:
public function getCredentials(Request $request)
{
// this method is only called if supports() returns true
return $this->fetchAccessToken($this->getFacebookClient());
}
Also noticed if I try again to login with facebook after this exception, then it logs in succesfully. But later noticed this is also not always the case.
I am thinking there is soemthing to do with race condition somewhere, because when I use xdebug and code stops at breakpoinst, it often workse ok.
The problem was chrome sending 2 requests because of prefetching.
https://www.keycdn.com/support/prefetching
When I enter url in address bar (for testing I had not made facebook button yet) chrome instantly loads it. Then I press enter and it loads it again. And things start happing what is unexpected when there are 2 requests to login with facebook.
Tested on firefox, there is no such problem. When I have made link to login to facebook and so I dont have to type in address bar, it also does not make prefetch and problem is gone on chrome also.

Unity Facebook SDK: FB.IsLoggedIn / FB.ShareLink issue

I'm trying to create my mobile app user to share my Facebook page and if they do, I give them an in-game item. I'm using the example code provided by Facebook here: https://developers.facebook.com/docs/unity/examples
The first issue is that FB.ShareLink doesn't comeback negative if the user cancels the sharing action. From what I've read, that's on purpose and it only works correctly if the user is logged in and my app is authorized. I tested it and that's true, if I use the login code to first login, it comes back as positive or negative correctly.
The second issue that I'm having though is that FB.IsLoggedIn never comes back negative and I'm not sure how to properly check this because even though it comes back as true, my app is note authorized and FB.ShareLink doesn't return negative when canceled. I start the Login issue and then I press the back arrow to cancel it but FB.IsLoggedIn still comes back as true.
How can I just check if the app is authorized? I'm guessing that's all I need to check before running the FB.ShareLink code.
Any ideas?
Thanks!
First, we try to login asking for the user's e-mail address.
public void LogIntoFacebook() {
List<string> perms = new List<string>() { "email" };
FB.LogInWithReadPermissions(perms, OnLogin);
}
Then you can check to see if you got the e-mail address permission using
AccessToken token = AccessToken.CurrentAccessToken;
if (token.Permissions.Contains("email")) { // do something }
If you do, then you move forward with the Facebook share.

Ionic/Firebase: Log in after logging out doesn't work

I am building an Ionic/Phonegap app with a Firebase backend.
Login
Followed the example from the official AngularFire documentation for login:
// Check sign-in data
$scope.signIn = function(user, password) {
// Log in
$scope.auth.$authWithPassword({
email : user,
password : password
})
// If successful
.then(function(authData) {
console.log('worked');
// Further code
}
// If failure, alert
.catch(function(error) {
console.log(error);
}
}
Login works fine.
Logout
For logout I also copied the example from the documentation:
$scope.logout = function() {
// Manually disconnect from database
Firebase.goOffline();
// Log user out
$scope.auth.$unauth();
// Go to landing page
$state.go('signin');
};
Seems to work as well (when I'm asking for the current authentication state of the user after logging out $getAuth() returns null).
Login after Logout
But if I'm now trying to log in again, nothing happens - no error, no success message. So neither of the console.logs triggers.
I need to close and open the app again or refresh the browser window in order to be able to log in again. Can anyone tell me what I'm doing wrong here?
Versions
Using the latest versions:
Ionic 1.2.4
Firebase 2.4.0
AngularFire 1.1.3
Remove the Firebase.goOffline() from your logout. If you want to manually manage Firebase connection then you should consider adding Firebase.goOnline() during login.
Auth.$unauth() will take care of logging out the user, you do not have to disconnect Firebase manually.

Facebook login WinJS Store app issues

I tried following this blog post
Which explains how to setup up facebook login on a WinJS app.
I got it all working, got the app ids set and the authentication dialog is showing the correct app name and authentication stuff, however when the app redirects the app receives this error (after closing the dialog: "The specified protocol is unknown") and the dialog shows the error message: "We can't connect to the service you need right now. Check your network connection or try this again later".
the error stack:
"WinRTError: The specified protocol is unknown.\r\n\n at getResultsOfAsyncOp (Function code:338:5)\n at op.completed (Function code:427:21)
Actual calling code:
var loginURL = "https://www.facebook.com/dialog/oauth?client_id=[snip]&display=popup&scope=user_about_me&response_type=token&redirect_uri=ms-app://s-[snip]/"
Windows.Security.Authentication.Web.WebAuthenticationBroker.authenticateAsync(
Windows.Security.Authentication.Web.WebAuthenticationOptions.none,
new Windows.Foundation.Uri(loginURL))
.then(function success(result) {
}, function error(error) {
});
Hopefully anyone here has any idea why this error message is thrown.
We managed to solve the issue.
The sid from the store was different from the sid of the app during local debugging. By changing the appmanifest -> packaging -> publisher certificate to a local certificate with the CN provided in the store settings the sid is updated to be equal to the one in the store.
et voila, it works.

Signin with Twitter stopped working suddenly

I have a web application which uses Twitter's OAUTH to login users. I am using Twitter4J version 2.1.11
This application has been working flawlessly and stopped working very recently, possibly in the past couple of weeks.
public static void authWithTwitter() {
try {
Twitter twitter = new TwitterFactory().getInstance();
twitter.setOAuthConsumer(TWITTER_CONSUMER_KEY, TWITTER_CONSUMER_SECRET);
RequestToken requestToken = twitter.getOAuthRequestToken(getTwitterCallbackUrl());
// save requestToken for retreival after user logs in
// code not shown for brevity
redirect(requestToken.getAuthenticationURL());
} catch(Exception e) {
cLogger.error("Could not perform pre twitter login steps", e);
}
}
This code would (till the app was working) redirect the user to Twitter's login page, which upon successful authentication, would call the callback url.
However, recently, this has stopped working and I get the following Exception.
401:Authentication credentials (http://dev.twitter.com/pages/auth) were missing or incorrect. Ensure that you have set valid conumer key/secret, access token/secret, and the system clock in in sync.
Failed to validate oauth signature and token
Relevant discussions can be on the Internet at:
http://www.google.co.jp/search?q=8dda30a8 or
http://www.google.co.jp/search?q=68161d96
TwitterException{exceptionCode=[8dda30a8-68161d96], statusCode=401, retryAfter=0, rateLimitStatus=null, version=2.1.11}
at twitter4j.internal.http.HttpClientImpl.request(HttpClientImpl.java:199)
at twitter4j.internal.http.HttpClientWrapper.request(HttpClientWrapper.java:75)
at twitter4j.internal.http.HttpClientWrapper.post(HttpClientWrapper.java:112)
at twitter4j.http.OAuthAuthorization.getOAuthRequestToken(OAuthAuthorization.java:148)
at twitter4j.TwitterOAuthSupportBaseImpl.getOAuthRequestToken(TwitterOAuthSupportBaseImpl.java:88)
at twitter4j.Twitter.getOAuthRequestToken(Twitter.java:58)
I did some searching and verified that I have the callback url set properly in my app's settings in dev.Twitter.com
I have not yet re-generated the key and consumer secret, but that would be the next step if I cannot get it to work.
Does anyone have a clue, why this would stop working ?
Make sure the servers clock is set correctly. If it is more than a few minutes off from Twitter's requests will fail.