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