Skip to content

Commit bb83ac4

Browse files
Add docker env var for secret key + base64encode secret key (lowcoder-org#446)
1 parent 1c82bb9 commit bb83ac4

File tree

6 files changed

+17
-8
lines changed

6 files changed

+17
-8
lines changed

‎deploy/docker/docker-compose-multi.yaml

+1
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ services:
4646
DEFAULT_ORG_GROUP_COUNT: 100
4747
DEFAULT_ORG_APP_COUNT: 1000
4848
DEFAULT_DEVELOPER_COUNT: 50
49+
LOWCODER_API_KEY_SECRET: "123456789101112131415123456789101112131415123456789101112131415123456789101112131415"
4950
restart: unless-stopped
5051
depends_on:
5152
- mongodb

‎deploy/docker/docker-compose.yaml

+1
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ services:
3333
ENCRYPTION_PASSWORD: "lowcoder.org"
3434
ENCRYPTION_SALT: "lowcoder.org"
3535
CORS_ALLOWED_DOMAINS: "*"
36+
LOWCODER_API_KEY_SECRET: "123456789101112131415123456789101112131415123456789101112131415123456789101112131415"
3637
# api and node service parameters
3738
LOWCODER_API_SERVICE_URL: "http://localhost:8080"
3839
LOWCODER_NODE_SERVICE_URL: "http://localhost:6060"

‎server/api-service/lowcoder-server/src/main/java/org/lowcoder/api/authentication/util/JWTUtils.java

+8-5
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
import io.jsonwebtoken.JwtParser;
55
import io.jsonwebtoken.Jwts;
66
import io.jsonwebtoken.SignatureAlgorithm;
7+
import io.jsonwebtoken.io.Encoders;
78
import jakarta.annotation.PostConstruct;
89
import lombok.extern.slf4j.Slf4j;
910
import org.lowcoder.domain.user.model.User;
@@ -12,8 +13,6 @@
1213
import org.springframework.stereotype.Component;
1314
import org.springframework.web.server.ServerWebExchange;
1415

15-
import java.util.Random;
16-
1716
import java.util.Date;
1817

1918
@Component
@@ -25,12 +24,17 @@ public class JWTUtils {
2524

2625
private JwtParser jwtParser;
2726

27+
private String base64EncodedSecret;
28+
2829
private final String TOKEN_HEADER = "Authorization";
2930
private final String TOKEN_PREFIX = "Bearer ";
3031

3132
@PostConstruct
3233
public void setup(){
33-
this.jwtParser = Jwts.parser().setSigningKey(authProperties.getApiKey().getSecret());
34+
base64EncodedSecret = Encoders.BASE64.encode(authProperties.getApiKey().getSecret().getBytes());
35+
this.jwtParser = Jwts.parserBuilder()
36+
.setSigningKey(base64EncodedSecret)
37+
.build();
3438
}
3539

3640
public String createToken(User user) {
@@ -39,10 +43,9 @@ public String createToken(User user) {
3943
.setIssuedAt(new Date());
4044
claims.put("userId", user.getId() );
4145
claims.put("createdBy", user.getName());
42-
String randomFactor = String.valueOf(new Random().nextLong(100000000L));
4346
return Jwts.builder()
4447
.setClaims(claims)
45-
.signWith(SignatureAlgorithm.HS256, authProperties.getApiKey().getSecret() + randomFactor)
48+
.signWith(SignatureAlgorithm.HS256, base64EncodedSecret)
4649
.compact();
4750
}
4851

‎server/api-service/lowcoder-server/src/main/resources/application-lowcoder.yml

+3-3
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,9 @@ spring:
33
mongodb:
44
authentication-database: admin
55
auto-index-creation: false
6-
uri: mongodb://192.168.8.100:27017/lowcoder?authSource=admin
6+
uri: mongodb://192.168.1.111:27017/lowcoder?authSource=admin
77
redis:
8-
url: redis://192.168.8.100:6379
8+
url: redis://192.168.1.111:6379
99
main:
1010
allow-bean-definition-overriding: true
1111
allow-circular-references: true
@@ -60,4 +60,4 @@ auth:
6060
secret: 123456789101112131415123456789101112131415123456789101112131415123456789101112131415
6161
email:
6262
enable: true
63-
enable-register: false
63+
enable-register: true

‎server/api-service/lowcoder-server/src/main/resources/selfhost/ce/application-selfhost.yml

+2
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@ common:
88
mode: ENTERPRISE
99

1010
auth:
11+
api-key:
12+
secret: ${LOWCODER_API_KEY_SECRET:123456789101112131415123456789101112131415123456789101112131415123456789101112131415}
1113
email:
1214
enable: ${LOGIN_CHANNEL_EMAIL:true}
1315
enable-register: ${ENABLE_USER_SIGN_UP:true}

‎server/api-service/lowcoder-server/src/main/resources/selfhost/ce/application.yml

+2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
auth:
2+
api-key:
3+
secret: ${LOWCODER_API_KEY_SECRET:123456789101112131415123456789101112131415123456789101112131415123456789101112131415}
24
email:
35
enable: true
46
enable-register: ${ENABLE_USER_SIGN_UP:true}

0 commit comments

Comments
 (0)