Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,11 @@
import org.springframework.security.authentication.UsernamePasswordAuthenticationToken;
import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.security.core.annotation.AuthenticationPrincipal;

@RestController
@RequestMapping(value = "/auth", produces = {"application/json"})
Expand Down Expand Up @@ -61,4 +63,15 @@ public ResponseEntity register(@RequestBody RegisterDTO data) {

return ResponseEntity.ok().build();
}

/**
* Example of what an endpoint can looks like after login
*
* @param Authorization header containing jwt token
* @return ResponseEntity of the logged in user
*/
@GetMapping(value= "/example", consumes = MediaType.APPLICATION_JSON_VALUE)
public ResponseEntity<String> validate(@AuthenticationPrincipal User user) {
return ResponseEntity.ok(user.getName());
}
}