Search code examples
jwttokenaccess-tokenloopback4

Loopback 4 - How long does the generated token expire? - ex: ToDo


I am studying the examples that the framework offers

In the To-Do example, it has JWT authentication.

How long does the generated token expire?

I didn't see a second or similar parameter, which could help with this

Link: https://github.com/strongloop/loopback-next/tree/master/examples/todo-jwt

OR

lb4 example todo-jwt


Solution

  • @loopback/todo-jwt example leverages @loopback/authentication-jwt, which provides configurable defaults.

    By default, tokens expire in 21600s (git permalink), and refresh tokens expire in 216000s (git permalink)

    Both of these are configurable (git permalink):

    // Inside RestApplication constructor
    
    // for jwt access token expiration
    this.bind(TokenServiceBindings.TOKEN_EXPIRES_IN).to("<Expiration Time in sec>");
    // for refresh token expiration
    this.bind(RefreshTokenServiceBindings.TOKEN_EXPIRES_IN).to("<Expiration Time in sec>");