Skip to content

Equivalent of this Python code #541

Answered by panva
ardimaunahan asked this question in Q&A
Discussion options

You must be logged in to vote

https://github.com/panva/jose/blob/v4.x/docs/functions/key_import.importPKCS8.md
https://github.com/panva/jose/blob/v4.x/docs/classes/jwt_sign.SignJWT.md

import * as jose from 'jose'

const obtainPrivateKeyPEMString = () => {
  return `-----BEGIN PRIVATE KEY-----
...
-----END PRIVATE KEY-----`;
}

const key = await jose.importPKCS8(obtainPrivateKeyPEMString(), 'PS256');

const jwt = await new jose.SignJWT({
  scope: '...',
})
  .setIssuedAt()
  .setExpirationTime('1h')
  .setIssuer('...')
  .setAudience('...')
  .setProtectedHeader({
    alg: 'PS256',
    kid: '...',
  })
  .sign(key)

console.log(jwt)

Replies: 2 comments

Comment options

You must be logged in to vote
0 replies
Answer selected by ardimaunahan
Comment options

You must be logged in to vote
0 replies
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants