Sign Up With Google
Sign In with Google enables users to sign in to Apps using their Google accounts.
To complete this tutorial, you will need:
- An app created at Back4App
- Set up a Subdomain for your Back4app app
First of all, it’s necessary to make sure that you have an existing app created at Back4App. However, if you are a new user, you can check this tutorial to learn how to create one.
Log into your Google Developer account and go to Google API Console. Click Credentials and choose OAuth 2.0 Client IDs
If you do not have a Consent Screen, Google will ask you to create one. Click on Configure consent Screen, you will be redirected to the following page:
Complete the screen consent configuration and hit Save
Pick the platform you will need. For this example, I am using Javascript (Web Application), but you should pick the one you will be using.
In Authorized JavaScript Origins, replace the URL with your subdomain. In Authorized redirect URIs, insert your subdomain followed by /redirect. As shown in the image below:
Note: If you do not have your subdomain enabled yet, please check the following guide to know how can you do this: Create your Subdomain
After that you should have your Client ID and Secret:
Visit the following URL, changing the values for REDIRECT_URI and CLIENT_ID for the ones you created:
The scopes necessary to retrieve the auth_token and later on the user_id are:
https://www.googleapis.com/auth/userinfo.email https://www.googleapis.com/auth/plus.me https://www.googleapis.com/auth/userinfo.profile
Log in with your Google account and the redirected website will have your code in the URL:
Copy the Code part of the URL only and run the following CURL command replacing the values YOUR_CODE, CLIENT_ID, CLIENT_SECRET, and REDIRECT_URI for the values of your application
Run it and you should retrieve your access token:
REMEMBER: the code can be used only once. If you get an error or don’t use your token, you must re-generate your Code to be able to run it again.
Now it is time to retrieve your Google's User ID. It is a numeric string that you will pass along as the id in step 4. To do so, run the following command replacing the YOUR TOKEN string for the token you received in the previous command.
Now that the sign-in with Google is configured, you can start the development process. The format for AUTHDATA is:
Here is the method for the iOS SDK:
And here for the Android SDK:
Remember, this must be done at every login for every user.