Token I'm trying:
eyJhbGciOiJFUzI1NiIsInR5cCI6IkpXVCIsImtpZCI6IkdBQUw3VlVWRzQifQ.eyJvcmlnaW4iOiJodHRwOi8vbG9jYWxob3N0OjgwODAiLCJpYXQiOjE1NTI0NDQ1NDcsImV4cCI6MTU1MjQ0ODE0NywiaXNzIjoiOEJVMlk4QzVKNyJ9._2H4qgImjfujDnyD_aapJW9sdFfwfb_iAi_8w7uM4APXuTJ6ucQTk_f3rYi53emdMX7CWsOLWIXr_EfcgRSrVQ
http://jwt.io gives me:
Header:
{
"alg": "ES256",
"typ": "JWT",
"kid": "GAAL7VUVG4"
}
Payload:
{
"origin": "http://localhost:8080",
"iat": 1552444547,
"exp": 1552448147,
"iss": "8BU2Y8C5J7"
}
The commands you wanted me to try:
~/websites/test [master ↑·1|✚ 9…7]
16:40 $ echo "eyJhbGciOiJFUzI1NiIsInR5cCI6IkpXVCIsImtpZCI6IkdBQUw3VlVWRzQifQ.eyJvcmlnaW4iOiJodHRwOi8vbG9jYWxob3N0OjgwODAiLCJpYXQiOjE1NTI0NDQ1NDcsImV4cCI6MTU1MjQ0ODE0NywiaXNzIjoiOEJVMlk4QzVKNyJ9._2H4qgImjfujDnyD_aapJW9sdFfwfb_iAi_8w7uM4APXuTJ6ucQTk_f3rYi53emdMX7CWsOLWIXr_EfcgRSrVQ" | tr "." "\n" | head -1 | base64 -D
{"alg":"ES256","typ":"JWT","kid":"GAAL7VUVG4" ~/websites/test [master ↑·1|✚ 9…7]
16:42 $ echo "eyJhbGciOiJFUzI1NiIsInR5cCI6IkpXVCIsImtpZCI6IkdBQUw3VlVWRzQifQ.eyJvcmlnaW4iOiJodHRwOi8vbG9jYWxob3N0OjgwODAiLCJpYXQiOjE1NTI0NDQ1NDcsImV4cCI6MTU1MjQ0ODE0NywiaXNzIjoiOEJVMlk4QzVKNyJ9._2H4qgImjfujDnyD_aapJW9sdFfwfb_iAi_8w7uM4APXuTJ6ucQTk_f3rYi53emdMX7CWsOLWIXr_EfcgRSrVQ" | tr "." "\n" | head -2 | base64 -D
{"alg":"ES256","typ":"JWT","kid":"GAAL7VUVG4"}?&?&?v??#?&?GG?????6Ɔ?7C???"?&?B#?SS#CCCSCr?&W?#?SS#CC?Cr?&?72#?#?%S%??3T?r ~/websites/vue-extras [master ↑·1|✚ 9…7]
16:42 $
My Init code:
mapkit.init({
authorizationCallback: function (done) {
fetch(`http://localhost:8081/token/mapkit`)
.then((res) => res.text())
.then((token) => {
console.log(token);
done(token);
});
},
language: 'en',
});
My alternate Init code:
mapkit.init({
authorizationCallback: function (done) {
done('eyJhbGciOiJFUzI1NiIsInR5cCI6IkpXVCIsImtpZCI6IkdBQUw3VlVWRzQifQ.eyJvcmlnaW4iOiJodHRwOi8vbG9jYWxob3N0OjgwODAiLCJpYXQiOjE1NTI0NDQ1NDcsImV4cCI6MTU1MjQ0ODE0NywiaXNzIjoiOEJVMlk4QzVKNyJ9._2H4qgImjfujDnyD_aapJW9sdFfwfb_iAi_8w7uM4APXuTJ6ucQTk_f3rYi53emdMX7CWsOLWIXr_EfcgRSrVQ');
},
language: 'en',
});
My route generates a new token every time:
case '/TOKEN/:TYPE':
if (route.method === 'GET' && route.parms.type === 'mapkit') {
if (!process.env.kid || !process.env.iss || !process.env.key) {
done(500, `Missing key file environment variable(s)`);
return;
}
const privateKey = new Buffer.from(process.env.key, 'base64')
// const privateKey = fs.readFileSync(__dirname + "/../MapKitJS_AuthKey.p8");
jwt.sign({
origin: event.local === true ? 'http://localhost:8080' : 'NO'
}, privateKey, {
keyid: process.env.kid,
issuer: process.env.iss,
expiresIn: '1h',
algorithm: 'ES256',
}, (err, token) => {
if (err) {
done(500, err);
} else {
done(200, token);
}
});
} else {
done(405, `Method Not Allowed: ${route.method}`);
}
break;
- The token isn't expired. The one I am trying here expires an hour from now
- I have no idea how to check if my credentials are correct. I followd the directions here: https://developer.apple.com/documentation/mapkitjs/setting_up_mapkit_js
- As far as I can tell I'm passing the token to the MapKitJS correctly. I see the console log from my code, I see the error from MapKitJS.
- In the server code, event.local is hard coded to true. As you can see in the token itself, the origin is 'http://localhost:8080', not NO. I am accessing a local http server with 'http://localhost:8080'as the URL and when looking at the chrome network tab for the init call I can in fact see the server is sending the Origin header set to http://localhost:8080. The token route is on http://localhost:8081, a differnet server.
- This isn't an issue with my server in general. If I change my init code to just return the token as a string I get the same response, you can see my alternate init code above.
The node package I'm using to generate the token is 'jsonwebtoken' version '^8.5.0'.
I really have no idea what to try. The error the server gives is generic and not helpfull.