Add configurable JWT expiration time config option
All checks were successful
continuous-integration/drone/push Build is passing
continuous-integration/drone/pr Build is passing

This commit is contained in:
Dominic Grimm 2022-03-07 13:50:28 +01:00
parent 29298023d2
commit 71ccfa6491
4 changed files with 6 additions and 1 deletions

View file

@ -26,6 +26,7 @@ BACKEND_URL=URL
# Backend - API
BACKEND_API_GRAPHQL_PLAYGROUND=false
BACKEND_API_JWT_SECRET=
BACKEND_API_JWT_EXPIRATION=360
# Backend - Worker
# Backend - SMTP
BACKEND_SMTP_HELO=

View file

@ -79,6 +79,7 @@ services:
BACKEND_URL: ${URL}
BACKEND_API_GRAPHQL_PLAYGROUND: ${BACKEND_API_GRAPHQL_PLAYGROUND}
BACKEND_API_JWT_SECRET: ${BACKEND_API_JWT_SECRET}
BACKEND_API_JWT_EXPIRATION: ${BACKEND_API_JWT_EXPIRATION}
BACKEND_SMTP_HELO: ${BACKEND_SMTP_HELO}
BACKEND_SMTP_HOST: ${BACKEND_SMTP_HOST}
BACKEND_SMTP_PORT: ${BACKEND_SMTP_PORT}

View file

@ -33,7 +33,7 @@ module Backend
user: User.new(user),
token: Auth.create_user_jwt(
user.id.not_nil!.to_i,
(Time.utc + (user.admin ? Time::Span.new(hours: 6) : Time::Span.new(days: 1))).to_unix
(Time.utc + Backend.config.api.jwt_expiration.minutes).to_unix
),
)
end

View file

@ -87,6 +87,9 @@ module Backend
# JWT signing key
getter jwt_secret : String
# JWT expiration time in minutes
getter jwt_expiration : Int32
# Helper method for enabling GraphQL playground
#
# Returns `true` if `Config#development?` or `#graphql_playground` are