구글 인증 마이그레이션을 @capgo/social-login으로
이 설정 프롬프트를 복사하여 설치 단계와 이 플러그인의 전체 마크다운 가이드를 포함합니다.
이 가이드는 @codetrix-studio/capacitor-google-auth Live Update @capgo/capacitor-social-login이 새로운 플러그인은 여러 가지 사회적 인증 제공자를 단일, 일관된 API로 통합합니다.
설치
설치-
구성품 제거:
터미널 창 npm uninstall @codetrix-studio/capacitor-google-auth -
새로운 구성품 설치:
터미널 창 npm install @capgo/capacitor-social-loginnpx cap sync
구글 인증 설정의 중요한 변경 사항
구글 인증 설정의 중요한 변경 사항웹 클라이언트 ID 요구 사항
웹 클라이언트 ID 요구 사항중요한 변경 사항: 업데이트된 플러그인은 모든 플랫폼에서 Web Client ID를 사용해야 합니다.
필요한 것은:
- Google Cloud Console에서 Web Client ID를 만드는 것입니다. 만약 이미 하나가 있다면:인증서를 얻는 방법)
- 모든 플랫폼에서 이 Web Client ID를 사용하세요
webClientIdAndroid의 경우, SHA1과 함께 Android Client ID를 만드는 것이 필요합니다. 그러나 이 토큰은 사용되지 않습니다. - Android 설정 가이드__CAPGO_KEEP_0__ 변경 사항)
Code 변경 사항
Section titled “Code Changes”변경 사항을 가져오기
변경 사항 가져오기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() __CAPGO_KEEP_0__
const user = await GoogleAuth.signIn();const res = await SocialLogin.login({ provider: 'google', options: { scopes: ['email', 'profile'], forceRefreshToken: true // if you need refresh token }});플랫폼별 변경 사항
플랫폼별 변경 사항안드로이드
안드로이드 설정 가이드- 복사
MainActivity.java(iOS):
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() {}}AppDelegate.swift (
__CAPGO_KEEP_1__-
__CAPGO_KEEP_2__iOS 설정 가이드)
-
업데이트하여
capacitor.config.json, 새로운 플러그인에서 사용하지 않습니다:
{ "plugins": { "GoogleAuth": { "scopes": ["profile", "email"], "serverClientId": "xxxxxx-xxxxxxxxxxxxxxxxxx.apps.googleusercontent.com", "forceCodeForRefreshToken": true }}- 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: 이메일, 이름, 이미지 URL 포함한 사용자 프로필 정보
추가 기능
추가 기능새로운 패키지는 Google 이외의 여러 가지 사회 인증 제공 업체를 지원합니다:
이 통합 접근 방식은 다음과 같은 이점을 제공합니다:
- 모든 제공 업체에서 일관적인 API
- 향상된 TypeScript 지원
- 개선된 오류 처리
- 활발한 유지 관리 및 커뮤니티 지원
추가 제공 업체에 대한 자세한 설정 지침은 main documentation 에서 확인할 수 있습니다.
Google Auth Migration에서 계속 진행하여 @capgo/social-login
구글 인증 마이그레이션에서 @capgo/social-login으로 계속 진행하세요이미 사용 중인 경우 구글 인증 마이그레이션을 @capgo/social-login으로 사용하여 인증 및 계정 흐름을 계획하고 연결하려면 Using @capgo/capacitor-social-login을 사용하여 Using @capgo/capacitor-social-login의 네이티브 기능을 위해 Using @capgo/capacitor-social-login의 구현 세부 정보를 위해 Using @capgo/capacitor-passkey의 구현 세부 정보를 위해 Using @capgo/capacitor-passkey Using @capgo/capacitor-native-biometric의 구현 세부 정보를 위해 Using @capgo/capacitor-native-biometric Using @capgo/capacitor-native-biometric 두 단계 인증 두 단계 인증 구현 세부 사항에 대한 정보입니다.