It is strange that Firebase can't create user in Unity SDK out of the box.
Firebase Console was tuned (anonymous access and email/password access are enabled) and google-service.json was placed in Assets folder of Unity.
However, Firebase still won't create a user. This is the code where it always fails:
auth.SignInAnonymouslyAsync().ContinueWith(task => {
if (task.IsCompleted && !task.IsCanceled && !task.IsFaulted) {
Debug.Log("User is now signed in.");
FirebaseUser newUser = task.Result;
}
else if (task.IsFaulted || task.IsCanceled)
{
Debug.Log("User signup failed");
}
});
Why?
There are possible several reasons:
The app was run in the Editor, rather than on the device
The configuration file is not updated after you add Firebase Auth feature
The password is shorter than 6 chacters
The email address is in invalid form, e.g. abcdef#aaa
The first one is highly likely the reason why.
I have created a tutorial here, which covers the steps to create/login using firebase in Unity, hope this is helpful.
Related
so i'm making a Unity Game and using Google PlayGames Sign in method. It seems to work when building an APK but not when sending an .ABB for internal testing.
public void SignInWithPlayGames()
{
PlayGamesPlatform.Instance.Authenticate((success) =>
{
if (success == SignInStatus.Success)
{
string authCode;
PlayGamesPlatform.Instance.RequestServerSideAccess(true, code =>
{
authCode = code;
//Here i call the LoginWithGooglePlayGamesServicesRequest to log in with playfab
});
}
});
}
I can't figure it out why is working one way but not the other. I'm using:
Unity 2020.3.26f1
Google Play Services SDK v0.11.01 (I was using v10.14 but had the same problem)
Latest Playfab SDK (I don't think playfab is the problem here)
PD: Looks like some people could sign in with the internal testing, but not all... While the APK works for everyone
I've try updating the playfab SDK, GPS SDK, checking if everything was setup correctly (resources, client id, etc)
After uploading an aab google will resign it with a new SHA1. This is known as your App Signing Key Certificate and it is not really documented anywhere that you need to update after release.
You can find the new SHA1 currently (2022-12-13) in the google play console for your game under Setup -> App Integrity and then the App Signing tab.
There you'll see a SHA1 key that you should replace the one that is currently being used for your GPGS Credentials with.
You should create a new GPGS credential and put your dev key (if you scroll down the sha1 for that will be listed under Upload Key Certificate) in it so you can continue to test.
Is there a way to check if a user has recently authenticated on Firebase to avoid this message when trying to delete a user: "This operation is sensitive and requires recent authentication. Log in again before retrying this request."
I have been playing around trying to compare lastSignInDate (below) to current time but there seems to be a large margin of error on this which can cause problems:
firebase.auth().currentUser.metadata.lastSignInTime
Are there any functions that can return a simple boolean as to whether a user has recently authenticated so the user.delete() function will work properly?
Thanks so much!
The best way to do this is by checking if the response has an error, like so:
let user = Auth.auth().currentUser
user.delete { error in
if let error = error {
if (error.code == "auth/requires-recent-login") {
// The user's credentials are too old. Prompt Login screen.
}
} else {
// ...
}
}
According to Firebase Documentation, There's no other approach to this other than comparing the current date with firebase.auth().currentUser.metadata.lastSignInDate (Only if you have the Admin SDK on your app, but you most probably do not need that for enabling a user to delete themselves).
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.
I just installed the new version of Unity 4.3 and the new facebook sdk and I can't get it working.
I created the app on facebook, copied over the app id to the unity facebook settings as required and copied the Package Name and Class name back to facebook.
Because the Android Key Hash is empty ( even it shouldn't be ) I used the methods posted by others to create one with openssl. I created it and copied over to facebook as required.
After this I created a small script to be able to login.
// Use this for initialization
void Start () {
enabled = false;
FB.Init(SetInit, OnHideUnity);
}
// Update is called once per frame
void Update () {
}
private void SetInit()
{
FbDebug.Log("SetInit");
enabled = true; // "enabled" is a property inherited from MonoBehaviour
if (FB.IsLoggedIn)
{
FbDebug.Log("Already logged in");
OnLoggedIn();
}
}
private void OnHideUnity(bool isGameShown)
{
FbDebug.Log("OnHideUnity");
if (!isGameShown)
{
// pause the game - we will need to hide
Time.timeScale = 0;
}
else
{
// start the game back up - we're getting focus again
Time.timeScale = 1;
}
}
void OnGUI(){
if (!FB.IsLoggedIn)
{
if (GUI.Button(new Rect(179 , 11, 287, 160), "Login to Facebook"))
{
FB.Login("email", LoginCallback);
}
}
}
void LoginCallback(FBResult result)
{
FbDebug.Log("LoginCallback");
Debug.Log("LoginCallback");
if (FB.IsLoggedIn)
{
OnLoggedIn();
}
}
void OnLoggedIn()
{
FbDebug.Log("Logged in. ID: " + FB.UserId);
}
Now when I click on the login button a Facebook window appears requesting permission, after I press ok, it returns, but I'm still not logged in... Can anybody help why is this?
Another strange thing I observed that the LoginCallback gets called as soon as I click on the login button, even though I would think it should only when I gave permission. Anyway when I give permission it returns to my app and nothing happens. I can click on the login button again and same thing happens, login callback called, it asks for permisions, I give the permision and returns back, nothing happened. Can anybody help?
Version 4.3.6 of the sdk should fix this problem. It's available here: https://developers.facebook.com/ We are still waiting for it to be approved on the asset store, so the only place to get it right now is from Facebook's site.
Note - it's still broken (5/2014) IF you use a Mac. Just follow the "Rafael solution", discover your hash properly from public void OnLoginComplete(string message). Cheers
So after being frustrated for a few days with having to trace out the key to my phone, I decided to look into what it was doing.
After some research it turned out that when you published to an android device, facebook would use the keystore that was defined in your publish settings, not your .android/debug.keystore file. So I went in and changed the sdk to make it work the proper way. Essentially I changed the SDK to look at the ProjectSettings instead of the debug directory for grabbing the key hash. In the FacebookAndroidUtils.cs I added the following.
// Using the user defined keystore values instead of the debug one.
degbugKeyHash = GetKeyHash( PlayerSettings.Android.keyaliasName, PlayerSettings.Android.keystoreName, PlayerSettings.Android.keyaliasPass, PlayerSettings.Android.keystorePass );
I created a small repo that provides the fix as well as some gui changes to make it more easy to update the key hash.
Github Facebook Unity SDK 6.1 Fix
Update - Fixed a bug with OS X related to escaping spaces on the string path
Hope this helps!
Take the "email" permission out of the login function and try it. Oops I thought I seen the "publish_actions" permission in there too.
Make sure the loginactivity in the manifest is in portrait.
Instead of implementing everything yourself, try using the free and open source SOOMLA Profile plugin for all of your social network needs:
https://github.com/soomla/unity3d-profile
Also available on the asset store for download:
https://www.assetstore.unity3d.com/en/#!/content/24601
It covers Facebook, Twitter and Google+ and has a unified API for logging in, posting statues, uploading images and getting friends lists. For proper disclosure, I'm one of the founders.
I think this is because Facebook just made some changes to their login process.
A few days ago, my air app was working with the FacebookDesktop class from the facebook-actionscript-api. Today I opened the project, and noticed that the Facebook login screens are a little different than when I started building my app. After I type my userID and password in, I grant the app access to my public profile, friend list and photos. Then another screen comes up where I grant the app permission to post to my friends on my behalf.
Then the window closes, and I get 'OAuthException 2500 An active access token must be used to query information about the current user.'
When I sign into Facebook through a browser, I see that my app shows up under "Your Apps" but I can't log in and do anything through my app.
I'm using Adobe Flash with GraphAPI_Desktop_1_8_1.swc on OSX Lion.
Here is my code:
public function MyApp(){
FacebookDesktop.init(APP_ID, onInit);
}
protected function onInit(result:Object, fail:Object):void {
if (result) {
trace("onInit, Logged In\n");
} else {
trace("onInit, Not Logged In\n");
var permissions:Array = ["publish_stream", "user_photos"];
FacebookDesktop.login(onLogin, permissions);
}
}
protected function onLogin(result:Object, fail:Object):void {
if (result) {
trace("Logged In as:");
trace(FacebookDesktop.getSession().user.name);
} else {
trace("Login Failed");
trace('code: '+fail.error.code); //code: 2500
trace('message: '+fail.error.message); //message: An active access token must be used to query information about the current user.
trace('type: '+fail.error.type); //type: OAuthException
}
}
I get the same results when I use the FlashDesktopExample provided in the SDK (modified with my app ID of course).
Any help would be great! Thanks in advance!
I ran into this problem, too: the success URL did not have any parameters.
Cadderly82 is correct; it's a problem with secure navigation. Turning off my Facebook account's "Secure Browsing" option fixed the problem, but I didn't want to have to require users to do that.
I was able to solve this by setting ALL of the FacebookURLDefaults values to use "https://".
Now I get a valid user-access-token in the success URL; and I get valid values regardless of my facebook account's secure-browsing setting.
I have figured out the problem:
The LoginWindow class sets the token based on the uri.
This worked fine until the LOGIN_SUCCESS_URL (http://www.facebook.com/connect/login_success.html) and the LOGIN_SUCCESS_SECUREURL (https://www.facebook.com/connect/login_success.html) pages stopped including the access token in the uri.
Hence, the token is never set. Even though my app shows up under the 'Your Apps' section in Facebook after I login, my app still can't do anything without a token.
I have two solutions:
The easiest is to change the LOGIN_SUCCESS_URL and/or the LOGIN_SUCCESS_SECUREURL properties in com.facebook.graph.core.FacebookURLDefaults like the following.
beginning on line 82:
public static var LOGIN_SUCCESS_URL:String = 'http://www.facebook.com/connect/login_success.html';
public static var LOGIN_SUCCESS_SECUREURL:String = 'https://www.facebook.com/connect/login_success.html';
Change to:
public static var LOGIN_SUCCESS_URL:String = 'http://www.yourwebsite.com/';
public static var LOGIN_SUCCESS_SECUREURL:String = 'https://www.yoursecurewebsite.com/';
of course you would use your own website - not 'http://www.yourwebsite.com/'. I tried it using http://localhost/ and it worked great.
Another solution is:
Change com.facebook.graph.windows.LoginWindow with the following code. I have made some changes to my files, so please forgive me if the line numbers are different than what they are in a fresh copy of the SDK.
around line 143:
change:
vars.redirect_uri = FacebookURLDefaults.LOGIN_SUCCESS_URL;
to:
vars.redirect_uri = 'http://localhost/';
In production code, you probably want to use your own website address instead of localhost, but I used localhost for testing purposes.
Then, in the handleLocationChange function (should be around line 168) add this to the else if statements:
}else if (html.location.indexOf ('http://localhost/') == 0) {
loginCallback(getURLVariables(), null);
userClosedWindow = false;
html.stage.nativeWindow.close();
html.removeEventListener(Event.LOCATION_CHANGE, handleLocationChange);
}
As I said before, change localhost to your website address.
I hope this helps!
I was having the same problem for random users and I don't really know if it is a Facebook problem with secure navigation:
Check user properties in Facebook: Security Settings > Secure Browsing
(www.facebook.com/settings?tab=security)
For users with "disabled" state it works fine.
For users with "migration" state it gives the error.
For users with previously "enabled" state it works fine.
When I tried with users in "migration" state and changed to "disabled", it worked fine.
Then if I turned it "enabled", the "migration" state is gone and marked as "enabled", but the error it's still there.
So I guess this is the problem, but don't know how to fix it.
alot has change in a year this is what i think the answer is now
you need a token to login FacebookDesktop.getSession().accessToken
public function MyApp(){FacebookDesktop.init(APP_ID, onInit, FacebookDesktop.getSession().accessToken); }