项目作者: akalu

项目描述 :
Vert.x microservice with JWT auth
高级语言: Java
项目地址: git://github.com/akalu/vertx-std-microservice.git
创建时间: 2021-05-18T14:23:34Z
项目社区:https://github.com/akalu/vertx-std-microservice

开源协议:

下载


Generic badge

About

This is a simple server application which implements a CR(UD) service with MongoDB as a backend and reactive API, built on the basis of Vert.x framework

Demonstrates the using of the following technologies:

  • Reactive authorization and JWT

  • Exposing public end points to access the data saved in the database

Public api contract:

Method Endpoint Secure Description
POST /register No register new user
GET /api/v1/token Yes get authorization token
GET /api/v1/:username Yes get users profile

Building

To launch your tests:

  1. mvn clean test

To package your application:

  1. mvn clean package

To run your application:

  1. java -cp ./target/vx-1.0.0-SNAPSHOT-fat.jar verticle.api.ProfileVerticle

Testing

Run all containers, register a user, then get a token and perform GET request for users profile.

The whole workflow can be presented as follows:

Registering a new user:

  1. POST /register HTTP/1.1
  2. > Host: localhost:4000
  3. > Content-Type: application/json
  4. > Accept: */*
  5. {
  6. "username": "Alisa",
  7. "password": "123",
  8. "city": "Amsterdam",
  9. "email": "alice@test.com",
  10. "deviceId": "2"
  11. }
  12. * upload completely sent off: 112 out of 112 bytes
  13. * Mark bundle as not supporting multiuse
  14. < HTTP/1.1 200 OK
  15. < vary: origin
  16. < content-length: 0

Getting token:

  1. POST /api/v1/token HTTP/1.1
  2. > Host: localhost:4000
  3. > Content-Type: application/json
  4. > Accept: */*
  5. {
  6. "username": "Alisa",
  7. "password":"123"
  8. }

Performing GET request to receive the profile:

  1. GET /api/v1/Alisa HTTP/1.1
  2. > Host: localhost:4000
  3. > Authorization: Bearer eyJ0eXAiOiJKV1QiLCJhbGciOiJSU.........ykA
  4. > Accept: */*

Reference