시작하기
설치
Set up this Capacitor plugin in the project.
Use the package manager already used by the project.
Install these package(s): `@capgo/capacitor-social-login`
Run the required Capacitor sync/update step after installation.
Read this markdown guide for the full setup steps: https://raw.githubusercontent.com/Cap-go/website/refs/heads/main/apps/docs/src/content/docs/docs/plugins/social-login/getting-started.mdx
Use that guide for platform-specific steps, native file edits, permissions, config changes, imports, and usage setup.
If that guide references other docs pages, read them too.
설치
설치Capgo의 AI-Assisted Setup을 사용하여 플러그인을 설치할 수 있습니다. AI 도구에 Capgo 기능을 추가하려면 다음 명령어를 사용하세요:
npx skills add https://github.com/cap-go/capacitor-skills --skill capacitor-plugins다음 명령어를 사용하여 플러그인을 설치하고 아래의 플랫폼별 지침을 따르세요:
Use the `capacitor-plugins` skill from `cap-go/capacitor-skills` to install the `@capgo/capacitor-social-login` plugin in my project.패키지를 설치하려면 다음 명령어를 실행하세요:
-
설치
터미널 창 npm install @capgo/capacitor-social-login -
자연 프로젝트와 동기화
터미널 창 npx cap sync -
앱 시작 시 초기화
import { SocialLogin } from '@capgo/capacitor-social-login';await SocialLogin.initialize({google: {webClientId: 'your-google-web-client-id',iOSClientId: 'your-google-ios-client-id',iOSServerClientId: 'your-google-web-client-id',mode: 'online',},apple: {clientId: 'your-apple-service-id',useProperTokenExchange: true,useBroadcastChannel: true,},facebook: {appId: 'your-facebook-app-id',},twitter: {clientId: 'your-twitter-client-id',redirectUrl: 'myapp://oauth/twitter',},oauth2: {github: {appId: 'your-github-client-id',authorizationBaseUrl: 'https://github.com/login/oauth/authorize',accessTokenEndpoint: 'https://github.com/login/oauth/access_token',redirectUrl: 'myapp://oauth/github',scope: 'read:user user:email',pkceEnabled: true,},},});
코어 플로우 예제
코어 플로우 예제 섹션await SocialLogin.login({ provider: 'google', options: { scopes: ['profile', 'email'] },});
await SocialLogin.login({ provider: 'oauth2', options: { providerId: 'github', scope: 'read:user user:email', },});세션 확인
세션 확인 섹션const status = await SocialLogin.isLoggedIn({ provider: 'google' });await SocialLogin.logout({ provider: 'google' });인증 코드 및 리프레시
인증 코드 및 리프레시 섹션// For providers that support this modeconst authCodeResult = await SocialLogin.getAuthorizationCode({ provider: 'google' });await SocialLogin.refresh({ provider: 'google', options: {} as never });고급 헬퍼
고급 헬퍼 섹션const jwt = await SocialLogin.decodeIdToken({ idToken: 'eyJhbGciOi...',});
const { date } = await SocialLogin.getAccessTokenExpirationDate({ accessTokenExpirationDate: Date.now() + 3600 * 1000,});
const expired = await SocialLogin.isAccessTokenExpired({ accessTokenExpirationDate: Date.now() + 1000,});
const active = await SocialLogin.isRefreshTokenAvailable({ refreshToken: 'a-token' });제공자별 참고사항
제공자별 참고사항 섹션구글 오프라인 모드
구글 오프라인 모드google.mode: 'offline' 리턴 serverAuthCode 로그인에서
이 모드에서는 로그아웃, isLoggedIn, getAuthorizationCode, 및 refresh가 사용할 수 없습니다. serverAuthCode 사용 SocialLogin.refresh() 백엔드 토큰 교환에만 입력으로 사용하세요. 앱에서 호출해야 하는 경우 google.mode: 'online' 대신 사용하세요.
strict 토큰 처리를 위해 설정하고 useProperTokenExchange: true Android에서 단순한 설정을 위해 설정하세요. useBroadcastChannel: true strict
OAuth2 웹 리다이렉트 흐름
OAuth2 웹 리다이렉트 흐름 섹션사용 OAuth2LoginOptions.flow: 'redirect' 페이지에서 벗어나서 이동하는 웹 흐름을 위한 것입니다.
동적 제공자 의존성
섹션 제목 “동적 제공자 의존성”특정 제공자를 포함하여 네이티브 앱 크기를 줄이려면 제공자를 구성할 수 있습니다. 앱이 특정 제공자만 필요할 때 가장 유용합니다.
제공자 구성 추가하기 capacitor.config.ts:
import type { CapacitorConfig } from '@capacitor/cli';
const config: CapacitorConfig = { appId: 'com.example.app', appName: 'MyApp', webDir: 'dist', plugins: { SocialLogin: { providers: { google: true, facebook: true, apple: true, twitter: false, }, logLevel: 1, }, },};
export default config;제공자 값은 다음과 같습니다:
true: 제공자가 활성화되어 있고 네이티브 의존성이 패키징됩니다.false: 제공자가 비활성화되어 있고 네이티브 의존성이 패키징되지 않습니다.
중요한 정보:
- 실행
npx cap sync제공자 구성이 변경된 후에 - 제공자 구성이 제공되지 않으면, 모든 제공자는
true과 같은 이전 호환성을 위해 기본값이 됩니다. - 제공자 중 하나를 비활성화하면
false런타임 시에도 제공자가 사용되지 않습니다. 제공자가 시스템 API만 사용하는 경우에도. - 이 구성은 iOS와 Android에만 영향을 미칩니다. Web에는 영향을 미치지 않습니다.
- Apple Sign-In on Android uses OAuth without external SDK dependencies.
- Twitter/X uses standard OAuth 2.0 without external SDK dependencies.
Twitter/X는 표준 OAuth 2.0을 사용하며 외부
plugins: { SocialLogin: { providers: { google: true, facebook: false, apple: true, twitter: false, }, },}관련 문서
관련 문서 섹션- 인터그레이션 개요
- Capgo Better Auth 통합
- OAuth2 및 OIDC 제공자
- 문제 해결
- 개인 정보 선언 및 iOS URL 핸들러
- Ionic Auth Connect에서 마이그레이션
- Capgo Social Login Auth Connect 마이그레이션 가이드
- 기존 제공자 마이그레이션
- Ionic Enterprise 플러그인 마이그레이션 솔루션
Getting Started에서 계속
시작하기에서 계속하기이러한 기능을 사용 중이라면 시작하기 인증 및 계정 흐름을 계획하고 연결하려면 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 for the implementation detail in @capgo/capacitor-native-biometric, and 두 단계 인증 두 단계 인증 구현 세부 사항에 대한 정보입니다.