콘텐츠로 건너뛰기

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:

  1. Create a web client in the Google Console

    1. Click on the search bar

      Google Console search bar
    2. Search for credentials and click on the APIs and Services option (number 2 on the screenshot)

      Search results showing credentials option with APIs and Services highlighted
    3. Click on the create credentials

      Create credentials button in Google Console
    4. Select OAuth client ID

      OAuth client ID option in credentials creation menu
    5. Select the Application type as Web application

      Application type selection with Web option highlighted
    6. Name your client and click Create

      Web client creation form with name field highlighted
    7. Copy the client ID, you’ll use this as the webClientId in your application

      Client ID details showing Web client ID to copy
  2. Configure the web client in the Google Console

    1. Please open the credentials page and click on your web client

      Credentials list showing web client to click
    2. 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 both http://localhost and http://localhost:5173

      1. Please click on add URI

        Authorized JavaScript origins section with ADD URI button
      2. Please type your URL

        ADD URI dialog with localhost URL entered
      3. Please repeat until you added all the URLs

      4. When you finish, your screen should look something like this

        Authorized JavaScript origins with multiple localhost URLs added
    3. 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 on http://localhost:5173/auth

      1. Please click on ADD URI

        Authorized redirect URIs section with ADD URI button
      2. Enter your URL and click ADD URL again

        ADD URI dialog with redirect URL entered
    4. Click save

      Save button at bottom of web client configuration
  3. Now, you should be ready to call login from JavaScript like so:

    1. First, import SocialLogin

      import { SocialLogin } from '@capgo/capacitor-social-login';
    2. 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',
      }
      })
      })
    3. Create a login button that calls SocialLogin.login when clicked

      const res = await SocialLogin.login({
      provider: 'google',
      options: {}
      })
      // Handle the response
      console.log(JSON.stringify(res));