Skip to content

vinceh121/tokenize4j

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

16 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Tokenize for Java (and any JVM-based language)

License GitHub Workflow Status GitHub release (latest by date)

Installation

With Gradle:

repositories {
  maven { url 'https://jitpack.io' }
}
dependencies {
  implementation 'com.github.vinceh121:tokenize4j:...'
}

With Maven:

<repositories>
  <repository>
    <id>jitpack.io</id>
    <url>https://jitpack.io</url>
  </repository>
</repositories>
<dependency>
  <groupId>com.github.vinceh121</groupId>
  <artifactId>tokenize4j</artifactId>
  <version>...</version>
</dependency>

How to use it

public class Main {
    public static void main(String[] args) {
        Tokenize tokenize = new Tokenize("very secure private key".getBytes());

        // Generation
        Token token = tokenize.generateToken(account);
        System.out.println(token); // xxxxxxxx.xxxxxxxxxxx.xxxxxxxxx

        // Validation
        String rawToken = "xxxxxxxx.xxxxxxxxxxx.xxxxxxxxx";
        Token token;
        try {
            token = tokenize.validateToken(rawToken, id -> Database.fetchAccount(id));
        } catch (SecurityException e) {
            System.out.println("Invalid token signature!");
        }
    }
}

License

This implementation is licensed under the BSD-3-Clause license.