Thanks to visit codestin.com
Credit goes to github.com

Skip to content

This tiny library let's you create an authentication microservice with Microprofile. You should provide your own implementation of UserService interface to fetch the user data.

License

Notifications You must be signed in to change notification settings

gdiazs/microprofile-jwt-login

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

27 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

microprofile-jwt-login

This library was built for Demo purposes it's not recommended at production.

This tiny library will let you add a simple auth mechanism. You must to provide your own implementation of UserService interface to tell to the login service where to fetch the user data.

By default this library uses JOSE implementation for JWT token creation. It has a password validation in order to validate the user credentials. It uses BCrypt with a salt to verify the encoded password.

On your Microprofile project

Maven Central

  <dependency>
    <groupId>io.github.gdiazs</groupId>
    <artifactId>microprofile-jwt-login</artifactId>
    <version>0.0.2</version>
  </dependency>

Create UserService implementation or use in memory approach for testing

Once you have imported this library in a Microprofile project built with https://start.microprofile.io/ you just need to configure a similar class like this. You can provide your own user service implementation if you want

   @Dependent
   public class AuthservicesConfig {

     @Produces
     public UserService userService() {

       UserServiceBuilder.userBuilder()
                 .addUser("gdiazs", "$2y$06$HJMVVcT0mBshzc9ZCLtJXuwi0R4CPuKGbJDGVlyGYAt6KnM9UfC6C", "admin", "tester")
                 .addUser("memo", "$2y$06$HJMVVcT0mBshzc9ZCLtJXuwi0R4CPuKGbJDGVlyGYAt6KnM9UfC6C", "developer");

       return UserServiceBuilder.build();
     }


     @Produces
     public PasswordEncoder passwordEncoder() {
       return new PasswordEncoderDefault(6);
     }
   }

Configure the Microprofile config properties

Don't forget add this properties

microprofile-config.properties

microprofile.jwt.secret=yoursecrethash
microprofile.jwt.privateKey=/privateKey.pem
microprofile.jwt.algorithm=RS256 # or HS256 depends on this the library uses secret or privateKey
microprofile.jwt.aud=web
microprofile.jwt.iss=https://server.example.com
microprofile.jwt.expiration=30000
microprofile.jwt.keyID=JWT-MP

Test your auth microservice

POST http://localhost:port/context/auth
{ 
  "username": "gdiazs",
  "password": "Test1234"
}

About

This tiny library let's you create an authentication microservice with Microprofile. You should provide your own implementation of UserService interface to fetch the user data.

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages