dropwizard-auth-jwt

A simple to use dropwizard jwt auth library

License

License

Categories

Categories

DropWizard Container Microservices
GroupId

GroupId

com.github.mambabosso
ArtifactId

ArtifactId

dropwizard-auth-jwt
Last Version

Last Version

1.2
Release Date

Release Date

Type

Type

jar
Description

Description

dropwizard-auth-jwt
A simple to use dropwizard jwt auth library
Project URL

Project URL

https://github.com/Mambabosso/dropwizard-auth-jwt
Source Code Management

Source Code Management

https://github.com/Mambabosso/dropwizard-auth-jwt

Download dropwizard-auth-jwt

How to add to project

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

Dependencies

compile (1)

Group / Artifact Type Version
com.auth0 : java-jwt jar 3.10.2

provided (3)

Group / Artifact Type Version
io.dropwizard : dropwizard-auth jar 2.0.8
com.fasterxml.jackson.core : jackson-databind jar 2.10.3
org.projectlombok : lombok jar 1.18.12

Project Modules

There are no modules declared in this project.

dropwizard-auth-jwt

Maven

<dependency>
    <groupId>com.github.mambabosso</groupId>
    <artifactId>dropwizard-auth-jwt</artifactId>
    <version>1.1</version>
</dependency>

Getting started

Example

Example Code - Link

Configuration

@Valid
@NotNull
private JwtConfiguration jwtConfiguration;

@JsonProperty("jwt")
public JwtConfiguration getJwtConfiguration() {
    return jwtConfiguration;
}

@JsonProperty("jwt")
public void setJwtConfiguration(JwtConfiguration jwtConfiguration) {
    this.jwtConfiguration = jwtConfiguration;
}

Application

In this example the class 'User' is our principal

authenticator = DefaultJwtAuthenticator.create(configuration.getJwtConfiguration(), User.class);

OAuthCredentialAuthFilter.Builder<User> oauthBuilder = new OAuthCredentialAuthFilter.Builder<>();
oauthBuilder.setAuthenticator(authenticator);
oauthBuilder.setPrefix("Bearer");

environment.jersey().register(new AuthDynamicFeature(oauthBuilder.buildAuthFilter()));

Tokens

Encode

Optional<String> token = authenticator.getJwtHandler().encode(userObject);
// do something with the token

Decode

Optional<User> user = authenticator.getJwtHandler().decode(token);
// do something with the user

Credits

Versions

Version
1.2
1.1