苹果登录
复制包含安装步骤和本插件的完整 Markdown 指南的设置提示。
在 Android 上使用 Apple 登录是hacky。Apple 对 Android 没有官方支持,所以解决方案略hacky。 Sign in with Apple Android 当前使用 Chrome tabs 来显示 OAuth2 网站。这一方法存在以下挑战:
配置困难
- __CAPGO_KEEP_0__
- 需要一个后端
了解安卓上的流程
标题:了解安卓上的流程让我们使用一个图表来解释安卓上的流程:
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
-
__CAPGO_KEEP_0__
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 过滤器
<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 = Service ID
ANDROID_SERVICE_ID= App 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"}标题为“使用插件”的部分
该函数的使用方法与IOS相同,具体信息请参见该部分然而 login __CAPGO_KEEP_0__ __CAPGO_KEEP_1__, 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