dwyl / learn-flutter

πŸ¦‹ Learn how to use Flutter to Build Cross-platform Native Mobile Apps
https://flutter.dev
GNU General Public License v2.0
73 stars 8 forks source link

Feature: Log in with Google in Flutter App #4

Open nelsonic opened 4 years ago

nelsonic commented 4 years ago

The starting point for people using the @dwyl Native App is Login. We are using Sign in with Google for the Web App and people will expect it for the Native Mobile app.

image

Todo

Try and make the appearance as similar to the Web App as possible. (if you need any help with colors or logos, please leave comments below with your questions)

nelsonic commented 4 years ago

@miguelmartins17 the Medium post above uses Firebase Authentication. That's fine for testing to see how it works on a Flutter/Native app, however we want to avoid using Firebase Authentication because we aren't going to use Firebase for storing application data. (_Firebase stores data in US and we have no control over how it is stored. We want to use strong encryption for all personal data so the people using our App know their data is secure. see: https://github.com/dwyl/technology-stack/issues/16 ..._).

If you are able to use Firebase Authentication without storing any personal information on Firebase, then this could be an option. But if it is not possible to use Firebase without storing data on Firebase, then we may need to write some custom authentication code to ensure that personal data is only stored on the device and the session is created on the Phoenix Application server. We can work together to create the Phoenix endpoint.

Please write up the steps you have taken so far so that anyone else can follow along. Thanks!

miguelmartins17 commented 4 years ago

@nelsonic I think it's impossible to use the firebase without keeping personal information. I've been doing some research and it's one of the ways we can try to use the MySQL approach because it will only save what the user enters if it's the email and password. But that way I don't know how we're going to do about Google, because with MySQL you'll be saving Google's email.

nelsonic commented 4 years ago

@miguelmartins17 let's look at it together tomorrow morning. πŸ‘

miguelmartins17 commented 4 years ago

@nelsonic I think I found a solution. So you don't have to use firebase to login with google.

nelsonic commented 4 years ago

@miguelmartins17 cool. Please share links and as much details as you can here. πŸ‘

miguelmartins17 commented 4 years ago

I think I found the solution for how to login with google without using Firebase I leave here the link:

https://www.youtube.com/watch?v=8o-DJDi2bmQ

nelsonic commented 4 years ago

@miguelmartins17 looks promising. πŸ‘ @deep98shah created a good demo: https://github.com/deep98shah/PeopleAPIdemo πŸ” Keep sharing your progress. πŸ“

miguelmartins17 commented 4 years ago

Even without using Firebase one of the steps to login with Google is to register the application on the Google console which includes registering the application in Firebase.

deep98shah commented 4 years ago

@miguelmartins17 looks promising. @deep98shah created a good demo: https://github.com/deep98shah/PeopleAPIdemo Keep sharing your progress. Thanks for acknowledging.πŸ‘

miguelmartins17 commented 4 years ago

First we need to register the app so we have to enable the Google People API. Here is the link to enable: https://developers.google.com/people/

From my research I think we can do that from this link. Then we have to install google_Sign_In plugin.

It's done at pubspec.yaml just adding it to the dependencies: google_Sign_In: "3.0.4"

And then if we go through this link: https://developers.google.com/people/v1/getting-started

We were able to register our application.

So far it's the only way I've found that it can work and take us to the next stage.

nelsonic commented 4 years ago

@miguelmartins17 please take a look at the WebView SPIKE https://github.com/dwyl/learn-flutter/issues/5 Once you are able to display a basic web page in a Flutter WebView, we can explore the option of displaying the Elixir Google Auth https://elixir-auth-google-demo.herokuapp.com in a WebView and what implications that has.

SimonLab commented 4 years ago

Thanks for the research/links above :arrow_up: I'm having a look at how to do authentication with Google and then authorization request from a mobile application to a serve using a REST API.

I'm going to have a look first a the google signin package: https://pub.dev/packages/google_sign_in I think this should allow us to retrieve a Google token.

The next step is to find a way to create a unique token for each user, this should be done on the API server. Once this token is created we need to find a way to save it on the application.

Finally for each new API requests from the application we can use the Authorization header containing the token. The server will validate the request and allow or block the response: https://flutter.dev/docs/cookbook/networking/authenticated-requests

I've also find the following link: https://www.didierboelens.com/2018/05/token-based-communication-with-server---part-1/

Flutter with Python: https://www.youtube.com/watch?v=Nikdbz6gBek&list=PL5tVJtjoxKzrC1dRdj9AsRKcYO33pK76P&index=1

SimonLab commented 4 years ago

A quick schema, on how to signin with Google and using a backend API. The API should also allow signin with email/password, only the steps before creating the auth token will be different.

IMG_20200123_135608

SimonLab commented 4 years ago

The following issue: https://github.com/flutter/flutter/issues/36673 suggests that we can bypass Firebase by setting the configuration values directly into Google cloud platform.

I've created a new application, and added the sha-1 key however I still have an issue: image

It seems that the oauth consent screen fields need to be all set with a values which in my case are. I'm not sure if my Flutter application needs more setups to work :thinking:

I continue to investigate...

nelsonic commented 4 years ago

@SimonLab this still implies that we are forced to use GCP for our App. πŸ’­ Keep going with your research. We can figure out how to do this without GCP later. πŸ‘

SimonLab commented 4 years ago

I think GCP is used as the same way as Google Console Developer in this case. It is to create a new application and OAuth Credentials.

From the flutter issue above it looks like Firebase is used as a way to automatically create the application with all the required configuration for a Flutter app: image

SimonLab commented 4 years ago

This morning I have tried again to use the https://pub.dev/packages/google_sign_in package. I still have the error describe on the previous comment: https://github.com/dwyl/learn-flutter/issues/4#issuecomment-578122210 I've used Firebase to set up the application and indeed it creates automatically a new application on the google console developer and defined all the necessary fields in the oauth consent screen.

I'm going to try one last time to create a new application (without the Firebase setup) and I'll add the steps I've done in the following comment.

miguelmartins17 commented 4 years ago

@SimonLab Hello, this video can be used as a help/reference if you want to login with Google without using Firebase. πŸ’­

https://www.youtube.com/watch?v=8o-DJDi2bmQ&t=268s

SimonLab commented 4 years ago

I'm guessing the error is due to the sha-1 key not matching the google application, however as the debug error are not useful it is difficult to debug.

@miguelmartins17 have you tried/managed to use the google_singnin package on your machine?

miguelmartins17 commented 4 years ago

@SimonLab Yes, and I didn't get any error, so it will be difficult to identify what the solution will be. Besides because when I did it I was still using Windows and now I'm not.

miguelmartins17 commented 4 years ago

@SimonLab I'm going back to Windows (for a few minutes) because that's where I was able to run the application. I'm sure I used Google_Sign_in package and had no errors.

miguelmartins17 commented 4 years ago

@SimonLab Are you using Firebase? πŸ€” I f you're using this link, it might help.

https://github.com/flutter/flutter/issues/25640

SimonLab commented 4 years ago

Thanks for the links @miguelmartins17 which editor/IDE are you using, Android Studio? I'm currently working with VScode.

My goal while trying the google signin package is to determine how quickly it is to setup and how easy it is to use. At the moment there are two main blockers:

iteles commented 4 years ago

@SimonLab Have you opened any issues explaining this situation (we're trying to do something that should be relatively simple and not require firebase) on the flutter repo or stack overflow that we could upvote?