remove token
This commit is contained in:
parent
948e35ae12
commit
d6939de924
@ -5,6 +5,7 @@ import java.time.Duration;
|
||||
|
||||
import javax.inject.Inject;
|
||||
import javax.ws.rs.CookieParam;
|
||||
import javax.ws.rs.DELETE;
|
||||
import javax.ws.rs.GET;
|
||||
import javax.ws.rs.Path;
|
||||
import javax.ws.rs.Produces;
|
||||
@ -66,11 +67,11 @@ public class TokenRessource {
|
||||
return Response.status(Response.Status.FORBIDDEN).build();
|
||||
}
|
||||
// Create a JWT token signed using the 'HS256' algorithm
|
||||
String newJwtCookie = Jwt.issuer("https://example.com/issuer").upn(name).groups(users.roles).claim(Claims.kid, users.id.toString()).expiresIn(Duration.ofMinutes(1)).sign();
|
||||
String newJwtCookie = Jwt.issuer("https://example.com/issuer").upn(name).groups(users.roles).claim(Claims.kid, users.id.toString()).expiresIn(Duration.ofMinutes(5)).sign();
|
||||
// or create a JWT token encrypted using the 'A256KW' algorithm
|
||||
// Jwt.upn("alice").encryptWithSecret(secret);
|
||||
String nameEncoded = Base64.toBase64String(name.getBytes(StandardCharsets.UTF_8));
|
||||
return Response.status(Response.Status.CREATED).cookie(new NewCookie(new Cookie("jwt", newJwtCookie), "Token JWT", 60, false), new NewCookie(new Cookie("user", nameEncoded), "Username", 60, false)).build();
|
||||
return Response.status(Response.Status.CREATED).cookie(new NewCookie(new Cookie("jwt", newJwtCookie), "Token JWT", 300, false), new NewCookie(new Cookie("user", nameEncoded), "Username", 60, false)).build();
|
||||
}
|
||||
// All mp.jwt and smallrye.jwt properties are still effective, only the verification key is customized.
|
||||
try {
|
||||
@ -87,4 +88,15 @@ public class TokenRessource {
|
||||
return Response.status(Response.Status.OK).build();
|
||||
}
|
||||
|
||||
@DELETE
|
||||
public Response deleteToken(@CookieParam("jwt") String jwtCookie) {
|
||||
if(jwtCookie == null){
|
||||
return Response.status(Response.Status.BAD_REQUEST).build();
|
||||
}
|
||||
|
||||
return Response.ok().cookie(new NewCookie(new Cookie("jwt", null), "", 0, false)).build();
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
@ -29,6 +29,6 @@ quarkus.redis.hosts=redis://redis:6379
|
||||
|
||||
quarkus.http.cors=true
|
||||
quarkus.http.origins=http://localhost:8084
|
||||
quarkus.http.cors.methods=GET,PUT,POST
|
||||
quarkus.http.cors.methods=GET,PUT,POST,DELETE
|
||||
quarkus.http.cors.headers=accept,authorization,content-type,x-requested-with,x-foobar
|
||||
quarkus.http.cors.access-control-allow-credentials=true
|
Loading…
x
Reference in New Issue
Block a user