[MapKit JS] token authorization

I have created mapsID and Private Key following documentation of Mapkit JS, but console always shows
"[MapKit] Initialization failed because the authorization token is invalid."

This is my codes :
app.get('/', (req, res) => {
  res.sendFile('/index.html')
})

app.get('/services/jwt', (req, res) => {

  const header = {
    "alg": "ES256",
    "typ": "JWT",
    "kid": "******"

  const payload = {
    "iss": "
******",
    "iat": Date.now() / 1000,
    "exp": (Date.now() / 1000) + 15778800,
  }

  var cert = fs.readFileSync('./AuthKey_
********.p8'); // private key that you downloaded
  var token = jwt.sign(payload, cert, { header: header });
  res.json({ token: token })
})

Your express app exposes the signed token from the /services/jwt endpoint as a JSON object (See res.json). Make sure the client JavaScript fetches from the /services/jwt endpoint correctly, instead of pass the whole JSON string to MapKit JS.

Also, you should consult the documentation of the jwt NPM package you imported to make sure you pass the right parameters to jwt.sign().

You can navigate to jwt.io which has a Debugger where you can paste & validate your token. Paste only test tokens as a security measure. As well, the jwt package has an option called expiresIn which you can set as {expiresIn: '364d'} to expire in about a year.

[MapKit JS] token authorization
 
 
Q