MicroProfile JWT Login

Library to enable JWT token generation for Microprofile Projects

License

License

GroupId

GroupId

io.github.gdiazs
ArtifactId

ArtifactId

microprofile-jwt-login
Last Version

Last Version

0.0.2
Release Date

Release Date

Type

Type

jar
Description

Description

MicroProfile JWT Login
Library to enable JWT token generation for Microprofile Projects
Project URL

Project URL

https://github.com/gdiazs/microprofile-jwt-login
Source Code Management

Source Code Management

http://github.com/gdiazs/microprofile-jwt-login/tree/master

Download microprofile-jwt-login

How to add to project

<!-- https://jarcasting.com/artifacts/io.github.gdiazs/microprofile-jwt-login/ -->
<dependency>
    <groupId>io.github.gdiazs</groupId>
    <artifactId>microprofile-jwt-login</artifactId>
    <version>0.0.2</version>
</dependency>
// https://jarcasting.com/artifacts/io.github.gdiazs/microprofile-jwt-login/
implementation 'io.github.gdiazs:microprofile-jwt-login:0.0.2'
// https://jarcasting.com/artifacts/io.github.gdiazs/microprofile-jwt-login/
implementation ("io.github.gdiazs:microprofile-jwt-login:0.0.2")
'io.github.gdiazs:microprofile-jwt-login:jar:0.0.2'
<dependency org="io.github.gdiazs" name="microprofile-jwt-login" rev="0.0.2">
  <artifact name="microprofile-jwt-login" type="jar" />
</dependency>
@Grapes(
@Grab(group='io.github.gdiazs', module='microprofile-jwt-login', version='0.0.2')
)
libraryDependencies += "io.github.gdiazs" % "microprofile-jwt-login" % "0.0.2"
[io.github.gdiazs/microprofile-jwt-login "0.0.2"]

Dependencies

compile (3)

Group / Artifact Type Version
com.nimbusds : nimbus-jose-jwt jar 5.7
org.bouncycastle : bcpkix-jdk15on jar 1.53
at.favre.lib : bcrypt jar 0.7.0

provided (1)

Group / Artifact Type Version
org.eclipse.microprofile : microprofile pom 1.2

Project Modules

There are no modules declared in this project.

microprofile-jwt-login

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

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

By default this library uses JOSE implementation to creates JWT. Has a password validation in order to validate user credentials. Uses BCrypt with salt to verify the encoded password. You can see the dependencies in pom.xml

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/ Just configure a similar class like this. You can provide your own user service implementation to fetch your user data.

   @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"
}

Versions

Version
0.0.2
0.0.1