내용으로 건너뛰기

Google 인증 마이그레이션을 @capgo/social-login으로

개요

개요

이 안내서에서는 @codetrix-studio/capacitor-google-auth 에서 @capgo/capacitor-social-login, ensuring a smooth transition and improved authentication experience. The new plugin unifies multiple social authentication providers under a single, consistent API.

이 새로운 플러그인은 여러 가지 소셜 인증 제공자를 단일하고 일관된 __CAPGO_KEEP_0__ 하에 통합합니다.

설치
  1. 구성 요소 제거:

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

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

__CAPGO_KEEP_0__

__CAPGO_KEEP_1__

__CAPGO_KEEP_2__

__CAPGO_KEEP_3__

__CAPGO_KEEP_4____CAPGO_KEEP_5__

Web Client ID를 사용해야 하는 이유

  1. __CAPGO_KEEP_6__Google Cloud Console에서 Web Client ID를 생성하세요. ()
  2. 인증 정보를 얻는 방법 webClientId 모든 플랫폼에서 이 Web Client ID를 사용하세요.
  3. Android의 경우, SHA1과 함께 Android Client ID를 생성해야 합니다. 하지만 이 토큰은 사용되지 않으며 (안드로이드 설정 가이드)

Code 변경 사항

Code 변경 사항 섹션

변경 사항 가져오기

변경 사항 가져오기 섹션
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.profile__CAPGO_KEEP_0__

사용자 프로필 정보

추가 기능

구글 이외의 여러 가지 소셜 인증 제공자도 지원합니다.

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

  • 모든 제공자에서 일관적인 API
  • 타입스크립트 지원이 향상되었습니다.
  • 오류 처리가 개선되었습니다.
  • 활발한 유지 보수 및 커뮤니티 지원

설정 지침을 확인하세요. 주요 문서 이 추가 제공자에 대한 자세한 설정 지침을 위한 문서를 확인하세요.