GodotNuts / GodotFirebase

Implementations of Firebase for Godot using GDScript
MIT License
554 stars 79 forks source link

[FEATURE REQUEST] Google Account direct Authentication #207

Closed Firemanarg closed 3 years ago

Firemanarg commented 3 years ago

I'm trying to implement a platform where users can login directly with their Google Accounts, without the need of copy and paste a token.

There is an example on documentation, but apparently that's for an old version. It would help a lot if you could provide some usage examples (I don't have much knowledge about networking programming and databases , and your API helped me a lot).

Pd: This is my first GitHub request ever, so I'm not sure if this is the right place to request this xD

WolfgangSenff commented 3 years ago

This has been implemented as of: https://github.com/GodotNuts/GodotFirebase/pull/205 - Feel free to check that out. I'm going to close this issue, but there's some documentation in the PR to explain it.

fenix-hub commented 3 years ago

@Firemanarg Hi, To login directly with Google Accounts without copypaste, you just need to use this snippet (adapt it to your own needs)

func _ready():
    Firebase.Auth.connect("login_succeeded", self, "_on_login_succeeded")
    Firebase.Auth.get_google_auth_localhost()

func _on_login_succeeded(user : Dictionary):
    #use @user as you wish

When the get_google_auth_localhost() is called for the first time it will automatically open your browser to let you select an account. After confirmation, an error page will appear. That page is actually a success page, if everything went fine, and the user can just go back to the application since it will be authenticated.

To make this work, you need to do two things prior:

  1. Enable Google as a provider (Go to your Firebase Project > Authentication > Sign-in method > Enable Google)
  2. Create OAuth credentials from the Google Cloud platform for your Firebase Project, either Browser or Desktop credentials are ok. Once created, copy and paste your clientId and clientSecret in your project (inside the configuration file for our plugin).