Skip to content

Commit 6a057f3

Browse files
committed
Set configurable secret for parsing.
1 parent 14905fa commit 6a057f3

1 file changed

Lines changed: 7 additions & 3 deletions

File tree

jjwt/src/main/java/io/jsonwebtoken/jjwtfun/controller/StaticJWTController.java

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
import io.jsonwebtoken.Jwts;
66
import io.jsonwebtoken.SignatureAlgorithm;
77
import io.jsonwebtoken.jjwtfun.model.JwtResponse;
8+
import org.springframework.beans.factory.annotation.Value;
89
import org.springframework.web.bind.annotation.RequestMapping;
910
import org.springframework.web.bind.annotation.RequestParam;
1011
import org.springframework.web.bind.annotation.RestController;
@@ -18,6 +19,9 @@
1819
@RestController
1920
public class StaticJWTController extends BaseController {
2021

22+
@Value("#{ @environment['jjwtfun.secret'] ?: 'secret' }")
23+
String secret;
24+
2125
@RequestMapping(value = "/static-builder", method = GET)
2226
public JwtResponse fixedBuilder() throws UnsupportedEncodingException {
2327

@@ -38,10 +42,10 @@ public JwtResponse fixedBuilder() throws UnsupportedEncodingException {
3842
}
3943

4044
@RequestMapping(value = "/parser", method = GET)
41-
public JwtResponse fixedParser(@RequestParam String jws) throws UnsupportedEncodingException {
45+
public JwtResponse parser(@RequestParam String jwt) throws UnsupportedEncodingException {
4246
Jws<Claims> claims = Jwts.parser()
43-
.setSigningKey("secret".getBytes("UTF-8"))
44-
.parseClaimsJws(jws);
47+
.setSigningKey(secret.getBytes("UTF-8"))
48+
.parseClaimsJws(jwt);
4549

4650
return new JwtResponse(claims);
4751
}

0 commit comments

Comments
 (0)