Error: secretOrPrivateKey must be an asymmetric key when using RS256
Closed this issue · 6 comments
const token = Mux.JWT.signPlaybackId('some-playback-id');
when create token gettign error
Error: secretOrPrivateKey must be an asymmetric key when using RS256
at Object.module.exports [as sign] (/home/chhayya/Documents/fitscopeV2/fitscopeV2_Backend/node_modules/.pnpm/jsonwebtoken@9.0.0/node_modules/jsonwebtoken/sign.js:124:22)
at Function.signPlaybackId (/home/chhayya/Documents/fitscopeV2/fitscopeV2_Backend/node_modules/.pnpm/@mux+mux-node@7.3.1/node_modules/@mux/mux-node/src/utils/jwt.ts:155:16)
at Function.sign (/home/chhayya/Documents/fitscopeV2/fitscopeV2_Backend/node_modules/.pnpm/@mux+mux-node@7.3.1/node_modules/@mux/mux-node/src/utils/jwt.ts:109:17)
at /home/chhayya/Documents/fitscopeV2/fitscopeV2_Backend/src/routes/content/categories.ts:170:47
at Array.map (<anonymous>)
at /home/chhayya/Documents/fitscopeV2/fitscopeV2_Backend/src/routes/content/categories.ts:168:60
at Array.map (<anonymous>)
at Object.<anonymous> (/home/chhayya/Documents/fitscopeV2/fitscopeV2_Backend/src/routes/content/categories.ts:167:33)
at processTicksAndRejections (node:internal/process/task_queues:96:5)
[ERROR] 13:10:37 Error: secretOrPrivateKey must be an asymmetric key when using RS256
@roninaruka do you have environment variables set:
process.env.MUX_SIGNING_KEY
process.env. MUX_PRIVATE_KEY
Thanks @dylanjha i have set
also use const token = Mux.JWT.sign('some-playback-id', { keyId: 'your key id', keySecret: 'your key secret' })
but same getting same error
Okay this is probably an issue with the keySecret.
Which way did you get your key:
- Created in the Mux Dashboard & copied to clipboard in the UI
- Created via the API
- Created in the Mux Dashboard & downloaded as
.pem
file
Can you try one of the first 2 options? Probably easiest if you just create in the dashboard and click "copy" to get the Base-64 encoded private key.
You can get to this screen from Settings > Signing Keys in the left nav and then click "Generate new key"
@dylanjha Thanks its working fine but one more question i have pass expiration in option like { expiration: ((new Date()).getTime() + 50).toString() }
for 50 sec
but its not wokring
is anything wrong here ??
@roninaruka well, 50 seconds is probably too short (the expiration has to be at least longer than the duration of the video
I'm noticing that this should be documented better, but the expiration
value gets passed into jwt.sign
as the expiresIn
value in this jsonwebtoken
dependency
Values are like this:
50
(50 seconds)50s
(50 seconds)7d
(7 days) -- the default4h
(4 hours)
See here for the syntax
@roninaruka hope that clears it up. Lmk if you're still having issues.