Android 上的 Apple 登录
复制一个包含安装步骤和本插件的完整 Markdown 指南的配置提示。
在 Android 上使用 Apple 登录是hacky。Apple 对 Android 没有官方支持,所以解决方案略微hacky。 Sign in with Apple Android 当前使用 Chrome tabs 来显示 OAuth2 网站。这一方法存在以下挑战:
配置困难
- 需要后端
- 理解 Android 流程
标题:理解 Android 流程
标题:理解 Android 流程让我们使用一个图表来解释 Android 流程:
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-
登录到 Apple 开发者门户.
-
点击
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
-
确保
Primary App ID设置为上一步配置的 App ID
-
添加您将托管后端的域名。
-
域名。点击下一步。
Done
-
确认域名和返回 URL 配置
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并添加以下意图过滤器:__CAPGO_KEEP_0__
<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 验证
这里 env section 将看起来:
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"}使用插件
标题为“使用插件”函数的使用方法 login 函数的使用方法与 IOS 一致,详细信息请参见该部分。 然而方法有一些变化。 initialize 复制到剪贴板
await SocialLogin.initialize({ apple: { clientId: 'ee.forgr.io.ionic.starter.service2', redirectUrl: 'https://appleloginvps.wcaleniewolny.me/login/callback' }})创建应用
创建应用-
如果您没有 App ID,请点击加号按钮
-
选择并点击继续
App IDs选择App ID类型
-
选择并点击
App选择App类型Continue
-
输入App描述和bundle ID
-
能力
Sign with Apple启用Sign in 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的实现细节,以及 双因素认证 关于双因素认证的实现细节