I've used JWTs a lot for user authentication, but I can't get them to work with MapKitJS. I have a route that creates a token...
const privateKey = fs.readFileSync(__dirname + "/../MapKitJS_AuthKey.p8");
const token = jwt.sign({
origin: event.local === true ? 'http://localhost:8080' : 'NO'
}, privateKey, {
header: {
kid: process.env.kid,
typ: 'JWT',
alg: 'ES256'
},
issuer: process.env.iss,
expiresIn: '1h',
algorithm: 'ES256'
});I'm using node, and the resulting token looks just fine...
eyJhbGciOiJFUzI1NiIsInR5cCI6IkpXVCIsImtpZCI6IkdBQUw3VlVWRzQifQ.eyJvcmlnaW4iOiJodHRwOi8vbG9jYWxob3N0OjgwODAiLCJpYXQiOjE1NTE1MDkzNDgsImV4cCI6MTU1MTUxMjk0OCwiaXNzIjoiOEJVMlk4QzVKNyJ9.BSXts5IrsUyPfsPnkbI-MeUC3xpZkQ2K_1wsjMw-RrT3qLE7WSULFpmvF076V6HAU1J80vBCd5o8veRXCFWN4g
Looking at it in jwt.io it come out nicely...
{
"alg": "ES256",
"typ": "JWT",
"kid": "GAAL7VUVG4"
}
{
"origin": "http://localhost:8080",
"iat": 1551509348,
"exp": 1551512948,
"iss": "8BU2Y8C5J7"
}
But passing the toke to MapKitJS I always get "Bootstrap.init(): initialization failed because the authorization token is invalid." from the server. I'm at a loss. I have no idea what to do at this point.
Hi,
Well, your code and my code work. I needed to make a new certificate. I don't know why the one I was using is invalid. I've tried the old certificate with your code and it produces invalid tokens as well. The new certificate makes valid tokens is both versions of the code.
I would be interested in knowing if the old certificate I downloaded got corrupted somehow or if it was originally invalid, but I can't redownload it so there is no way to tell.
Anyway, thank you for your help, sorry I've been such a bother.
For anyone else reading this: The certificate was invalid. I made a new one Key and downloaded the new certificate and things worked.