Platform
Sign Up With Google
10 min
sign in with google tutorial introduction sign in with google enables users to sign in to apps using their google accounts prerequisites to complete this tutorial, you will need an app created at back4app see the create new app tutorial to learn how to create an app at back4app set up a subdomain for your back4app app see activating your web hosting and live query to learn how to create an subdomain in back4app an google developer account 1 create a new 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 https //www back4app com/docs/get started/new parse app to learn how to create one 2 create a new client identifier log into your google developer account https //developers google com/ and go to google api console google api console click credentials credentials and choose oauth 2 0 client ids 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 configure consent screen , you will be redirected to the following page complete the screen consent configuration and hit save 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 authorized javascript origins , replace the url with your subdomain in authorized redirect uris authorized redirect uris , insert your subdomain followed by /redirect /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 3 retrieve your code visit the following url, changing the values for redirect uri redirect uri and client id 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 your code , client id client id , client secret client secret , and redirect uri redirect uri for the values of your application 1 curl x post \\ 2 https //oauth2 googleapis com/token \\ 3 f 'grant type=authorization code' \\ 4 f 'code=your code' \\ 5 f 'client id=client id' \\ 6 f 'client secret=client secret' \\ 7 f 'redirect uri=redirect uri' 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 google's user id it is a numeric string that you will pass along as the id id in step 4 to do so, run the following command replacing the your token your token string for the token you received in the previous command 1 curl x get https //www googleapis com/userinfo/v2/me?access token=your token 4 start the development now that the sign in with google is configured, you can start the development process the format for authdata is 1 { 2 "google" { 3 "id" "user's google id (string)", 4 "id token" "an authorized google id token for the user (use when not using access token)", 5 "access token" "an authorized google access token for the user (use when not using id token)" 6 } 7 } here is the method for the ios sdk 1 pfuser loginwithauthtype(inbackground "google", authdata \["access token"\ tokenstring, "id" user]) continuewith { task > any? in 2 3 } and here for the android sdk 1 map\<string, string> authdata = new hashmap\<string, string>(); 2 authdata put("access token", tokenstring); 3 authdata put("id", user); 4 parseuser loginwithinbackground("google", authdata){ 5 6 } remember, this must be done at every login for every user