Merge pull request 'Add configurable JWT expiration time config option' (#89) from configurable-jwt-token-expiration-time into main
All checks were successful
continuous-integration/drone/push Build is passing

Reviewed-on: mentorenwahl/mentorenwahl#89
This commit is contained in:
Dominic Grimm 2022-03-07 13:00:17 +00:00
commit 453489546e
5 changed files with 10 additions and 4 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

View file

@ -12,19 +12,20 @@ To change the environment variables edit the `.env` file.
| `BACKEND_URL` | `String` | Backend webroot (= `URL`) |
| `BACKEND_API_GRAPHQL_PLAYGROUND` | `Bool` | Enables GraphQL playground (automatically enabled when compiled in development mode) |
| `BACKEND_API_JWT_SECRET` | `String` | Password to encrypt all authentication tokens with |
| `BACKEND_API_JWT_EXPIRATION` | `Int` | Expiration time of authentication tokens in minutes |
| `BACKEND_SMTP_HELO` | `String` | SMTP server HELO |
| `BACKEND_SMTP_HOST` | `String` | SMTP server hostname |
| `BACKEND_SMTP_PORT` | `Int32` | SMTP server port (= `587`) |
| `BACKEND_SMTP_PORT` | `Int` | SMTP server port |
| `BACKEND_SMTP_NAME` | `String` | Name to send emails with |
| `BACKEND_SMTP_USERNAME` | `String` | SMTP account username |
| `BACKEND_SMTP_PASSWORD` | `String` | SMTP account password |
| `BACKEND_LDAP_HOST` | `String` | LDAP server hostname |
| `BACKEND_LDAP_PORT` | `Int32` | LDAP server port (= `389`) |
| `BACKEND_LDAP_PORT` | `Int` | LDAP server port |
| `BACKEND_LDAP_BASE_DN` | `String` | LDAP virtual DN |
| `BACKEND_LDAP_BASE_USER_DN` | `String` | LDAP user group DN |
| `BACKEND_LDAP_BIND_DN` | `String` | LDAP admin account DN |
| `BACKEND_LDAP_BIND_PASSWORD` | `String` | LDAP admin account password |
| `BACKEND_LDAP_CACHE_REFRESH_INTERVAL` | `Int32` | Periodical cache refresh interval in minutes |
| `BACKEND_LDAP_CACHE_REFRESH_INTERVAL` | `Int` | Periodical cache refresh interval in minutes |
## Compile time