Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Firebase Authenticate using Facebook, Twitter, Google, etc #36

Open
SergioDragon opened this issue Mar 5, 2020 · 28 comments
Open

Firebase Authenticate using Facebook, Twitter, Google, etc #36

SergioDragon opened this issue Mar 5, 2020 · 28 comments
Labels
ideas Ideas for future extensions

Comments

@SergioDragon
Copy link

Hello,
Are you planning to add to FB4D support of Firebase Authenticate using Facebook, Twitter, Google, and other methods offered by Firebase?

@SchneiderInfosystems SchneiderInfosystems added the ideas Ideas for future extensions label Mar 5, 2020
@SchneiderInfosystems
Copy link
Owner

SchneiderInfosystems commented Mar 5, 2020

Hi,
This would be a nice extension and should not be very complicated. Unfortunately, I will currently not find the time to do this implementation. If you can implement this in function by yourself according to https://firebase.google.com/docs/reference/rest/auth#section-sign-in-with-oauth-credential please send me a pull request and will carefully review your code.

@SergioDragon
Copy link
Author

I'm a beginner in Firebase and FB4D. Maybe only after some time learning both, I can do something :)
But maybe have here other pros for whom it will be easy.

@SergioDragon
Copy link
Author

I checked the sources of FB4D and Firebase Authentication manuals.
My knowledge is not enough to expand FB4D with Facebook/Twitter/Google/Apple/etc authentication. It looks too complicated for me, unfortunately.
If someone else can implement, would be cool!

PS/ I took FB4D for use at my android app. Hopefully, in few days first results.

@SchneiderInfosystems
Copy link
Owner

I keep this change request on the wish list but it has no priority. Thank you for understanding.

@SchneiderInfosystems
Copy link
Owner

I have implemented yet the required interface IFirebaseAuthentication.SignInWithOAuthCredentials and in IFirebaseUse the getter methods OAuthProviderId, OAuthFederatedId, OAuthIdToken, OAuthAccessToken, OAuthTokenSecret, and OAuthRawUserInfo.

@SergioDragon: Can you test now this function?

@kazuser
Copy link

kazuser commented Mar 26, 2021

Hello,
Are you planning to add to FB4D support of Firebase Authenticate using Facebook, Twitter, Google, and other methods offered by Firebase?

Did you try this one: https://github.com/grijjy/DelphiGoogleSignIn ?

@VanarGames
Copy link

VanarGames commented Apr 12, 2021

https://github.com/grijjy/DelphiGoogleSignIn is a good solution,
BUT ads-modules are disabled in it (advertising does not work), which is very critical for me!
Do you happen to have a similar solution, but with ad support? :)
SchneiderInfosystems, please give priority to the implementation of Google-authentication in FB4D!!!

@SchneiderInfosystems
Copy link
Owner

SchneiderInfosystems commented Apr 13, 2021

The DelphiGoogleSignIn is just a wrapper over the Firebase SDK running on Android Devices. With FB4D, I'm taking a different approach: a true cross-platform library for Firemonkey and VCL.
IMHO, I have already developed the required interface for supporting Google Account sign-in over SignInWithOAuthCredentials, My intention is to bring an example that demonstrate this sign-in method. Unfortunately, there is still some other higher prioritized task to do in FB4D.

@VanarGames: If you have a commercial project and/or want to discuss ways of collaboration, feel free to contact me by mail at webmaster @ Schneider - Infosys . ch.

@kazuser
Copy link

kazuser commented Apr 16, 2021

https://github.com/grijjy/DelphiGoogleSignIn is a good solution,
BUT ads-modules are disabled in it (advertising does not work), which is very critical for me!

@VanarGames I.e. I can't use TBannerAD with DelphiGoogleSignIn? o_O

@VanarGames
Copy link

VanarGames commented Apr 16, 2021

https://github.com/grijjy/DelphiGoogleSignIn - хорошее решение,
НО в нем отключены ads-модули (реклама не работает), что для меня очень критично!

@VanarGames Т.е. я не могу использовать TBannerAD с DelphiGoogleSignIn? о_О

Quite right!
Or DelphiGoogleSignIn or TBanner :)

@kazuser
Copy link

kazuser commented Apr 16, 2021

https://github.com/grijjy/DelphiGoogleSignIn - хорошее решение,
НО в нем отключены ads-модули (реклама не работает), что для меня очень критично!

@VanarGames Т.е. я не могу использовать TBannerAD с DelphiGoogleSignIn? о_О

Quite right!
Or DelphiGoogleSignIn or TBanner :)

But how can this be related? 🤔
And how did you know about it? 🤨

@VanarGames
Copy link

But how can this be related? 🤔
And how did you know about it? 🤨

But how can this be related?
Theoretically, there is no connection - it's just that the SDK libraries are very changed in the project and there are no ads-moduls
And how did you know about it?
I tested

@kazuser
Copy link

kazuser commented Apr 17, 2021

I have implemented yet the required interface IFirebaseAuthentication.SignInWithOAuthCredentials and in IFirebaseUse the getter methods OAuthProviderId, OAuthFederatedId, OAuthIdToken, OAuthAccessToken, OAuthTokenSecret, and OAuthRawUserInfo.

@SchneiderInfosystems, could you please explain where I can get data for fields
OAuthTokenName, OAuthToken, ProviderID, RequestUri

Can't find it on my console.cloud.google.com 😕

😕

@kazuser
Copy link

kazuser commented Apr 17, 2021

BTW: do I need to publish app before use SignInWithOAuthCredentials?
Untitled

@SchneiderInfosystems
Copy link
Owner

SchneiderInfosystems commented Apr 17, 2021

Unfortunately, I did not find time to write an example yet. That is why I do not know all answers yet.

The ProviderID for Google is 'google.com'.

As I understand, you have firstly to sign in to the google account. From this, I would expect, that you get the OAuthToken. The OAuthTokenName is probably GOOGLE_ID_TOKEN.

Here you find additional information from the Firebase Rest API:
https://firebase.google.com/docs/reference/rest/auth#section-sign-in-with-oauth-credential

@kazuser
Copy link

kazuser commented Apr 17, 2021

Unfortunately, I did not find time to write an example yet. That is why I do not know all answers yet.

The ProviderID for Google is 'google.com'.

As I understand, you have firstly to sign in to the google account. From this, I would expect, that you get the OAuthToken. The OAuthTokenName is probably GOOGLE_ID_TOKEN.

Here you find additional information from the Firebase Rest API:
https://firebase.google.com/docs/reference/rest/auth#section-sign-in-with-oauth-credential

Thanks for info! Clearing up a bit now.

But still an error comes out:
Untitled

@kazuser
Copy link

kazuser commented Apr 17, 2021

Unfortunately, I did not find time to write an example yet. That is why I do not know all answers yet.

The ProviderID for Google is 'google.com'.

As I understand, you have firstly to sign in to the google account. From this, I would expect, that you get the OAuthToken. The OAuthTokenName is probably GOOGLE_ID_TOKEN.

Here you find additional information from the Firebase Rest API:
https://firebase.google.com/docs/reference/rest/auth#section-sign-in-with-oauth-credential

Hm...

Is string (generated by FB4D) fully and correctly completed?

String from FB4D:

Sign in with OAuth for google.com failed: INVALID_CREDENTIAL_OR_PROVIDER_ID : Invalid IdP response/credential: http://localhost?eyJh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ap18aZkipiNTv6Fl5mTzwv3foJ-qu8ciZqEtzjjKh2MzM4-4u6kyZgnp0MvXMhWdM7G250AbsXBu-u1u9tGOY_F9jJhToRnL09PwXvzX&providerId=google.com

... string from your link:

curl 'https://identitytoolkit.googleapis.com/v1/accounts:signInWithIdp?key=[API_KEY]' \
-H 'Content-Type: application/json' \
--data-binary '{"postBody":"id_token=[GOOGLE_ID_TOKEN]&providerId=[google.com]","requestUri":"[http://localhost]","returnIdpCredential":true,"returnSecureToken":true}'

@SchneiderInfosystems
Copy link
Owner

SchneiderInfosystems commented Apr 17, 2021

Oh, it seems, that I have mixed up the parameters. The parameters should be packed into a JSON object in the body and not in the URL. Only the API_Key should remain in the URL.
I hope, I get time next week to fix this point.

Are you able to share your project with me so I can move faster?

@kazuser
Copy link

kazuser commented Apr 18, 2021

Oh, it seems, that I have mixed up the parameters. The parameters should be packed into a JSON object in the body and not in the URL. Only the API_Key should remain in the URL.
I hope, I get time next week to fix this point.

Are you able to share your project with me so I can move faster?

Sorry, I'm afraid it's impossible — the SignInWithGoogle function requires signing with a cert from the closed keystore, so you need create your own test-Android-project in https://play.google.com/console and https://console.firebase.google.com

@kazuser
Copy link

kazuser commented Apr 18, 2021

So, I did it. Finally 😎

  1. @SchneiderInfosystems, please do not change anything in SignInWithOAuthCredentials! You did everything right, there were mistakes on my side!

Untitled

  1. The working version looks like this:
  fAuth := TFirebaseAuthentication.Create('Web_API_Key');
  fAuth.LinkOrSignInWithOAuthCredentials('id_token', 'a_very_very_long_string_from_screenshot_below', 'google.com', 'http://localhost', OnUserResponse, OnUserError);

Untitled

@SchneiderInfosystems
Copy link
Owner

@kazuser : Great news, congrats on this first success!

My goal is to provide an understandable tutorial for a small test project that will be runnable not only on Android but on all platforms.

I tried today to build the GoogleSignIn for my Android mobil. But I was missing Grijjy.Bson in Googke.Api. Can you help me?

@kazuser
Copy link

kazuser commented Apr 18, 2021

@kazuser : Great news, congrats on this first success!

My goal is to provide an understandable tutorial for a small test project that will be runnable not only on Android but on all platforms.

Thanks!

I tried today to build the GoogleSignIn for my Android mobil. But I was missing Grijjy.Bson in Googke.Api. Can you help me?

Of cource!

Manual: https://blog.grijjy.com/2017/07/20/using-google-sign-in-for-firebase-sdk-on-android

Library: https://github.com/grijjy/GrijjyFoundation

@SchneiderInfosystems
Copy link
Owner

You have mixed the code from here
https://github.com/grijjy/GrijjyFoundation
and here:
https://github.com/grijjy/DelphiGoogleSignIn?

@kazuser
Copy link

kazuser commented Apr 18, 2021

You have mixed the code from here
https://github.com/grijjy/GrijjyFoundation
and here:
https://github.com/grijjy/DelphiGoogleSignIn?

изображение

@SchneiderInfosystems
Copy link
Owner

SchneiderInfosystems commented Apr 19, 2021

Ok, one step ahead. Now I got this error when deploying on my device:

[PAClient Error] Error: E2312 C:\Users\Christoph\Documents\Experimental\DelphiGoogleSignIn\Example.Firemonkey\Android64\Debug\GoogleSignIn\AndroidManifest.xml:33: error: Error: No resource found that matches the given name (at 'value' with value '@integer/google_play_services_version').

I believe that is related to the chapter Getting Started Quick Steps.
Especially step 2 is unclear to me. Do I need really to add these 120 files manually to my android deployment file list? File by file manually? I don't hope so! And how I have to add the jar libraries exactly? Can you show me your screen dump to the deployment list?

I made more researches in the meantime. What do you think kazuser? Cloud that brings the solution:
https://stackoverflow.com/questions/34271698/delphi-google-oauth2-token-request-using-indy-http-get-400-bad-request
If yes, I will immediately stop by trying GoogleSignIn and begin to implement this request by using THTTPClient ;)

@kazuser
Copy link

kazuser commented Apr 19, 2021

[PAClient Error] Error: E2312 C:\Users\Christoph\Documents\Experimental\DelphiGoogleSignIn\Example.Firemonkey\Android64\Debug\GoogleSignIn\AndroidManifest.xml:33: error: Error: No resource found that matches the given name (at 'value' with value '@integer/google_play_services_version').

Don't know what is it but you can try to delete "AndroidManifest.template.xml".

Especially step 2 is unclear to me. Do I need really to add these 120 files manually to my android deployment file list?

No. Please check email.

I will immediately stop by trying GoogleSignIn and begin to implement this request by using THTTPClient ;)

I think a built-in solution will be the best for sure! https://github.com/grijjy/DelphiGoogleSignIn was just for testing :)

@SchneiderInfosystems
Copy link
Owner

SchneiderInfosystems commented Apr 20, 2021

I was able to successfully implement the second part by taken the auth code from the android app GoogleSignIn:

image

Unfortunately, I have no idea how to implement the first request,

@kazuser: Pls check your mailbox but this state is newer than the mail I sent.

@kazuser
Copy link

kazuser commented Apr 21, 2021

I was able to successfully implement the second part by taken the auth code from the android app GoogleSignIn:

Well done! 👍

I have no idea how to implement the first request

What is "the first request"? I think we need to sync somehow 😅

How I see it:

  1. The very first step is "Sign In":
    15

  2. Next step is "Grant Refresh Token":
    15+

  3. Final step (before use SignInWithOAuthCredentials) is "Grant OAuth/2 Token":
    15++

So you have 2 & 3 steps now, am I right? :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
ideas Ideas for future extensions
Projects
None yet
Development

No branches or pull requests

4 participants