10 examples of 'jsonwebtoken npm' in JavaScript

Every line of 'jsonwebtoken npm' code snippets is scanned for vulnerabilities by our powerful machine learning engine that combs millions of open source libraries, ensuring your JavaScript code is secure.

All examples are scanned by Snyk Code

By copying the Snyk Code Snippets you agree to
54public get token() {
55 return jwt.sign({
56 id: this.id,
57 role: this.role
58 }, process.env.JWT_KEY);
59}
28function _generateToken(user: User): string {
29 // Only add essential information to the JWT
30 const jwtUser: IJsonWebTokenContents = {
31 id: user._id,
32 roles: user.roles
33 }
34
35 return JWT.sign(jwtUser, env.JWT_SECRET, {
36 expiresIn: '7d'
37 })
38}
49function createRefreshToken(userId) {
50 return jwt.sign(
51 {
52 userId,
53 type: "refresh"
54 },
55 AUTH_SECRET,
56 {
57 expiresIn: REFRESH_TOKEN_EXPIRE_SECONDS,
58 issuer: JWT_ISSUER
59 }
60 );
61}
10export function createToken(id, callback) {
11
12 const helper = utility.setSessionKey(id);
13
14 const token = jwt.sign({
15 _id: id,
16 _verify: helper.verify
17 }, config.secret, {
18 //noTimestamp: true
19 expiresIn: config.redis.token.time
20 });
21
22 callback(null, {
23 key: helper.key,
24 value: token
25 });
26}
9function generateToken(params = {}) {
10 return jwt.sign(params, process.env.SECRET_KEY, {
11 expiresIn: 86400,
12 });
13}
6static generateToken(user: IUser, isMediaToken: boolean = false) {
7 const data: any = {_id: user._id.toString()};
8 if (isMediaToken) {
9 // This isMediaToken property signifies that the token is only meant for media access, i.e. for images, videos, PDFs and so on.
10 // In the rest of the codebase (API back-end & App front-end) the special token with this property is called the mediaToken.
11 // It is explicitly NOT valid for any regular user operations, like viewing pages (that require the user to be logged-in).
12 // Thus, in combination with randomized unguessable filenames, URLs that have a mediaToken attached are technically sharable.
13 // Since the token will also expire eventually, any accidental leak of an URL with mediaToken should be contained automatically.
14 // (Unless the affected files are replicated and distributed by other means prior to the expiration of course.)
15 data.isMediaToken = true;
16 }
17 return sign(
18 data,
19 config.secret,
20 {
21 expiresIn: 10080 // in seconds
22 }
23 );
24}
5function signToken(user: Object) {
6 const roleinfo = user.roles[0].name;
7 const payload: AuthToken = {
8 issuer: 'boldr',
9 subject: user.id,
10 algorithms: ['HS256'],
11 expiresIn: '7 days',
12 email: user.email,
13 role: roleinfo,
14 };
15 return jwt.sign(payload, config.token.secret);
16}
40static generateToken(user) {
41 const token = jwt.sign(
42 {
43 id: user.userId,
44 role: user.role,
45 email: user.email.toLowerCase(),
46 },
47 process.env.SECRET,
48 {
49 expiresIn: 172800
50 }
51 );
52
53 return token;
54}
53public async verifyToken(token: string) {
54 return (await jwt.verify(token, jwtSettings.secretKey)) as IJwtPayload;
55}
49export function generateToken (userId) {
50 return jwt.sign({ userId }, getAppKey())
51}

Related snippets