With Authentication

102 views
Skip to first unread message

Super bunso

unread,
Jul 6, 2018, 7:51:39 AM7/6/18
to firebase-unity-solutions
I was able to try the demo for the leaderboard..now I want to add authentication.. now I can login to google play as authentication and make login for firebase.. I have uid.. question is 
how I can add it to demo? also the leaderboard controller seem only for public..I try to change the firebase-db-rules.txt but still denied.. 
also possible to get all the other scores? 

Super bunso

unread,
Jul 8, 2018, 8:01:00 PM7/8/18
to firebase-unity-solutions
any?

Dane Liergaard

unread,
Jul 9, 2018, 2:45:29 PM7/9/18
to firebase-unity-solutions
Hi Super Bunso, thanks for reaching out!

First a note to be clear: Changing the text in firebase-db-rules.txt won't do anything, as it is merely a file to contain the rules text to copy and paste into the Firebase Console. In order to change the rules for your DB, you will have to log in to the console, select your project, open the Database section and navigate to Rules. That is where changes to the rules are registered.

If you want to use Firebase Auth, I would recommend using the rules in firebase-db-auth-rules.txt. What this does is leave the reading of scores public to anyone (so you will be able to read other users scores, necessary for the leaderboard), but only allows writes if the user_id field of a new score matches the auth.user_id variable built in to Firebase Database rules' syntax.

This question makes me realize that there should probably be a "username" field on the score records as well, since UID is not the best public representation of a user on the leaderboard itself. I will add that as a task for the repo. 

Please follow up on whether this helps, or if you need any more details on auth or any other aspect of the leaderboard. Good luck!

Best,
DZ

Dane Liergaard

unread,
Jul 9, 2018, 2:51:49 PM7/9/18
to firebase-unity-solutions
From your comment on the blog I see that you also changed the rules in the Firebase Console, so please disregard that part.

In that case I don't see any immediate reason to still be getting the access denied error. Did you follow the setup steps to authenticating your unity project with firebase here?

Perhaps you could post the full error message so that I can get more details of what exactly is going on.

Best,
DZ

Super bunso

unread,
Jul 10, 2018, 8:21:41 PM7/10/18
to firebase-unity-solutions
yes I follow the steps I already have uid.. but I dont use p12 cause thats from ios right? I'm only using it for android and im in windows pc btw.. 

here is the rules I use in the firebase console not sure if it the correct one 
{
  "rules": {
   "$uid": {
        ".write": "$uid === auth.uid",
        ".read": true,
      }
  }
}

Dane Liergaard

unread,
Jul 11, 2018, 12:44:56 PM7/11/18
to firebase-unity-solutions
Hi, you do need to use the p12 key regardless of OS, but only in the editor so that you can upload test scores without needing to be authorized as the test user.

Also, the LeaderboardController attempts to read the scores from the "all_scores" path (unless you change that in the inspector). Try these rules in the Firebase console:

{
"rules": {
"all_scores": {
".indexOn": ["score", "user_id"],
".read": "true",
".write": "newData.child('user_id') == auth.uid"
}
}
}

Super bunso

unread,
Jul 11, 2018, 8:49:44 PM7/11/18
to firebase-unity-solutions
thank you for reply .. I dont have the p12 key cause im using windows.. that why I'm directly testing in from device.. btw I gonna try this one.. thanks

Dane Liergaard

unread,
Jul 12, 2018, 12:11:54 PM7/12/18
to firebase-unity-solutions
Hi, no problem! Please let me know whether those rules help or not.

Regarding the P12 key, please see this setup step for Firebase Realtime Database, which is what allows in-editor authorization to be able to upload scores while ignoring the normal auth rules. Once you've verified that the auth rules work for individual users, this will give you more freedom to test things in-editor instead of having to build and test on device in all cases. It is consistent across operating systems, so working on Windows shouldn't be different from working on Linux or Mac.

Super bunso

unread,
Jul 15, 2018, 8:23:10 PM7/15/18
to firebase-unity-solutions
Hi I got error in firebase when changing the rules 
Error saving rules - Line 12: Invalid == expression: left operand is not a number, boolean, string, null.

Super bunso

unread,
Jul 15, 2018, 9:13:41 PM7/15/18
to firebase-unity-solutions
I change to rule like this to fix the error in firebase console 
{
  "rules": {
    "all_scores": {
      ".indexOn": ["score", "user_id"],
      ".read": "true",
      ".write": "newData.child('user_id').isString() == auth.uid"
    }
  }
}


but when testing in device i got this log in during sending score 
07-16 09:09:48.403: W/Unity(14930): 07/16/2018 01:09:48 [Warn] RepoOperation: setValue at /all_scores/-LHVci28tIH-xP12RvtX failed: DatabaseError: Permission denied
07-16 09:09:48.403: W/Unity(14930):  
07-16 09:09:48.403: W/Unity(14930): (Filename: ./artifacts/generated/common/runtime/DebugBindings.gen.cpp Line: 51)
07-16 09:09:48.427: W/Unity(14930): Exception adding score: System.AggregateException: Exception of type 'System.AggregateException' was thrown.
07-16 09:09:48.427: W/Unity(14930): -----------------
07-16 09:09:48.427: W/Unity(14930): Firebase.Database.DatabaseException: Firebase Database error: Permission denied
07-16 09:09:48.427: W/Unity(14930):  
07-16 09:09:48.427: W/Unity(14930): (Filename: ./artifacts/generated/common/runtime/DebugBindings.gen.cpp Line: 51)

Super bunso

unread,
Jul 16, 2018, 2:03:55 AM7/16/18
to firebase-unity-solutions
I also try to get P21 file  but it was not found not sure why.. I attached a screenshoot 
p21.png

Dane Liergaard

unread,
Jul 16, 2018, 12:01:47 PM7/16/18
to Super bunso, firebase-unity-solutions
Thanks for the correct rules and the screenshot, those are both very helpful. For for the file, please try putting the entire filename in the LeaderboardController's field, including the file extension (in this case, sampleP12.p12). Let me know if that works.

Best,
DZ

On Sun, Jul 15, 2018 at 11:03 PM Super bunso <http....@gmail.com> wrote:
I also try to get P21 file  but it was not found not sure why.. I attached a screenshoot 

--
You received this message because you are subscribed to the Google Groups "firebase-unity-solutions" group.
To unsubscribe from this group and stop receiving emails from it, send an email to firebase-unity-sol...@googlegroups.com.
To post to this group, send email to firebase-uni...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/firebase-unity-solutions/20ced183-3f1f-4250-a1e0-f742f04d922d%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Super bunso

unread,
Jul 16, 2018, 8:27:16 PM7/16/18
to firebase-unity-solutions
still did not work but different result.. now I got bad request .. also about the service account email.. I just follow this format SERVICE-A...@YOUR-FIREBASE-APP.iam.gserviceaccount.com
400 Bad Request
UnityEngine.Debug:LogError(Object)
Firebase.Platform.FirebaseLogger:LogMessage(PlatformLogLevel, String)
Firebase.Unity.UnityLoggingService:LogMessage(PlatformLogLevel, String)
Firebase.Unity.WWWHttpRequest:EnsureExecuted()
Firebase.Unity.WWWHttpRequest:get_ResponseCode()
Firebase.Platform.Security.ServiceAccountCredential:SendOAuth(OAuthRequest)
Firebase.Platform.Security.ServiceAccountCredential:GetAccessTokenForRequestSync(CancellationToken)
Firebase.Platform.Security.ServiceCredential:GetAccessTokenForRequest()
Firebase.Platform.Default.BaseAuthService:GetTokenAsync(IFirebaseAppPlatform, Boolean)
Firebase.Unity.FirebaseAuthService:GetTokenAsync(IFirebaseAppPlatform, Boolean)
Firebase.Platform.Default.BaseAuthService:GetTokenAsync(IFirebaseAppPlatform, Boolean, IGetTokenCompletionListener)
Firebase.Database.Core.AuthTokenProvider:GetToken(Boolean, IGetTokenCompletionListener)
Firebase.Database.Internal.Core.ConnectionAuthTokenProvider258:GetToken(Boolean, IGetTokenCallback)
Firebase.Database.Internal.Connection.Runnable557:Run()
Firebase.Database.Internal.Connection.Util.Runnable53:Run()
Google.Sharpen.Task`1:Run()
Google.Sharpen.ThreadPoolExecutor:RunPoolThread()
Google.Sharpen.RunnableAction:Run()
Firebase.Database.Internal.Utilities.ExceptionCatcher:Run()
Google.Sharpen.Thread:InternalRun()


On Tuesday, July 17, 2018 at 12:01:47 AM UTC+8, Dane Liergaard wrote:
Thanks for the correct rules and the screenshot, those are both very helpful. For for the file, please try putting the entire filename in the LeaderboardController's field, including the file extension (in this case, sampleP12.p12). Let me know if that works.

Best,
DZ

On Sun, Jul 15, 2018 at 11:03 PM Super bunso <http....@gmail.com> wrote:
I also try to get P21 file  but it was not found not sure why.. I attached a screenshoot 

--
You received this message because you are subscribed to the Google Groups "firebase-unity-solutions" group.
To unsubscribe from this group and stop receiving emails from it, send an email to firebase-unity-solutions+unsub...@googlegroups.com.
p21.png

Dane Liergaard

unread,
Jul 30, 2018, 3:57:40 PM7/30/18
to Super bunso, firebase-unity-solutions
Hi Super, sorry for the delay - Google Next was last week and everyone was heads-down preparing for that the week before. I am back at work this week and haven't had a chance to return to this yet, but just wanted to check in to let you know it's still on my radar. Let me know if you have gotten it figured out as well, and I can add some documentation to hopefully prevent anyone else from having the same issue in the future.

Best,
DZ

To unsubscribe from this group and stop receiving emails from it, send an email to firebase-unity-sol...@googlegroups.com.
--
You received this message because you are subscribed to the Google Groups "firebase-unity-solutions" group.
To unsubscribe from this group and stop receiving emails from it, send an email to firebase-unity-sol...@googlegroups.com.

To post to this group, send email to firebase-uni...@googlegroups.com.

Dane Liergaard

unread,
Jul 31, 2018, 1:15:30 PM7/31/18
to Super bunso, firebase-unity-solutions
Hi Super, to be clear, did you get the service account email from either the IAM page on the cloud console (https://console.cloud.google.com/iam-admin/iam) or by finding it in the service account settings in the firebase console, like in the following screenshot?ss.png

Thanks,
DZ
Reply all
Reply to author
Forward
0 new messages