使用 Apple 登录 - 无法验证授权码

Sign In with Apple - Cannot Validate the Authorization Grant Code

我正在努力将 Sign In with Apple 集成到我的应用程序中。该应用程序是使用 expo 在 React Native 中编写的,我现在几乎完全使用这个组件。 https://docs.expo.io/versions/latest/sdk/apple-authentication/#usage

我已经能够使用此组件成功生成授权授予代码,但是,我无法在服务器端对其进行验证。这是我目前收到的错误:

{
    "error": "invalid_grant",
    "error_description": "The code has expired or has been revoked."
}

详情

我已将 Sign In with Apple key 添加到我的应用程序并下载了私钥。我已将应用程序发布到 TestFlight,因此我在模拟器中获得了自己的包标识符,而不是 Expo。

这是来自第一个请求的授权代码的格式(格式不是 JSON,因为它是从 go 输出的):

{
   realUserStatus:1 ,
   authorizationCode:xxxx ,
   fullName:{
        middleName:null
        nameSuffix:null 
        namePrefix:null
        givenName:null 
        familyName:null
        nickname:null} 
   state:null 
   identityToken:xxxxxxx
   email:null 
   user:xxxxx      
}

我正在使用这个库来生成验证请求:https://github.com/pagnihotry/siwago我是 运行 来自我的笔记本电脑的 go 脚本(不是与应用程序关联的域),以及copying/pasting 将信息导入 Postman。

两种方法都使用 x-www-form-urlencoded。 go 应用程序正在签署 client_secret,我认为这是正确的方式,因为我不再获得 400 invalid_client。我已经解码 client_secret 并确认验证请求的格式为:

{
  "alg": "ES256",
  "kid": "SECRET_KEY_ID"
}
{
  "iss": "TEAM_ID",
  "iat": 1626740200,
  "exp": 1629332200,
  "aud": "https://appleid.apple.com",
  "sub": "BUNDLE_ID"
}

我已通过根据我的私钥的 public 补码验证它来确认客户端机密是用我的私钥签名的。

授权https://appleid.apple.com/auth/token请求的表单数据为(数值无标点符号):

client_id: [BUNDLE_ID]
client_secret: [signed secret]
code: [authorizationCode] (from the Authorization grant code)
grant_type: authorization_code
redirect_uri: [left empty in go, not a key in Postman]

我已经多次请求我的授权码并且认为我可能被限制了,但后来我第一次尝试了一个全新的但仍然得到了 invalid_grant 响应。

寻求任何帮助,过去整整两天我都在这上面度过,感到筋疲力尽。

我认为 Apple 的服务器需要更多时间,因为我看到其他帖子也有类似的问题。等了两天左右,又试了一次,没问题。