본문 바로가기

Google Auth의 @capgo/social-login 마이그레이션

GitHub

이 가이드는 마이그레이션을 위한 포괄적인 단계를 제공합니다. @codetrix-studio/capacitor-google-auth 대상 @capgo/capacitor-social-login이를 통해 원활한 전환과 개선된 인증 경험을 보장할 수 있습니다. 새 플러그인은 여러 소셜 인증 제공업체를 하나의 일관된 API로 통합합니다.

  1. 기존 패키지를 제거하세요:

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

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

Google Auth 설정의 주요 변경 사항

“Google Auth 설정의 주요 변경 사항” 섹션

Web Client ID 필수 사항

“Web Client ID 요구 사항” 섹션

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

다음 작업을 수행해야 합니다:

  1. Web Client ID가 없으면 Google Cloud Console에서 생성하세요 (자격 증명을 가져오는 방법)
  2. 이 Web Client ID를 webClientId 모든 플랫폼에서 이 필드에 사용하세요
  3. Android에서는 SHA1로 Android Client ID를 여전히 생성해야 하지만, 이는 검증용일 뿐이며 해당 토큰은 사용되지 않습니다 (Android 설정 가이드)
import { GoogleAuth } from '@codetrix-studio/capacitor-google-auth';
import { SocialLogin } from '@capgo/capacitor-social-login';

설정 방식이 단순한 형태에서 GoogleAuth.initialize() 더 구조화된 SocialLogin.initialize() 중첩된 Google 구성으로:

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() 명시적인 provider 지정으로:

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 (Android 전체 설정 가이드):
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 meta 태그를 제거하세요 index.html 기존에 사용 중이었다면:
<meta name="google-signin-client_id" content="{your client id here}" />
<meta name="google-signin-scope" content="profile email" />

Response Type 변경 사항

“Response Type Changes” 섹션

이제 인증 응답은 provider 정보, access token, ID token, 사용자 프로필 데이터를 담은 구조화된 객체를 제공합니다:

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.profile: 이메일, 이름, 이미지 URL을 포함한 사용자 프로필 정보

새 패키지는 Google 외에도 다양한 소셜 인증 제공업체를 지원합니다:

이 통합 방식은 다음을 제공합니다:

  • 모든 제공업체에서 일관된 API
  • 개선된 TypeScript 지원
  • 더 나은 에러 처리
  • 적극적인 유지보수 및 커뮤니티 지원

앱 통합의 주요 문서 추가 제공자에 대한 상세 설정 안내를 참고하세요.

Google Auth Migration에서 @capgo/social-login로 계속 진행

“Google Auth 마이그레이션에서 @capgo/social-login로 계속하기” 섹션

사용 중이라면 Google Auth의 @capgo/social-login 마이그레이션 인증 및 계정 흐름을 설계할 때, 이를 다음 항목과 연결하세요: @capgo/capacitor-social-login 사용하기 @capgo/capacitor-social-login 사용 시 네이티브 기능을 위해, @capgo/capacitor-social-login @capgo/capacitor-social-login의 구현 세부 사항은, @capgo/capacitor-passkey @capgo/capacitor-passkey의 구현 세부 사항은 @capgo/capacitor-native-biometric @capgo/capacitor-native-biometric의 구현 세부 사항은, 2단계 인증 2단계 인증의 구현 세부 사항에 대해서는