【问题标题】:DeviceCheck: Missing or badly formatted authorization tokenDeviceCheck:缺少或格式错误的授权令牌
【发布时间】:2018-07-04 22:19:42
【问题描述】:

我正在尝试在 iOS11 中使用 Apple 的新 DeviceCheck 机制实现免费试用机制。我已经在 RAILs 4 中实现了服务器部分。有相当多的代码,所以我把它放在一个要点中:https://gist.github.com/jmfriend/b86f52f8f0649ad4cae176c08b77f000

我收到错误消息:“授权令牌丢失或格式错误”。这表明我在为 AuthKey_#####.p8 文件生成 JWT 时做错了。

这段代码也在要点中,但为了便于参考,问题可能出在这就是处理 p8 文件的代码:

def auth_header
  # The authentication key must must use the ES256 algorithm and be in the Base 64 URL–encoded JSON web token format.
  # If your token doesn't use this format, you receive a BAD_AUTHENTICATION_TOKEN HTTP error.
  "Bearer #{auth_token}"
end

def auth_token
  @auth_token ||= fetch_auth_token
end

def fetch_auth_token
  header = {
      typ: "JWT", # Must be specified; not in documentation
      alg: "ES256",
      kid: key_id
  }

  body = {
      iss: team_id,
      iat: DateTime.now().to_time.to_i ,
      exp: DateTime.now().to_time.to_i + 43_200 # 12hrs     #    Time.now.to_i
  }

  authentication_token = JWT.encode(body, auth_key, 'ES256', header_files = header)
  authentication_token
end

def auth_key
  file = File.read(developer_token_file)
  key = OpenSSL::PKey::EC.new(file)
  key.check_key
  key
end

【问题讨论】:

  • 发现一个错误,header_files应该是header_fields。不幸的是,仍然出现同样的错误。
  • 现在已经针对实时 Apple 服务器进行了尝试,并得到了不同的响应。奇怪的是,不再收到“缺少或格式错误的授权令牌”。但是,我收到 200 响应消息:“无法找到位状态”。这不是 JSON,所以破坏了我期望 JSON 的代码。有谁知道这个消息是什么意思?它在官方文档中,但我没有解释为什么你会得到它。

标签: ruby-on-rails json jwt ios11 devicecheck


【解决方案1】:

在这种情况下,“缺少或格式错误的授权令牌”问题是由使用如下应用程序标识符引起的:xxxx.com.companyname.subdomain.* 在使用开发版本的应用程序时。在您的应用的实际版本中,因为此应用 ID 最终成为显式应用 ID,所以它可以工作。

我已经对此进行了测试,让我的应用程序的开发版本通过使用与正常不同的配置文件来使用显式应用程序 ID。

'未能找到位状态'事实证明,这只是意味着您尚未为此设备设置任何位。在设置其位之前,您无需验证设备。 Note 还将 RAIls 要点更新为实时运行的代码。

【讨论】:

    猜你喜欢
    • 2018-10-31
    • 2018-05-03
    • 1970-01-01
    • 1970-01-01
    • 2016-03-08
    • 2017-12-11
    • 1970-01-01
    • 2021-06-09
    • 2021-10-20
    相关资源
    最近更新 更多