]> git.datanom.net - token-manager.git/blob - src/main/java/dk/cbs/soa/soasi/service/tokenserver/controller/TokenServer.java
initial commit
[token-manager.git] / src / main / java / dk / cbs / soa / soasi / service / tokenserver / controller / TokenServer.java
1 package dk.cbs.soa.soasi.service.tokenserver.controller;
2
3 import org.springframework.http.HttpStatus;
4 import org.springframework.http.ResponseEntity;
5 import org.springframework.web.bind.annotation.PostMapping;
6 import org.springframework.web.bind.annotation.RequestBody;
7 import org.springframework.web.bind.annotation.RequestMapping;
8 import org.springframework.web.bind.annotation.RestController;
9
10 import dk.cbs.soa.soasi.service.tokenserver.model.AuthCredential;
11 import dk.cbs.soa.soasi.service.tokenserver.model.Token;
12 import dk.cbs.soa.soasi.service.tokenserver.model.TokenPair;
13 import dk.cbs.soa.soasi.service.tokenserver.service.AuthService;
14 import io.swagger.v3.oas.annotations.Parameter;
15 import lombok.RequiredArgsConstructor;
16 import lombok.extern.slf4j.Slf4j;
17
18 @RestController
19 @RequestMapping(value = "/v1/api", produces = "application/json")
20 @Slf4j
21 @RequiredArgsConstructor
22 public class TokenServer {
23
24 private final AuthService authService;
25
26 @PostMapping("/auth")
27 public ResponseEntity<TokenPair> authenticate(
28 @Parameter(description = "AuthCredential must be digitally signed with a X.509 certifikate. Signature is part of credentials")
29 @RequestBody AuthCredential authCredential) {
30 return new ResponseEntity<TokenPair>(authService.getTokenPair(authCredential), HttpStatus.OK);
31 }
32
33 @PostMapping("/refresh")
34 public ResponseEntity<TokenPair> refresh(
35 @Parameter(description = "Refresh token to be reneewed. A refresh token can max be used 5 times before aauirering a new from authenticate")
36 @RequestBody String refreshToken) {
37 return new ResponseEntity<TokenPair>(authService.getRefreshPair(refreshToken), HttpStatus.OK);
38 }
39
40 @PostMapping("/token")
41 public ResponseEntity<Token> getToken(
42 @Parameter(description = "Refresh token to create access from")
43 @RequestBody String refreshToken) {
44 return new ResponseEntity<Token>(authService.getAccessToken(refreshToken), HttpStatus.OK);
45 }
46 }
This page took 0.498799 seconds and 6 git commands to generate.