Skip to content
Snippets Groups Projects
Commit 422a36f7 authored by Manuel Spuhler's avatar Manuel Spuhler
Browse files

JWT wip

parent e90dacc1
No related branches found
No related tags found
No related merge requests found
......@@ -93,3 +93,4 @@ services:
workflows:
workflowUrl: {{ default .Env.WORKFLOW_URL "http://localhost:9090" }}
workflowAuthorization: {{ default .Env.WORKFLOW_AUTHORIZATION "undefined" }}
JWTSecret: {{ default .Env.JWT_SECRET "secret" }}
......@@ -7,7 +7,10 @@ import org.springframework.http.ResponseEntity;
import org.springframework.http.HttpStatus;
import com.auth0.jwt.algorithms.Algorithm;
import com.auth0.jwt.JWT;
import eu.hbp.mip.model.User;
import eu.hbp.mip.model.UserInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.*;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
......@@ -19,17 +22,25 @@ public class JWTApi {
private static final Logger LOGGER = LoggerFactory.getLogger(JWTApi.class);
@Autowired
private UserInfo userInfo;
@Value("#{'${services.workflows.JWTSecret}'}")
private String JWTSecret;
@ApiOperation(value = "Create a JSON Web Token", response = String.class)
@RequestMapping(method = RequestMethod.POST)
public ResponseEntity<String> createJWT() {
LOGGER.info("Create a JSON Web Token");
Algorithm algorithm = Algorithm.HMAC512("secret");
String token = JWT.create()
.withIssuer("mip.humanbrainproject.eu")
.withSubject("subj")
.sign(algorithm);
User user = userInfo.getUser();
Algorithm algorithm = Algorithm.HMAC512(JWTSecret);
String token = JWT.create().withIssuer("mip.humanbrainproject.eu").withSubject(user.getEmail()).sign(algorithm);
LOGGER.info(algorithm.toString());
LOGGER.info(token);
return ResponseEntity.status(HttpStatus.CREATED).body(token);
}
......
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment