Android 上的 Apple 登录
复制一个包含安装步骤和完整 Markdown 指南的配置提示。
苹果登录在 Android 上是hacky。苹果没有对 Android 的官方支持 Sign in with Apple 在 Android 上,所以解决方案略微hacky。
Android 当前使用 Chrome tabs 来显示 OAuth2 网站。这种方法存在以下挑战:
- 配置困难
- 需要后端
理解 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-
点击
Identifiers.
您应该看到一个类似这样的屏幕:
- 确保这个字段显示
App IDs - 确保您可以找到您的 App ID。
- 确保这个字段显示
-
确保该功能在您的应用程序中启用
Sign in with Apple为您的应用程序启用该功能- 点击您的应用程序
- 确保该功能已启用
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 下拉菜单
-
添加您将在后端托管的域名
-
确认数据并点击
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
配置应用重定向
Section titled “配置应用重定向”您在图表中看到的后端执行一个名为“”的步骤 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 验证
部分将看起来像这样: env 服务ID
ANDROID_SERVICE_ID应用IDIOS_SERVICE_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"}标题为“使用插件”
= Service ID使用方式与IOS相同,具体请参见相关说明。 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__CAPGO_KEEP_0__Continue
-
输入描述和应用 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 中的实现细节 两因素身份验证 对于在两因素身份验证中的实现细节