项目作者: rmitula

项目描述 :
:lock: Sample Spring Security application with JWT authentication
高级语言: Java
项目地址: git://github.com/rmitula/spring-security-jwt.git
创建时间: 2018-11-05T21:41:52Z
项目社区:https://github.com/rmitula/spring-security-jwt

开源协议:

下载


spring-security-jwt

Technology stack

  • Java 10
  • Spring Boot
  • Spring Data
  • Spring Security
  • PostgreSQL / H2
  • Maven
  • Log4j
  • Lombok
  • Swagger

API Documentation

Signup

  1. POST: http://localhost:5000/api/auth/signup

Header

  1. Content-Type: application/json

Body

  1. {
  2. "name": "Jan Kowalski",
  3. "email": "email@example.com",
  4. "password": "password"
  5. }

Signup success

Status: 200

Body (Created user id)

  1. 1

Signup email already exists

Status: 409

Body (Created user id)

  1. {
  2. "code": 409,
  3. "message": "Email is already taken"
  4. }

Signup bad request

Status: 400

Body

  1. {
  2. "code": 400,
  3. "message": "error message..."
  4. }

Signin

  1. POST: http://localhost:5000/api/auth/signin

Header

  1. Content-Type: application/json

Body

  1. {
  2. "email": "email@example.com",
  3. "password": "password"
  4. }

Signin success

Status: 200

Body

  1. {
  2. "accessToken": "eyJhbGciOiJIUzUxMiJ9.eyJzdWIiOiIxIiwiaWF0IjoxNTQxNTA2MjA4LCJleHAiOjE1NDIxMTEwMDh9.xRU2vmXUvtHmrL_BDKm-rzTKd0Sv8BtPR3AmOO0ZgLnSXIT0EeDh1cN7lvrxM-H2fNuO4vJMJdOXV8By8E4BkQ",
  3. "tokenType": "Bearer"
  4. }

Signin email not found

Status: 404

Body

  1. {
  2. "code": 404,
  3. "message": "User not found [email: email@example.com]"
  4. }

Signin unauthorized

Status: 401

Body

  1. {
  2. "timestamp": "2018-11-11T17:37:12.573+0000",
  3. "status": 401,
  4. "error": "Unauthorized",
  5. "message": "Sorry, You're not authorized to access this resource.",
  6. "path": "/api/auth/signin"
  7. }

Current user

Logged in user credentials

  1. GET: http://localhost:5000/api/users/me

Header

  1. Authorization: Bearer eyJhbGciOiJIUzUxMiJ9.eyJzdWIiOiIxIiwiaWF0IjoxNTQxNTA2MjA4LCJleHAiOjE1NDIxMTEwMDh9.xRU2vmXUvtHmrL_BDKm-rzTKd0Sv8BtPR3AmOO0ZgLnSXIT0EeDh1cN7lvrxM-H2fNuO4vJMJdOXV8By8E4BkQ

Current user success

Status: 200

Body

  1. {
  2. "id": 1,
  3. "username": "email@example.com",
  4. "name": "Jan Kowalski"
  5. }

Current user - unauthorized

Status: 401

Body

  1. {
  2. "timestamp": "2018-11-11T17:26:42.886+0000",
  3. "status": 401,
  4. "error": "Unauthorized",
  5. "message": "Sorry, You're not authorized to access this resource.",
  6. "path": "/api/users/me"
  7. }