Google Login on Web
이 콘텐츠는 아직 귀하의 언어로 제공되지 않습니다.
Introduction
In this guide, you will learn how to setup Google Login with Capgo Social Login for web applications. I assume that you have already read the general setup guide.
Using Google login on the web
Using the google login on the web is rather simple. In order to use it, you have to do the following:
-
Create a web client in the Google Console
-
Click on the search bar
-
Search for
credentials
and click on theAPIs and Services
option (number 2 on the screenshot) -
Click on the
create credentials
-
Select
OAuth client ID
-
Select the
Application type
asWeb application
-
Name your client and click
Create
-
Copy the client ID, you’ll use this as the
webClientId
in your application
-
-
Configure the web client in the Google Console
-
Please open the credentials page and click on your web client
-
Now, please add the
Authorized JavaScript origins
. This should include all the addresses that you might use for your app. In might case, I will ONLY use localhost, but since I use a custom port I have to add bothhttp://localhost
andhttp://localhost:5173
-
Please click on
add URI
-
Please type your URL
-
Please repeat until you added all the URLs
-
When you finish, your screen should look something like this
-
-
Now, please add some
Authorized redirect URIs
. This will depend on what page do you depend to use the CapacitorSocialLogin plugin on. In my case, I am going to be using it onhttp://localhost:5173/auth
-
Please click on
ADD URI
-
Enter your URL and click
ADD URL
again
-
-
Click
save
-
-
Now, you should be ready to call
login
from JavaScript like so:-
First, import
SocialLogin
import { SocialLogin } from '@capgo/capacitor-social-login'; -
Then, call initialize. This should be called ONLY once.
// onMounted is Vue specific// webClientId is the client ID you got in the web client creation step not the android client ID.onMounted(() => {SocialLogin.initialize({google: {webClientId: '673324426943-avl4v9ubdas7a0u7igf7in03pdj1dkmg.apps.googleusercontent.com',}})}) -
Create a login button that calls
SocialLogin.login
when clickedconst res = await SocialLogin.login({provider: 'google',options: {}})// Handle the responseconsole.log(JSON.stringify(res));
-