Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Misc API Key Feature Updates #446

Merged
merged 1 commit into from
Oct 26, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions deploy/docker/docker-compose-multi.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ services:
DEFAULT_ORG_GROUP_COUNT: 100
DEFAULT_ORG_APP_COUNT: 1000
DEFAULT_DEVELOPER_COUNT: 50
LOWCODER_API_KEY_SECRET: "123456789101112131415123456789101112131415123456789101112131415123456789101112131415"
restart: unless-stopped
depends_on:
- mongodb
Expand Down
1 change: 1 addition & 0 deletions deploy/docker/docker-compose.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ services:
ENCRYPTION_PASSWORD: "lowcoder.org"
ENCRYPTION_SALT: "lowcoder.org"
CORS_ALLOWED_DOMAINS: "*"
LOWCODER_API_KEY_SECRET: "123456789101112131415123456789101112131415123456789101112131415123456789101112131415"
# api and node service parameters
LOWCODER_API_SERVICE_URL: "http://localhost:8080"
LOWCODER_NODE_SERVICE_URL: "http://localhost:6060"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import io.jsonwebtoken.JwtParser;
import io.jsonwebtoken.Jwts;
import io.jsonwebtoken.SignatureAlgorithm;
import io.jsonwebtoken.io.Encoders;
import jakarta.annotation.PostConstruct;
import lombok.extern.slf4j.Slf4j;
import org.lowcoder.domain.user.model.User;
Expand All @@ -12,8 +13,6 @@
import org.springframework.stereotype.Component;
import org.springframework.web.server.ServerWebExchange;

import java.util.Random;

import java.util.Date;

@Component
Expand All @@ -25,12 +24,17 @@ public class JWTUtils {

private JwtParser jwtParser;

private String base64EncodedSecret;

private final String TOKEN_HEADER = "Authorization";
private final String TOKEN_PREFIX = "Bearer ";

@PostConstruct
public void setup(){
this.jwtParser = Jwts.parser().setSigningKey(authProperties.getApiKey().getSecret());
base64EncodedSecret = Encoders.BASE64.encode(authProperties.getApiKey().getSecret().getBytes());
this.jwtParser = Jwts.parserBuilder()
.setSigningKey(base64EncodedSecret)
.build();
}

public String createToken(User user) {
Expand All @@ -39,10 +43,9 @@ public String createToken(User user) {
.setIssuedAt(new Date());
claims.put("userId", user.getId() );
claims.put("createdBy", user.getName());
String randomFactor = String.valueOf(new Random().nextLong(100000000L));
return Jwts.builder()
.setClaims(claims)
.signWith(SignatureAlgorithm.HS256, authProperties.getApiKey().getSecret() + randomFactor)
.signWith(SignatureAlgorithm.HS256, base64EncodedSecret)
.compact();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@ spring:
mongodb:
authentication-database: admin
auto-index-creation: false
uri: mongodb://192.168.8.100:27017/lowcoder?authSource=admin
uri: mongodb://192.168.1.111:27017/lowcoder?authSource=admin
redis:
url: redis://192.168.8.100:6379
url: redis://192.168.1.111:6379
main:
allow-bean-definition-overriding: true
allow-circular-references: true
Expand Down Expand Up @@ -60,4 +60,4 @@ auth:
secret: 123456789101112131415123456789101112131415123456789101112131415123456789101112131415
email:
enable: true
enable-register: false
enable-register: true
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ common:
mode: ENTERPRISE

auth:
api-key:
secret: ${LOWCODER_API_KEY_SECRET:123456789101112131415123456789101112131415123456789101112131415123456789101112131415}
email:
enable: ${LOGIN_CHANNEL_EMAIL:true}
enable-register: ${ENABLE_USER_SIGN_UP:true}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
auth:
api-key:
secret: ${LOWCODER_API_KEY_SECRET:123456789101112131415123456789101112131415123456789101112131415123456789101112131415}
email:
enable: true
enable-register: ${ENABLE_USER_SIGN_UP:true}
Expand Down