컨텐츠로 바로가기

Google 인증을 @capgo/social-login으로 이동

설정 개요

개요

이 가이드는 Capgo에서 Capacitor로의 전환을 위한 완전한 단계를 제공합니다. @codetrix-studio/capacitor-google-auth 으로 @capgo/capacitor-social-login, 사용자 경험을 개선하고 smooth한 전환을 보장하기 위해 새로운 플러그인은 여러 소셜 인증 제공자를 단일, 일관된 API로 통합합니다.

설치

설치
  1. __CAPGO_KEEP_0__를 제거하세요:

    터미널 창
    npm uninstall @codetrix-studio/capacitor-google-auth
  2. 새로운 패키지를 설치하세요:

    터미널 창
    npm install @capgo/capacitor-social-login
    npx cap sync

Google 인증 설정에서 중요한 변경 사항

Google 인증 설정에서 중요한 변경 사항

웹 클라이언트 ID 요구 사항

웹 클라이언트 ID 요구 사항

중요한 변경 사항: 업데이트된 플러그인은 모든 플랫폼에서 웹 클라이언트 ID를 사용해야 합니다.

필요한 항목

  1. Google Cloud Console에서 웹 클라이언트 ID를 만드는 방법인증 정보를 얻는 방법)
  2. 이 웹 클라이언트 ID를 모든 플랫폼에서 사용하세요 webClientId Android의 경우, SHA1과 함께 Android 클라이언트 ID를 만드는 것이 필요하지만, 이 토큰은 사용되지 않습니다 (
  3. 사용되지 않습니다안드로이드 설정 가이드)

변경 사항 가져오기

변경 사항 가져오기 제목
import { GoogleAuth } from '@codetrix-studio/capacitor-google-auth';
import { SocialLogin } from '@capgo/capacitor-social-login';

구글 구성이 중첩된 GoogleAuth.initialize() 구글 구성이 중첩된 구조화된 호출로 변환됩니다: SocialLogin.initialize() 클립보드 복사

GoogleAuth.initialize({
clientId: 'CLIENT_ID.apps.googleusercontent.com',
scopes: ['profile', 'email'],
grantOfflineAccess: true,
});
await SocialLogin.initialize({
google: {
webClientId: 'WEB_CLIENT_ID.apps.googleusercontent.com', // Use Web Client ID for all platforms
iOSClientId: 'IOS_CLIENT_ID', // for iOS
mode: 'offline' // replaces grantOfflineAccess
}
});

로그인 방법이 GoogleAuth.signIn() 으로 SocialLogin.login() 특정 제공자 지정과 함께

const user = await GoogleAuth.signIn();
const res = await SocialLogin.login({
provider: 'google',
options: {
scopes: ['email', 'profile'],
forceRefreshToken: true // if you need refresh token
}
});

플랫폼별 변경 사항

플랫폼별 변경 사항 섹션

안드로이드

안드로이드 섹션
  1. 업데이트하여 MainActivity.java (안드로이드 전체 설정 가이드):
import ee.forgr.capacitor.social.login.GoogleProvider;
import ee.forgr.capacitor.social.login.SocialLoginPlugin;
import ee.forgr.capacitor.social.login.ModifiedMainActivityForSocialLoginPlugin;
import com.getcapacitor.PluginHandle;
import com.getcapacitor.Plugin;
import android.content.Intent;
import android.util.Log;
public class MainActivity extends BridgeActivity {
public class MainActivity extends BridgeActivity implements ModifiedMainActivityForSocialLoginPlugin {
@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
if (requestCode >= GoogleProvider.REQUEST_AUTHORIZE_GOOGLE_MIN && requestCode < GoogleProvider.REQUEST_AUTHORIZE_GOOGLE_MAX) {
PluginHandle pluginHandle = getBridge().getPlugin("SocialLogin");
if (pluginHandle == null) {
Log.i("Google Activity Result", "SocialLogin login handle is null");
return;
}
Plugin plugin = pluginHandle.getInstance();
if (!(plugin instanceof SocialLoginPlugin)) {
Log.i("Google Activity Result", "SocialLogin plugin instance is not SocialLoginPlugin");
return;
}
((SocialLoginPlugin) plugin).handleGoogleLoginIntent(requestCode, data);
}
}
public void IHaveModifiedTheMainActivityForTheUseWithSocialLoginPlugin() {}
}
  1. AppDelegate.swift (에서 큰 변화가 필요하지 않습니다.iOS 설정 가이드)

  2. 설정을 capacitor.config.json새로운 플러그인에서 사용하지 않습니다.

{
"plugins": {
"GoogleAuth": {
"scopes": ["profile", "email"],
"serverClientId": "xxxxxx-xxxxxxxxxxxxxxxxxx.apps.googleusercontent.com",
"forceCodeForRefreshToken": true
}
}
  1. Google Sign-In 메타 태그를 제거하십시오. index.html 사용하고 있으면 제거하십시오.
<meta name="google-signin-client_id" content="{your client id here}" />
<meta name="google-signin-scope" content="profile email" />

응답 형식 변경

응답 형식 변경

인증 응답은 구조화된 객체를 제공하여 제공자 정보, 액세스 토큰, ID 토큰 및 사용자 프로필 데이터를 포함합니다.

interface GoogleLoginResponse {
provider: 'google';
result: {
accessToken: {
token: string;
expires: string;
// ... other token fields
} | null;
idToken: string | null;
profile: {
email: string | null;
familyName: string | null;
givenName: string | null;
id: string | null;
name: string | null;
imageUrl: string | null;
};
};
}

응답 구조는 다음과 같습니다.

  • provider: 인증 제공자 ('google')
  • result.accessToken: 만료일을 포함한 액세스 토큰 정보
  • result.idToken: 인증을 위한 ID 토큰
  • result.프로필: 사용자 프로필 정보, 이메일, 이름, 이미지 URL 포함

새 패키지는 Google 이외의 여러 가지 사회 인증 제공자도 지원합니다.

이 통합 접근 방식은 다음과 같은 이점을 제공합니다.

  • 모든 제공자에서 일관적인 API
  • 향상된 타입스크립트 지원
  • 개선된 오류 처리
  • 활성 유지 관리 및 커뮤니티 지원

체크하는 메인 문서 이 추가 제공자에 대한 자세한 설정 지침을 확인하세요.