Hi all,
I've been trying to get this DeviceCheck to work for a while now. But I keep getting this error:
HTTP/1.0 400 Bad Request; Missing or badly formatted authorization token.
I've tried it with NodeJS in the following way:
var jwt = require('jsonwebtoken'); var cert = fs.readFileSync('AuthKey_###.p8'); var jwToken = jwt.sign({}, cert, { algorithm: 'ES256', keyid: "#p8KeyID#", issuer: "#teamID#"});
And in PHP:
use Zenstruck\JWT\Token; use Zenstruck\JWT\Signer\OpenSSL\ECDSA\ES256; use \Ramsey\Uuid\Uuid; function generateJWT($teamId, $keyId, $privateKeyFilePath) { $payload = [ "iss" => $teamId, "iat" => time() ]; $header = [ "kid" => $keyId ]; $token = new Token($payload, $header); return (string)$token->sign(new ES256(), $privateKeyFilePath); }
Neither of those two scripts work. Both are getting the previously mentioned error. I am adding the "Authorization: Bearer " header with the JWT appended. So it's definitely there.
Have the DeviceCheck services not been working for a while now? Or am I generating the JWT in a wrong way?
Thanks in advance,
Tim
So the way I was getting the p8 key was wrong. Such a silly mistake...
Instead of (correct):
var cert = fs.readFileSync('AuthKey_###.p8').toString();
I had (incorrect):
var cert = fs.readFileSync('AuthKey_###.p8');
I found the solution to my problem in the answer to this question: