simter-jwt

Pure Java implementation for JSON Web Token (JWT)

License

License

MIT
GroupId

GroupId

tech.simter
ArtifactId

ArtifactId

simter-jwt
Last Version

Last Version

1.1.0
Release Date

Release Date

Type

Type

jar
Description

Description

simter-jwt
Pure Java implementation for JSON Web Token (JWT)
Project URL

Project URL

https://github.com/simter/simter-jwt
Project Organization

Project Organization

simter
Source Code Management

Source Code Management

https://github.com/simter/simter-jwt.git

Download simter-jwt

How to add to project

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

Dependencies

compile (1)

Group / Artifact Type Version
javax.json : javax.json-api jar 1.1.4

test (2)

Group / Artifact Type Version
org.junit.jupiter : junit-jupiter jar
com.owlike : genson jar 1.5

Project Modules

There are no modules declared in this project.

simter-jwt [中文]

Pure Java implementation for JSON Web Token (JWT) [RFC7519]

Installation

<dependency>
  <groupId>tech.simter</groupId>
  <artifactId>simter-jwt</artifactId>
  <version>1.0.0</version>
</dependency>

Requirement

  • Java 8+ - this component use java8 native Base64 and HMACSHA-256
  • At lease one JSR-353 provider (Java API for JSON Processing)
    e.g. Genson, Jackson, Glassfish

Usage

Create a JWT

// create a default header: 
// e.g. {"typ":"JWT","alg":"HS256"}
Header header = Header.DEFAULT;

// create a payload
// e.g. {"iss":"RJ","aud":"you","exp":1483200000,"iat":1451577600,"name":"tester"}
Payload payload = new Payload();

// set some registed claims
payload.issuer = "RJ";
payload.audience = "you";
payload.issuedAt = ZonedDateTime.now().toEpochSecond();
payload.expires = ZonedDateTime.now().plusMonths(1).toEpochSecond();

// add your public/private claims
payload.add("name", "tester");
...

// sign and encode with the secret key
// eg. [header].[payload].[signature]
String jwt = new JWT(header, payload).generate("the-secret-key");

Verify a JWT

// verify and decode to a JWT instance
JWT jwt = JWT.verify("[header].[payload].[signature]", "the-secret-key");

// get your public/private claims value
String name = jwt.payload.get("name");

Build

mvn clean package

Deploy

First take a look at simter-parent deploy config.

Deploy to LAN Nexus Repository

mvn clean deploy -Plan

Deploy to Sonatype Repository

mvn clean deploy -Psonatype

After deployed, login into https://oss.sonatype.org. Through Staging Repositories, search this package, then close and release it. After couple hours, it will be synced to Maven Central Repository.

Deploy to Bintray Repository

mvn clean deploy -Pbintray

Will deploy to https://api.bintray.com/maven/simter/maven/tech.simter:simter-jwt/;publish=1. So first create a package https://bintray.com/simter/maven/tech.simter:simter-jwt on Bintray. After deployed, check it from https://jcenter.bintray.com/tech/simter/simter-jwt.

References

tech.simter

Versions

Version
1.1.0
1.0.0
0.4.0
0.3.0
0.1.0