Android 上的 Apple 登录
复制一个包含安装步骤和本插件的完整Markdown指南的设置提示。
, Sign in with Apple ,
,
- ,
- ,
,
,,
flowchart TD
A("await SocialLogin.login()") -->|Handled in the plugin|B(Generate the login URL)
B --> |Pass the link| C(Open the Chrome browser)
C --> D(Wait for the user to login)
D --> |Apple redirects to your backend|E(Handle the data returned from Apple)
E --> F(Redirect back to the app)
F --> G(Return to JS)
您已经了解了挑战和流程,现在让我们开始配置。
创建服务 ID
创建服务 ID-
登录到 苹果开发者门户.
-
点击
Identifiers.
您应该看到一个类似这样的屏幕:
- 确保这个字段显示
App IDs - 确保您可以找到您的 App ID。
- 确保这个字段显示
-
确保您的应用
Sign in with Apple能力已启用- 点击您的应用
- 确保您的应用
Sign in with Apple能力已启用
- 如果它没有启用,启用它。
- 点击您的应用
-
返回所有
All Identifiers
-
点击
App Ids并前往Services IDs
-
创建一个新标识符
-
点击加号按钮
-
选择
Servcice IDs并点击Continue
-
输入描述和标识符并点击
Continuie.
-
请确认详细信息并点击
Register
-
点击新创建的服务
-
启用
Sign in with Apple选项
-
配置
Sign In with Apple
-
确保设置为上一步中配置的 App ID
Primary App ID设置主 App ID 下拉菜单
-
设置域名和返回 URL 字段
-
确认数据并点击
Done
-
点击
Continue
-
点击
Save
-
创建密钥
标题:创建密钥-
返回所有
All Identifiers
-
点击
Keys
-
点击加号图标
-
命名您的密钥
-
选择
Sign in with Apple并点击Configure
-
选择主要 App ID,然后按
Save
-
点击
Continue
-
点击
Register
-
复制密钥 ID 并下载密钥。
-
找到下载的密钥并将其保存在后端文件夹中。
获取团队 ID
标题:获取团队 ID为了使用 Login with Apple 在 Android 上,您需要获取 Team ID。它将在后端使用。
-
前往 本网站 向下滚动
-
找到
Team ID
配置应用重定向
标题为“配置应用重定向”的部分如图所示,后端执行一个名为 Redirect back to the app的步骤。这需要对应用进行手动更改。
- 修改
AndroidManifest.xml-
打开文件,我将使用
AndroidStudio
-
找到
MainActivity并添加以下意图过滤器
<intent-filter><action android:name="android.intent.action.VIEW" /><category android:name="android.intent.category.DEFAULT" /><category android:name="android.intent.category.BROWSABLE" /><data android:scheme="capgo-demo-app" android:host="path" /></intent-filter>
-
- 修改
MainActivity-
请打开
MainActivity
-
添加以下 code:
@Overrideprotected void onNewIntent(Intent intent) {String action = intent.getAction();Uri data = intent.getData();if (Intent.ACTION_VIEW.equals(action) && data != null) {PluginHandle pluginHandle = getBridge().getPlugin("SocialLogin");if (pluginHandle == null) {Log.i("Apple Login Intent", "SocialLogin login handle is null");return;}Plugin plugin = pluginHandle.getInstance();if (!(plugin instanceof SocialLoginPlugin)) {Log.i("Apple Login Intent", "SocialLogin plugin instance is not SocialLoginPlugin");return;}((SocialLoginPlugin) plugin).handleAppleLoginIntent(intent);return;}super.onNewIntent(intent);}
-
后端配置
标题:后端配置Android 需要一个后端,但配置后端也会影响 IOS。提供了一个示例后端 在这里
本示例提供以下内容:
- 一个简单的 JSON 数据库
- 从 Apple 服务器请求 JWT 的方法
- 一个简单的 JWT 验证
protectedTokens env targetLanguage
ANDROID_SERVICE_ID= 服务 IDIOS_SERVICE_ID= 应用 ID
env: { PRIVATE_KEY_FILE: "AuthKey_U93M8LBQK3.p8", KEY_ID: "U93M8LBQK3", TEAM_ID: "UVTJ336J2D", ANDROID_SERVICE_ID: "ee.forgr.io.ionic.starter.service2", IOS_SERVICE_ID: "me.wcaleniewolny.test.ionic.vue", PORT: 3000, REDIRECT_URI: "https://xyz.wcaleniewolny.me/login/callback", BASE_REDIRECT_URL: "capgo-demo-app://path"}使用插件
标题:使用插件函数的使用方法与 IOS 一致,详见下文 login 然而, 方法有一些变化。复制到剪贴板 initialize 危险
await SocialLogin.initialize({ apple: { clientId: 'ee.forgr.io.ionic.starter.service2', redirectUrl: 'https://appleloginvps.wcaleniewolny.me/login/callback' }})创建应用
标题:创建应用-
如果您没有 App ID,请点击加号按钮
-
选择
App IDs点击继续
-
点击类型
App点击Continue
-
输入描述和 App ID
-
启用
Sign with Apple能力
-
点击
Continue
-
确认详细信息并点击
Register
从 Android 上的 Apple 登录继续
标题:从 Android 上的 Apple 登录继续如果您正在使用 在 Android 上使用 Apple 登录 来规划身份验证和帐户流程,连接它到 使用 @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 的实现细节, 和 双因素认证 对于双因素认证的实现细节。