使用新的DeviceCheck应用程序接口-我使用以下命令生成一个令牌:
[DCDevice.currentDevice generateTokenWithCompletionHandler:^(NSData * _Nullable token, NSError * _Nullable error)我正在使用签名的JWT成功地进行身份验证,以:
https://api.development.devicecheck.apple.com/v1/validate_device_token但得到的回应是:
Missing or incorrectly formatted device token payload以下是有效负载的示例:
{"device_token":"0200000072912.......<rest of tokenString>","transaction_id":"ac61b285-4420-4b7e-a750-fef2b9f3419c","timestamp":1506150851000}因此,我的问题是-如何从NSData获取令牌-这些方法都不起作用:
NSString *tokenString = [[token description] stringByTrimmingCharactersInSet:[NSCharacterSet characterSetWithCharactersInString:@"<>"]];
tokenString = [tokenString stringByReplacingOccurrencesOfString:@" " withString:@""];
NSString *tokenString = [token base64EncodedStringWithOptions:0];
const unsigned *tokenBytes = [token bytes];
NSString *tokenString = [NSString stringWithFormat:@"%08x%08x%08x%08x%08x%08x%08x%08x",
ntohl(tokenBytes[0]), ntohl(tokenBytes[1]), ntohl(tokenBytes[2]),
ntohl(tokenBytes[3]), ntohl(tokenBytes[4]), ntohl(tokenBytes[5]),
ntohl(tokenBytes[6]), ntohl(tokenBytes[7])];
NSMutableString *hexToken;
const unsigned char *iterator = (const unsigned char *) [token bytes];
hexToken = [[NSMutableString alloc] init];
for (NSInteger i = 0; i < token.length; i++)
{
[hexToken appendString:[NSString stringWithFormat:@"%02lx", (unsigned long) iterator[i]]];
}
NSString *tokenString = [NSString stringWithString:hexToken];苹果开发者论坛帮不上忙--我找到的唯一另一个问题是令牌在一分钟内过期--我会在几秒钟内发布到服务器上。
我正在使用Java HttpPost -并使用以下命令添加有效负载:
StringEntity params = new StringEntity(jsonPayload);
httpPost.setEntity(params);如果我将时间戳修改为秒而不是毫秒,我会得到一个关于时间戳的错误,所以我假设我正确地获得了服务器的有效负载。
提前感谢您的帮助。
发布于 2017-10-05 02:02:10
好的,选项2是正确的答案:
NSString *tokenString = [token base64EncodedStringWithOptions:0];服务器响应可能具有误导性-请注意,相同的响应:
Missing or incorrectly formatted device token payload如果您多次尝试使用相同的transaction_id发布JSON有效负载,或者多次发送相同的device_token (如果已经返回200 ),则可能会返回。
https://stackoverflow.com/questions/46377626
复制相似问题