I'm trying to implement a free trial mechanism using Apple's new DeviceCheck mechanism in iOS11. I've implemented the server part in RAILs 4. There's a fair bit of code, so I've put it in a gist: https://gist.github.com/jmfriend/b86f52f8f0649ad4cae176c08b77f000
I get the error: "Missing or badly formatted authorization token". That suggests that I'm doing something wrong when generating the JWT for the AuthKey_#####.p8 file.
For ease of reference, given it's probably where the issue is, this is the code that handles the p8 file:
def auth_header
# The authentication key must must use the ES256 algorithm and be in the Base 64 URL–encoded JSON web token format.
"Bearer #{auth_token}"
end
def auth_token
@auth_token ||= fetch_auth_token
end
def fetch_auth_token
header = { typ: "JWT",
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 }
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
It looks like this issue is caused by using use an application identifier like this: xxxx.com.companyname.subdomain.* when using the dev version of your app. In the live version of your app, because this app id ends up being an explicit App ID, it will work.
I've tested this getting the dev version of my app to use the explicit App ID by using a different provisioning profile to normal.
Now, to figure out why getting 'Failed to find bit state'. My speculation is that you have to validate a device, before you can set its bits. Haven't seen this in the documentation, but that's my guess given the error.