项目作者: ankitwasankar

项目描述 :
Micronaut 2.0 JWT - Securing Rest End Points | MySQL + JWT
高级语言: Java
项目地址: git://github.com/ankitwasankar/micronaut-2.0-jwt-example.git
创建时间: 2020-08-03T12:05:47Z
项目社区:https://github.com/ankitwasankar/micronaut-2.0-jwt-example

开源协议:

下载


Securing Rest Endpoints | Micronaut 2.0 | JWT | MySQL

  1. Micronaut Security + JWT token generation + MySQL
  2. Fetching JWT token and accessing secured endpoints using this bearer token.

Micronaut 2.0 - JWT token Example

How to use this example

  • Import project in Intellij or Eclipse
  • Update datasource in application.yml database details.
  • Execute database queries given below in MySQL database.
  • Run the Application
  • Verification: Test using postman

1. Execute database queries:

  1. drop database if exists demo;
  2. create database demo;
  3. use demo;
  4. create table auth_user ( id int auto_increment primary key, username varchar(100), password varchar(50));
  5. create table auth_role ( id int auto_increment primary key, name varchar(50), description varchar(200));
  6. create table auth_user_role ( auth_user_id int, auth_role_id int);
  7. insert into auth_user (username, password) values ('sherlock', 'password');
  8. insert into auth_role (name, description) values ('ADMIN', 'Admin user');
  9. insert into auth_role (name, description) values ('USER', 'User');
  10. insert into auth_user_role (auth_user_id, auth_role_id) values (1,1);

2. Using Postman to test the application

  • Get JWT Token by providing username and password:
  • Use JWT token to access secured rest end point:

References

Feature http-client documentation

Feature security-jwt documentation

Feature openapi documentation

Feature security documentation

Feature testcontainers documentation