Giter Site home page Giter Site logo

Comments (8)

erezger avatar erezger commented on May 3, 2024 16

hello
what about two different secret keys?
secret key for access token and different secret key for refresh token?

from jwt.

quangpdt avatar quangpdt commented on May 3, 2024 12

A simple implementation can help you on this without module support:

Install jsonwebtoken package and its type definition:

npm i jsonwebtoken  
npm i -D @types/jsonwebtoken

Implement the refresh token like these:

import * as jwt from 'jsonwebtoken';

public createToken({ id, email, role }: UserModel) {
    const user = { id, email, role };
    const token = this.jwtService.sign(user);
    const refreshToken = jwt.sign(user, refreshTokenSecretKey, { expiresIn: '14d' });
    return {
        expires_in: expiresIn,
        access_token: token,
        refresh_token: refreshToken,
    };
}

Hope this help!

from jwt.

isurumaldeniya avatar isurumaldeniya commented on May 3, 2024 7

You can change the expires time when you sign the token.
access_token: this.jwtService.sign(payload_acess, {expiresIn: 50} ),
refresh_token: this.jwtService.sign(payload_refresh, {expiresIn: 500})

here time is on seconds.

from jwt.

tiberiumihai avatar tiberiumihai commented on May 3, 2024

If you decide to merge this PR, can you please update the npm package as well with the new version? Thanks!

from jwt.

kamilmysliwiec avatar kamilmysliwiec commented on May 3, 2024

You're totally right, I completely forgot about it. Just left comments in the PR

from jwt.

kamilmysliwiec avatar kamilmysliwiec commented on May 3, 2024

Published as 0.2.0 :)

from jwt.

hectormartin42 avatar hectormartin42 commented on May 3, 2024

I have the same problem

from jwt.

merq-rodriguez avatar merq-rodriguez commented on May 3, 2024

Hello guys, he asks me if you can tell me how to implement the access token and refresh token with different secret keys each.
I have seen that they can be used with different expiration times, but I still don't know how to implement them with a different secret key. Can you think of something? @isurumaldeniya

from jwt.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.