Windows
本文旨在介绍如何设置 Apple 身份验证,让您的游戏可以使用 Player Network 登录鉴权服务通过 Apple 渠道登录。
前提条件
1. 在 Apple Developer 上配置 iOS 应用
1. 创建 Services ID
如果您使用的是现有的 Services ID,在 Identifiers 页面中点击对应的 Services ID,在 Edit your Services ID Configuration 下打开 Sign in with Apple 选项后,点击 Configure 并继续步骤6。
- 
登录 Apple Developer,并在在顶部导航栏中点击 Account,并选择 Certificates, IDs & Profiles 下的 Identifiers。  
- 
点击蓝色添加图标(+)。  
- 
选择 Services IDs 后,点击 Continue。 

- 
输入 Description 和 Identifier。 - Description:游戏应用的名称或描述。
- Identifier:唯一标识符。
  
- 
在 Capabilities 下打开 Sign in with Apple 选项后,点击 Configure。 
- 
在 Return URLs 下,添加 Player Network 提供的重定向链接后,点击 Save。 - North America:https://na-webproxy.intlgame.com/v2/webproxy/appleredirect
- Singapore and other regions:https://sg-webproxy.intlgame.com/v2/webproxy/appleredirect
- Testing:https://test-webproxy.intlgame.com/v2/webproxy/appleredirect
- aws-North America:https://aws-na-webproxy.intlgame.com/v2/webproxy/appleredirect
  
- 
点击 Continue > Register,创建 Services ID。 
2. 创建用于访问服务的密钥
创建用于计算 client_secret 的密钥和 相应的 Key ID。
- 
在 Certificates, Identifiers & Profiles 侧边栏中,点击 Keys。 
- 
点击蓝色添加图标(+)。  
- 
在 Key Name 下,输入密钥的唯一名称。 
- 
选择 Sign in with Apple 旁边的复选框,然后点击 Configure。  
- 
在 Primary App ID 下,选择在 上一步 中创建的 App ID,然后点击 保存。  
- 
点击 Continue。 
- 
点击 Register 生成密钥,并记下 Key ID。 
- 
点击 Download 下载密钥文件(只能下载一次,切勿丢失),该文件保存为文件后缀 .p8 的文本文件。 
3. 获取 Team ID
- 
登录 Apple Developer。 
- 
在顶部导航栏中,点击Account下滑找到Membership details以查看Team ID。  
有关 Apple Developer配置的更多信息,请参见 What the Heck is Sign In with Apple?。
- 获取 Player Network 控制台登录账号。
- 为游戏创建新项目,或加入已有项目。
- 下载 SDK。
- 接入 SDK。
- 在 Player Network 控制台添加 Apple 为业务的登录鉴权方式。
步骤1:为 Apple 登录配置 SDK
打开项目的 INTLConfig.ini 文件:
[Apple]
APPLE_WEB_APP_ID = {INTL_APPLE_WEB_APP_ID}
将 {INTL_APPLE_WEB_APP_ID} 替换为游戏的 Apple Web APPLICATION ID。
步骤2:添加 Apple 登录
- Apple 登录是无法在重签包测试的,建议使用 TestFlight 或者 Dev 的打包。
- Apple 登录不提供 PictureUrl(用户头像 URL)。更多信息,请参见 Unity 引擎的 INTLAuthResult 或 Unreal Engine 的 FINTLAuthResult。
Login 接口的登录权限参数传入 email 和 fullName:
- 在首次登录的界面中有编辑用户名和隐 藏邮箱的选项(Fig 2)。在回调中可以获取 email和fullName。- 玩家选择隐藏邮箱,获取的邮箱为随机邮箱地址
- 玩家选择共享邮箱,获取到用户的真实邮箱地址
 
- 后续登录不会获取到 email和fullName,登录界面(Fig 2),没有编辑用户名和隐藏邮箱选项。
- 如果玩家停止 app 使用 Apple ID 后再次登录,会显示 Fig 1 所示选项。
玩家可以选择 设置 > [您的用户名] > 密码和安全 > 使用 Apple ID > [应用名称] > 停止使用 Apple ID 来停止让 app 继续使用 Apple ID 登录。
在 Login 接口的登录权限参数传入空字符串时,登录界面没有编辑用户名和隐藏邮箱的选项(Fig 2)。在回调中 email 和 fullName 为空。
Fig 1:

Fig 2:
- 
注册登录相关回调。 - Unity
- Unreal Engine
 // Add callbacks
 public void AddAuthObserver()
 {
 INTLAPI.AddAuthResultObserver(OnAuthResultEvent);
 }
 // Remove callbacks
 public void RemoveAuthObserver()
 {
 INTLAPI.RemoveAuthResultObserver(OnAuthResultEvent);
 }
 // Process the INTLAuthResult callback
 public void OnAuthResultEvent(INTLAuthResult ret)
 {
 Debug.Log($"MethodID: {ret.MethodId}");
 
 string methodTag = "";
 if (authRet.MethodId == (int)INTLMethodID.INTL_AUTH_LOGIN)
 {
 methodTag = "Login";
 }
 else if (authRet.MethodId == (int)INTLMethodID.INTL_AUTH_BIND)
 {
 methodTag = "Bind";
 }
 else if (authRet.MethodId == (int)INTLMethodID.INTL_AUTH_AUTOLOGIN)
 {
 methodTag = "AutoLogin";
 }
 else if (authRet.MethodId == (int)INTLMethodID.INTL_AUTH_QUERY_USER_INFO)
 {
 methodTag = "QueryUserInfo";
 }
 else if (authRet.MethodId == (int)INTLMethodID.INTL_AUTH_GET_AUTH_RESULT)
 {
 methodTag = "GetAuthResult";
 }
 }C++ Event Handling (above v1.15) //configure callback
 FINTLAuthEvent authEvent;
 authEvent.AddUObject(this, &OnAuthResult_Implementation);
 UINTLSDKAPI::SetAuthResultObserver(authEvent);
 // Remove callbacks
 UINTLSDKAPI::GetAuthResultObserver().Clear();void OnAuthResult_Implementation(FINTLAuthResult ret)
 {
 UE_LOG(LogTemp, Warning, TEXT("MethodID: %d"), ret.MethodId);
 }Unreal Event Handling void OnAuthResult_Implementation(FINTLAuthResult ret)
 {
 UE_LOG(LogTemp, Warning, TEXT("MethodID: %d"), ret.MethodId);
 }
- 
调用 AutoLogin接口自动登录。- Unity
- Unreal Engine
 INTLAPI.AutoLogin();UINTLSDKAPI::AutoLogin();
- 
在自动登录失败时调用 Login接口使玩家手动登录。- Unity
- Unreal Engine
 INTLAPI.Login(INTLChannel.Apple);UINTLSDKAPI::Login(EINTLLoginChannel::kChannelApple);
- 
与游戏后台同步客户端身份验证状态,等待最终验证结果。 
[可选] 设置 email 权限
Apple 获取玩家邮箱需要玩家授权,如果玩家拒绝授权将无法获取到玩家邮箱,详见 Login 接口传入 email 和 fullName。
要在 Apple 登录时获取玩家邮箱需先设置对应权限,开启后将在 AuthResult 的 ChannelInfo 中返回 email。
- 基于合规考虑,可针对特定来源对返回的 email做 mask 处理,如有需求请联系 Player Network 助手打开。
- 可在后台流水日志中上报 hash 后的 base64(sha256(email)),如有需求请联系 Player Network 助手打开。
- 可用于验证玩家信息或绑定列表是否包含 email信息,如有需求请联系 Player Network 助手打开。
- 
调用 Login 接口时,需要在 permissions参数中添加email权限。
- 
在 Player Network 控制台 开启 email 返回功能,将 return_email 设置为 YES,详细步骤请参见 第三方渠道配置。 
步骤3:验收登录功能
在 Player Network SDK 日志中搜索关键字 "AuthResult" 确认渠道名称和 OpenID 是否正确返回。如果正确,则表明集成配置成功,登录功能已成功添加。
如果接入过程中遇到问题,请参见 常见问题。