Getting Started
复制一个设置提示,包含安装步骤和该插件的完整Markdown指南。
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.
您可以使用我们的AI辅助设置来安装插件。将Capgo技能添加到您的AI工具中,使用以下命令:
npx skills add https://github.com/Cap-go/capgo-skills --skill capacitor-plugins然后使用以下提示:
Use the `capacitor-plugins` skill from `Cap-go/capgo-skills` to install the `@capgo/capacitor-social-login` plugin in my project.如果您更喜欢手动设置,请运行以下命令安装插件并遵循以下平台特定的说明:
-
安装包
终端窗口 bun add @capgo/capacitor-social-login -
同步本地项目
终端窗口 bunx cap sync -
在应用启动时初始化
import { SocialLogin } from '@capgo/capacitor-social-login';await SocialLogin.initialize({google: {webClientId: 'your-google-web-client-id',iOSServerClientId: 'your-google-server-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 离线模式
Google 离线模式google.mode: 'offline' 返回 serverAuthCode 在此模式下,登出、isLoggedIn、getAuthorizationCode 和 refresh 不可用。
仅作为您的后端令牌交换的输入使用。如果您需要在应用中调用,请使用 serverAuthCode 而不是 SocialLogin.refresh() Apple google.mode: 'online' 仅作为您的后端令牌交换的输入使用。如果您需要在应用中调用,请使用
Set useProperTokenExchange: true 用于严格令牌处理和 useBroadcastChannel: true 用于 Android 简化设置。
OAuth2 网页重定向流
Section titled “OAuth2 网页重定向流”用于网页流程,页面导航 OAuth2LoginOptions.flow: 'redirect' Provider 在 __CAPGO_KEEP_0__ 配置
Section titled “Provider 在 Capacitor 配置”
Section titled “Provider configuration in Capacitor”复制到剪贴板
import type { CapacitorConfig } from '@capacitor/cli';
const config: CapacitorConfig = { appId: 'com.example.app', appName: 'My App', webDir: 'dist', plugins: { SocialLogin: { providers: { google: true, facebook: true, apple: true, twitter: false, }, }, },};相关文档
相关文档部分- 集成概述
- 改进的Auth集成
- OAuth2和OIDC提供者
- 从Ionic Auth Connect迁移
- Social Login Auth Connect迁移指南
- 迁移旧版提供者
- Ionic企业插件迁移解决方案
继续从Getting Started
继续从Getting Started部分如果您正在使用 开始使用 为了计划身份验证和帐户流程,连接它与 使用@capgo/capacitor-social-login 为native能力在使用@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中,以及 双因素身份验证 为实现细节在双因素身份验证中.