Skip to content

Instantly share code, notes, and snippets.

@arimanov
Last active May 19, 2025 20:15
Show Gist options
  • Save arimanov/5a3d2dd765d86a1e70acac378b567e53 to your computer and use it in GitHub Desktop.
Save arimanov/5a3d2dd765d86a1e70acac378b567e53 to your computer and use it in GitHub Desktop.
JWT HS256 generator
import { SignJWT, jwtVerify } from 'jose';
async function generateJWT() {
try {
const customSecretKeyString = '';
const secretKey = new TextEncoder().encode(customSecretKeyString);
const payload = {
iss: '',
tid: '',
aud: ''
};
const token = await new SignJWT(payload)
.setProtectedHeader({ alg: 'HS256' })
.setIssuedAt()
.setExpirationTime('1y')
.sign(secretKey);
console.log('JWT:', token);
} catch (error) {
console.error('Error:', error);
}
}
generateJWT();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment