Skip to content

Commit e3c7c63

Browse files
authored
Merge pull request #7942 from BacLuc/feature-refresh-jwt-token
refresh the access token in the background
2 parents 16662ef + c483357 commit e3c7c63

27 files changed

+302
-6
lines changed

.helm/ecamp3/templates/api_configmap.yaml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,9 @@ metadata:
77
{{- include "app.commonLabels" . | nindent 4 }}
88
data:
99
ADDITIONAL_TRUSTED_HOSTS: {{ .Values.domain | quote }}
10+
{{- if not (.Values.api.authenticationTokenTtl | empty) }}
11+
AUTHENTICATION_TOKEN_TTL: {{ .Values.api.authenticationTokenTtl | quote }}
12+
{{- end }}
1013
COOKIE_PREFIX: {{ include "api.cookiePrefix" . | quote }}
1114
APP_ENV: {{ .Values.api.appEnv | quote }}
1215
APP_DEBUG: {{ .Values.api.appDebug | quote }}

.helm/ecamp3/values.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ featureToggle:
1818
checklist: false # enables checklist feature in frontend
1919

2020
api:
21+
authenticationTokenTtl:
2122
subpath: "/api"
2223
image:
2324
repository: "docker.io/ecamp/ecamp3-api"

api/.env

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,4 +81,6 @@ MAIL_FROM_NAME="eCamp v3"
8181
RECAPTCHA_SECRET="disabled"
8282
###< google/recaptcha ###
8383

84+
# Tokens are valid for 12 hours..
85+
AUTHENTICATION_TOKEN_TTL=43200
8486
TRANSLATE_ERRORS_TO_LOCALES="en,de,fr,it,rm"

api/composer.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
"exercise/htmlpurifier-bundle": "5.1",
2424
"friendsofsymfony/http-cache": "3.1.1",
2525
"friendsofsymfony/http-cache-bundle": "3.2.0",
26+
"gesdinet/jwt-refresh-token-bundle": "1.5.0",
2627
"google/recaptcha": "1.3.1",
2728
"guzzlehttp/guzzle": "7.10.0",
2829
"knpuniversity/oauth2-client-bundle": "2.18.4",

api/composer.lock

Lines changed: 81 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

api/config/bundles.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
use Exercise\HTMLPurifierBundle\ExerciseHTMLPurifierBundle;
77
use Fidry\AliceDataFixtures\Bridge\Symfony\FidryAliceDataFixturesBundle;
88
use FOS\HttpCacheBundle\FOSHttpCacheBundle;
9+
use Gesdinet\JWTRefreshTokenBundle\GesdinetJWTRefreshTokenBundle;
910
use Hautelook\AliceBundle\HautelookAliceBundle;
1011
use KnpU\OAuth2ClientBundle\KnpUOAuth2ClientBundle;
1112
use Lexik\Bundle\JWTAuthenticationBundle\LexikJWTAuthenticationBundle;
@@ -44,4 +45,5 @@
4445
SentryBundle::class => ['all' => true],
4546
TwigExtraBundle::class => ['all' => true],
4647
FOSHttpCacheBundle::class => ['all' => true],
48+
GesdinetJWTRefreshTokenBundle::class => ['all' => true],
4749
];
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
gesdinet_jwt_refresh_token:
2+
cookie:
3+
enabled: true
4+
same_site: strict
5+
path: /
6+
http_only: true
7+
secure: '%env(bool:COOKIE_SECURE)%'
8+
remove_token_from_body: true
9+
refresh_token_class: App\Entity\RefreshToken
10+
single_use: true
11+
token_parameter_name: '%env(COOKIE_PREFIX)%refresh_token'

api/config/packages/lexik_jwt_authentication.yaml

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,7 @@ lexik_jwt_authentication:
77
public_key: '%env(resolve:JWT_PUBLIC_KEY)%'
88
pass_phrase: '%env(JWT_PASSPHRASE)%'
99

10-
# Tokens are valid for 12 hours, should be safe because we never expose the whole token to JavaScript.
11-
# Of course it would be even better to have only short-lived tokens but renew them on every request.
12-
token_ttl: 43200
10+
token_ttl: '%env(AUTHENTICATION_TOKEN_TTL)%'
1311

1412
# Read the JWT token from a split cookie: The [api-domain]_jwt_hp and [api-domain]_jwt_s cookies are combined with a period (.)
1513
# to form the full JWT token.

api/config/packages/security.yaml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,13 +28,16 @@ security:
2828
lazy: true
2929
provider: app_user_provider
3030
user_checker: App\Security\UserStatusChecker
31+
entry_point: jwt
3132
json_login:
3233
check_path: /authentication_token
3334
username_path: identifier
3435
password_path: password
3536
success_handler: lexik_jwt_authentication.handler.authentication_success
3637
failure_handler: lexik_jwt_authentication.handler.authentication_failure
3738
jwt: ~
39+
refresh_jwt:
40+
check_path: /token/refresh
3841
custom_authenticators:
3942
- App\Security\OAuth\GoogleAuthenticator
4043
- App\Security\OAuth\HitobitoAuthenticator
@@ -46,6 +49,7 @@ security:
4649
- { path: ^/auth, roles: PUBLIC_ACCESS } # OAuth and resend password endpoints
4750
- { path: ^/content_types, roles: PUBLIC_ACCESS } # Content types is more or less static and the same for all camps
4851
- { path: ^/invitations/.*/(find|reject), roles: PUBLIC_ACCESS }
52+
- { path: ^/token/refresh, roles: PUBLIC_ACCESS }
4953
- { path: ^/users$, methods: [POST], roles: PUBLIC_ACCESS } # register
5054
- { path: ^/users/.*/activate$, methods: [PATCH], roles: PUBLIC_ACCESS }
5155
- { path: .*, roles: [ROLE_USER] } # Protect all other routes must be at the end

api/config/routes.yaml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,6 @@
44
authentication_token:
55
path: /authentication_token
66
methods: ['POST']
7+
api_refresh_token:
8+
path: /token/refresh
9+
methods: ['POST']

0 commit comments

Comments
 (0)