Equivalent of this Python code #541
Answered
by
panva
ardimaunahan
asked this question in
Q&A
-
I'm just wondering if there is someone that can help me convert this sample working Python code to using jose:
|
Beta Was this translation helpful? Give feedback.
Answered by
panva
May 31, 2023
Replies: 2 comments
-
https://github.com/panva/jose/blob/v4.x/docs/functions/key_import.importPKCS8.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) |
Beta Was this translation helpful? Give feedback.
0 replies
Answer selected by
ardimaunahan
-
Amazing, it worked! Thanks a lot @panva. But I noticed that I had to add the
In the Python library, it automatically adds that. |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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