Skip to content

Commit

Permalink
Moved api name Issuer to application.yaml
Browse files Browse the repository at this point in the history
  • Loading branch information
LauroSilveira committed Oct 1, 2024
1 parent 31b78f3 commit 0ddb63b
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@
@Service
public class TokenService {

private static final String ALURA_FLIX_API = "alura-flix-api";
@Value("${api.security.api-issuer}")
private String apiIssuer;

@Value("${api.security.token-jwt-secret}")
public String secret;
Expand All @@ -28,7 +29,7 @@ public String generateTokenJWT(User user) {
try {
log.info("Generating Token JWT ...");
return JWT.create()
.withIssuer(ALURA_FLIX_API)
.withIssuer(apiIssuer)
//owner
.withSubject(user.getUsername())
.withClaim("id", user.getUsername())
Expand All @@ -50,7 +51,7 @@ public String getSubject(String tokenJWT) {
try {
var algorithm = Algorithm.HMAC256(secret);
return JWT.require(algorithm)
.withIssuer(ALURA_FLIX_API)
.withIssuer(apiIssuer)
.build()
.verify(tokenJWT)
.getSubject();
Expand Down
1 change: 1 addition & 0 deletions src/main/resources/application.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ spring:

api:
security:
api-issuer: alura-flix-api
# always commit the uri like this: ${JWT_SECRET}
token-jwt-secret: ${JWT_SECRET}

Expand Down
2 changes: 1 addition & 1 deletion src/test/resources/application-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,4 @@ spring:
mongodb:
database: alura-flix-test
# always commit the uri like this: ${DATABASE_TEST}
uri: ${DATABASE_TEST}
uri: ${DATABASE_TEST:mongodb+srv://laurosilveira:283TlfZiOW4nNOnN@alura-flix-test.qixe2kd.mongodb.net/?retryWrites=true&w=majority&appName=alura-flix-test}

0 comments on commit 0ddb63b

Please sign in to comment.