1 package dk
.cbs
.soa
.soasi
.service
.tokenserver
.controller
;
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
;
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
;
19 @RequestMapping(value
= "/v1/api", produces
= "application/json")
21 @RequiredArgsConstructor
22 public class TokenServer
{
24 private final AuthService authService
;
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
);
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
);
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
);