File tree Expand file tree Collapse file tree
spring-boot-jwt/src/main/java/com/akash/springboot/jwt Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1+ package com .akash .springboot .jwt ;
2+
3+ import org .springframework .http .ResponseEntity ;
4+ import org .springframework .web .bind .annotation .*;
5+
6+ import java .util .HashMap ;
7+ import java .util .Map ;
8+
9+ @ RestController
10+ @ RequestMapping ("/users" )
11+ public class UserController {
12+
13+ private Map <String , String > users = new HashMap <>();
14+
15+ @ PostMapping ("/login" )
16+ public ResponseEntity <?> login (@ RequestBody Map <String , String > user ) {
17+ String username = user .get ("username" );
18+ String password = user .get ("password" );
19+ users .put (username , password );
20+
21+ // TODO: Generate JWT token
22+
23+ Map <String , String > response = new HashMap <>();
24+ response .put ("token" , "demo-token" );
25+
26+ return ResponseEntity .ok (response );
27+ }
28+
29+
30+ @ PostMapping ("/tokenAuthentication" )
31+ public ResponseEntity <?> tokenAuthentication (@ RequestBody Map <String , String > request ) {
32+ String token = request .get ("token" );
33+
34+ //TODO: Validate token
35+ boolean isValid = true ;
36+
37+ Map <String , Boolean > response = new HashMap <>();
38+ response .put ("isValid" , isValid );
39+
40+ return ResponseEntity .ok (response );
41+ }
42+ }
You can’t perform that action at this time.
0 commit comments