Skip to content

Commit

Permalink
Authentication and session handling in BFF doesn't work in cluster mo…
Browse files Browse the repository at this point in the history
…de (#1140) (#1145)

Co-authored-by: khanhtranduy <[email protected]>
  • Loading branch information
khanhtrand and khanhtranduy authored Oct 14, 2024
1 parent cb6b212 commit eeaf29a
Show file tree
Hide file tree
Showing 6 changed files with 54 additions and 2 deletions.
3 changes: 3 additions & 0 deletions .env
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,9 @@ PROMETHEUS_SERVICE_PORT=9090
PROMETHEUS_SERVICE_HOST=prometheus
PROMETHEUS_ADDR=${PROMETHEUS_SERVICE_HOST}:${PROMETHEUS_SERVICE_PORT}

# Redis
SPRING_DATA_REDIS_HOST=redis
SPRING_DATA_REDIS_PORT=6379

# *******************************************************
# Environment Variables are injected to the microservices
Expand Down
8 changes: 8 additions & 0 deletions backoffice-bff/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,14 @@
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-oauth2-client</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-redis</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.session</groupId>
<artifactId>spring-session-data-redis</artifactId>
</dependency>
</dependencies>
<build>
<plugins>
Expand Down
10 changes: 10 additions & 0 deletions backoffice-bff/src/main/resources/application.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,12 @@ spring:
client-id: backoffice-bff
client-secret: TVacLC0cQ8tiiEKiTVerTb2YvwQ1TRJF #gitleaks:allow
scope: openid, profile, email, roles
data:
redis:
host: redis
port: 6379
session:
store-type: redis
management:
tracing:
sampling:
Expand All @@ -42,6 +48,8 @@ spring:
on-profile: "dev"
cloud:
gateway:
default-filters:
- SaveSession
routes:
# Changes for your local development should not be committed
- id: api_servicename_local
Expand Down Expand Up @@ -69,6 +77,8 @@ spring:
on-profile: "prod"
cloud:
gateway:
default-filters:
- SaveSession
routes:
- id: api
uri: http://nginx
Expand Down
13 changes: 13 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -591,6 +591,18 @@ services:
- kafka-connect
networks:
- yas-network
redis:
image: redis:7.4.1-alpine
restart: always
ports:
- '6379:6379'
environment:
- SPRING_DATA_REDIS_HOST
- SPRING_DATA_REDIS_PORT
volumes:
- redis:/data
networks:
- yas-network

networks:
yas-network:
Expand All @@ -600,3 +612,4 @@ networks:
volumes:
postgres:
pgadmin:
redis:
8 changes: 8 additions & 0 deletions storefront-bff/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,14 @@
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-gateway</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-redis</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.session</groupId>
<artifactId>spring-session-data-redis</artifactId>
</dependency>
</dependencies>
<build>
<plugins>
Expand Down
14 changes: 12 additions & 2 deletions storefront-bff/src/main/resources/application.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,12 @@ spring:
client-id: storefront-bff
client-secret: ZrU9I0q2uXBglBnmvyJdkl1lf0ncr8tn #gitleaks:allow
scope: openid, profile, email, roles
data:
redis:
host: redis
port: 6379
session:
store-type: redis
management:
metrics:
distribution:
Expand All @@ -39,22 +45,24 @@ spring:
on-profile: "dev"
cloud:
gateway:
default-filters:
- SaveSession
routes:
# Changes for your local development should not be committed
- id: api_servicename_local
uri: http://localhost:8081
predicates:
- Path=/api/servicename/**
filters:
- RewritePath=/api/(?<segment>.*), /$\{segment}
- TokenRelay=
- StripPrefix=1
- id: api
uri: http://api.yas.local
predicates:
- Path=/api/**
filters:
- RewritePath=/api/(?<segment>.*), /$\{segment}
- TokenRelay=
- StripPrefix=1
- id: nextjs
uri: http://localhost:3000
predicates:
Expand All @@ -66,6 +74,8 @@ spring:
on-profile: "prod"
cloud:
gateway:
default-filters:
- SaveSession
routes:
- id: api
uri: http://nginx
Expand Down

0 comments on commit eeaf29a

Please sign in to comment.