diff --git a/.circleci/config.yml b/.circleci/config.yml
deleted file mode 100644
index 909f794..0000000
--- a/.circleci/config.yml
+++ /dev/null
@@ -1,62 +0,0 @@
-version: 2
-jobs:
- java_7_build:
- docker:
- - image: openjdk:7u121-jdk
- steps:
- - checkout
- - run: chmod +x gradlew
- # Download and cache dependencies
- - restore_cache:
- keys:
- - v1-dependencies-{{ checksum "build.gradle" }}
- # fallback to using the latest cache if no exact match is found
- - v1-dependencies-
- # run tests!
- - run: ./gradlew clean check jacocoTestReport --continue --console=plain
- - run:
- name: Upload Coverage
- when: on_success
- command: bash <(curl -s https://codecov.io/bash)
- - save_cache:
- paths:
- - ~/.m2
- key: v1-dependencies-{{ checksum "build.gradle" }}
- environment:
- GRADLE_OPTS: '-Dorg.gradle.jvmargs="-Xmx2048m -XX:+HeapDumpOnOutOfMemoryError"'
- _JAVA_OPTIONS: "-Xms512m -Xmx1024m"
- TERM: dumb
-
- java_8_build:
- docker:
- - image: openjdk:8-jdk
- steps:
- - checkout
- - run: chmod +x gradlew
- # Download and cache dependencies
- - restore_cache:
- keys:
- - v1-dependencies-{{ checksum "build.gradle" }}
- # fallback to using the latest cache if no exact match is found
- - v1-dependencies-
- # run tests!
- - run: ./gradlew clean check jacocoTestReport --continue --console=plain
- - run:
- name: Upload Coverage
- when: on_success
- command: bash <(curl -s https://codecov.io/bash)
- - save_cache:
- paths:
- - ~/.m2
- key: v1-dependencies-{{ checksum "build.gradle" }}
- environment:
- GRADLE_OPTS: '-Dorg.gradle.jvmargs="-Xmx2048m -XX:+HeapDumpOnOutOfMemoryError"'
- _JAVA_OPTIONS: "-Xms512m -Xmx1024m"
- TERM: dumb
-
-workflows:
- version: 2
- build:
- jobs:
- - java_7_build
- - java_8_build
diff --git a/.gitignore b/.gitignore
index ab35b85..999c86d 100644
--- a/.gitignore
+++ b/.gitignore
@@ -1,90 +1,173 @@
-# Created by .ignore support plugin (hsz.mobi)
-### OSX template
-*.DS_Store
-.AppleDouble
-.LSOverride
-
-# Icon must end with two \r
-Icon
-
-# Thumbnails
-._*
-
-# Files that might appear in the root of a volume
-.DocumentRevisions-V100
-.fseventsd
-.Spotlight-V100
-.TemporaryItems
-.Trashes
-.VolumeIcon.icns
-.com.apple.timemachine.donotpresent
-
-# Directories potentially created on remote AFP share
-.AppleDB
-.AppleDesktop
-Network Trash Folder
-Temporary Items
-.apdisk
-
-
-### JetBrains template
-# Covers JetBrains IDEs: IntelliJ, RubyMine, PhpStorm, AppCode, PyCharm, CLion, Android Studio and Webstorm
-# Reference: https://intellij-support.jetbrains.com/hc/en-us/articles/206544839
-
-# Intellij
-.idea/
-*.iml
-
-## File-based project format:
-*.iws
-
-## Plugin-specific files:
-
-# IntelliJ
-/out/
-/lib/out/
+# Maven Shaded Jar Artifact
+dependency-reduced-pom.xml
-# mpeltonen/sbt-idea plugin
-.idea_modules/
+node_modules
-# JIRA plugin
-atlassian-ide-plugin.xml
+# Ignore Eclipse stuff
+.project
+.settings
+.classpath
-# Crashlytics plugin (for Android Studio and IntelliJ)
-com_crashlytics_export_strings.xml
-crashlytics.properties
-crashlytics-build.properties
-fabric.properties
+# Ignore Java and IntelliJ IDEA stuff
+.idea
+target
+*.iml
-### Java template
-*.class
+## Ignore Visual Studio temporary files, build results, and
+## files generated by popular Visual Studio add-ons.
-# Mobile Tools for Java (J2ME)
-.mtj.tmp/
+packages
-# Package Files #
-*.jar
-*.war
-*.ear
+# User-specific files
+*.suo
+*.user
+*.sln.docstates
-# virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml
-hs_err_pid*
+# Build results
-### Gradle template
-.gradle
+[Dd]ebug/
+[Rr]elease/
+x64/
build/
-target/
-dependency-reduced-pom.xml
-
-# Ignore Gradle GUI config
-gradle-app.setting
-
-# Avoid ignoring Gradle wrapper jar file (.jar files are usually ignored)
-!gradle-wrapper.jar
-
-# Cache of project
-.gradletasknamecache
-
-# # Work around https://youtrack.jetbrains.com/issue/IDEA-116898
-# gradle/wrapper/gradle-wrapper.properties
-
+[Bb]in/
+[Oo]bj/
+
+# Enable "build/" folder in the NuGet Packages folder since NuGet packages use it for MSBuild targets
+!packages/*/build/
+
+# MSTest test Results
+[Tt]est[Rr]esult*/
+[Bb]uild[Ll]og.*
+
+*_i.c
+*_p.c
+*.ilk
+*.meta
+*.obj
+*.pch
+*.pdb
+*.pgc
+*.pgd
+*.rsp
+*.sbr
+*.tlb
+*.tli
+*.tlh
+*.tmp
+*.tmp_proj
+*.log
+*.vspscc
+*.vssscc
+.builds
+*.pidb
+*.log
+*.scc
+
+# Visual C++ cache files
+ipch/
+*.aps
+*.ncb
+*.opensdf
+*.sdf
+*.cachefile
+
+# Visual Studio profiler
+*.psess
+*.vsp
+*.vspx
+
+# Guidance Automation Toolkit
+*.gpState
+
+# ReSharper is a .NET coding add-in
+_ReSharper*/
+*.[Rr]e[Ss]harper
+
+# TeamCity is a build add-in
+_TeamCity*
+
+# DotCover is a Code Coverage Tool
+*.dotCover
+
+# NCrunch
+*.ncrunch*
+.*crunch*.local.xml
+
+# Installshield output folder
+[Ee]xpress/
+
+# DocProject is a documentation generator add-in
+DocProject/buildhelp/
+DocProject/Help/*.HxT
+DocProject/Help/*.HxC
+DocProject/Help/*.hhc
+DocProject/Help/*.hhk
+DocProject/Help/*.hhp
+DocProject/Help/Html2
+DocProject/Help/html
+
+# Click-Once directory
+publish/
+
+# Publish Web Output
+*.Publish.xml
+
+# NuGet Packages Directory
+## TODO: If you have NuGet Package Restore enabled, uncomment the next line
+#packages/
+
+# Windows Azure Build Output
+csx
+*.build.csdef
+
+# Windows Store app package directory
+AppPackages/
+
+# Others
+sql/
+*.Cache
+ClientBin/
+[Ss]tyle[Cc]op.*
+~$*
+*~
+*.dbmdl
+*.[Pp]ublish.xml
+*.pfx
+*.publishsettings
+
+# RIA/Silverlight projects
+Generated_Code/
+
+# Backup & report files from converting an old project file to a newer
+# Visual Studio version. Backup files are not needed, because we have git ;-)
+_UpgradeReport_Files/
+Backup*/
+UpgradeLog*.XML
+UpgradeLog*.htm
+
+# SQL Server files
+App_Data/*.mdf
+App_Data/*.ldf
+
+
+#LightSwitch generated files
+GeneratedArtifacts/
+_Pvt_Extensions/
+ModelManifest.xml
+
+# =========================
+# Windows detritus
+# =========================
+
+# Windows image file caches
+Thumbs.db
+ehthumbs.db
+
+# Folder config file
+Desktop.ini
+
+# Recycle Bin used on file shares
+$RECYCLE.BIN/
+
+# Mac desktop service store files
+.DS_Store
diff --git a/.travis.yml b/.travis.yml
new file mode 100644
index 0000000..ef0da2f
--- /dev/null
+++ b/.travis.yml
@@ -0,0 +1,8 @@
+language: java
+jdk:
+- oraclejdk7
+branches:
+ only:
+ - master
+after_success:
+ - bash <(curl -s https://codecov.io/bash)
\ No newline at end of file
diff --git a/AUTHORS.md b/AUTHORS.md
deleted file mode 100644
index ac4aa97..0000000
--- a/AUTHORS.md
+++ /dev/null
@@ -1,6 +0,0 @@
-### This is the list of JWTs for Node authors for copyright purposes.
-### This does not necessarily list everyone who has contributed code, since in
-### some cases, their employer may be the copyright holder. To see the full list
-### of contributors, see the revision history in source control.
-
-Auth0 LLC, Google LLC
diff --git a/CHANGELOG.md b/CHANGELOG.md
deleted file mode 100644
index d62283b..0000000
--- a/CHANGELOG.md
+++ /dev/null
@@ -1,110 +0,0 @@
-Copyright (c) 2017 The Authors of 'JWTS for Java'
-
-Permission is hereby granted, free of charge, to any person obtaining a copy of
-this software and associated documentation files (the "Software"), to deal in
-the Software without restriction, including without limitation the rights to
-use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
-the Software, and to permit persons to whom the Software is furnished to do so,
-subject to the following conditions:
-
-The above copyright notice and this permission notice shall be included in all
-copies or substantial portions of the Software.
-
-THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
-IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
-FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
-COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
-IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
-CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
-# Change Log
-
-## [3.3.0](https://github.com/auth0/java-jwt/tree/3.3.0) (2017-11-06)
-[Full Changelog](https://github.com/auth0/java-jwt/compare/3.2.0...3.3.0)
-**Closed issues**
-- Wrong ES256 signature length [\#187](https://github.com/auth0/java-jwt/issues/187)
-
-**Fixed**
-- Rework ECDSA [\#212](https://github.com/auth0/java-jwt/pull/212) ([lbalmaceda](https://github.com/lbalmaceda))
-- Instantiate exception only when required [\#198](https://github.com/auth0/java-jwt/pull/198) ([rumdidumdum](https://github.com/rumdidumdum))
-
-## [3.2.0](https://github.com/auth0/java-jwt/tree/3.2.0) (2017-05-04)
-[Full Changelog](https://github.com/auth0/java-jwt/compare/3.1.0...3.2.0)
-**Closed issues**
-- Claim.isNull() returns true for JSON Object constructed claims [\#160](https://github.com/auth0/java-jwt/issues/160)
-- Incorrectly rejects whitespace after JSON header as invalid [\#144](https://github.com/auth0/java-jwt/issues/144)
-- No token type [\#136](https://github.com/auth0/java-jwt/issues/136)
-- Timestamps are limited by Integer/int to 2038-01-19T04:14:07.000+0100 [\#132](https://github.com/auth0/java-jwt/issues/132)
-
-**Added**
-- Refactor KeyProvider to receive the "Key Id" [\#167](https://github.com/auth0/java-jwt/pull/167) ([lbalmaceda](https://github.com/lbalmaceda))
-- Add Sign/Verify of Long type claims [\#157](https://github.com/auth0/java-jwt/pull/157) ([vrancic](https://github.com/vrancic))
-- added date validation dedicated exception [\#155](https://github.com/auth0/java-jwt/pull/155) ([Spyna](https://github.com/Spyna))
-- Allow to get a Claim as Map [\#152](https://github.com/auth0/java-jwt/pull/152) ([lbalmaceda](https://github.com/lbalmaceda))
-- Add Algorithm KeyProvider interface [\#149](https://github.com/auth0/java-jwt/pull/149) ([lbalmaceda](https://github.com/lbalmaceda))
-- Instantiate RSA/EC Algorithm with both keys [\#147](https://github.com/auth0/java-jwt/pull/147) ([lbalmaceda](https://github.com/lbalmaceda))
-- Add Key Id setter and set JWT Type after signing [\#138](https://github.com/auth0/java-jwt/pull/138) ([lbalmaceda](https://github.com/lbalmaceda))
-
-**Changed**
-- Change the JWT.decode() return type to DecodedJWT [\#150](https://github.com/auth0/java-jwt/pull/150) ([lbalmaceda](https://github.com/lbalmaceda))
-
-**Fixed**
-- Fix Claim.isNull() method for JSON Objects [\#161](https://github.com/auth0/java-jwt/pull/161) ([lbalmaceda](https://github.com/lbalmaceda))
-- Accept blanks, new line and carriage returns on JSON [\#151](https://github.com/auth0/java-jwt/pull/151) ([lbalmaceda](https://github.com/lbalmaceda))
-- Fix Date value conversion [\#137](https://github.com/auth0/java-jwt/pull/137) ([lbalmaceda](https://github.com/lbalmaceda))
-
-## [3.1.0](https://github.com/auth0/java-jwt/tree/3.1.0) (2017-01-04)
-[Full Changelog](https://github.com/auth0/java-jwt/compare/3.0.2...3.1.0)
-
-**Added**
-- Make Clock customization accessible for verification [\#125](https://github.com/auth0/java-jwt/pull/125) ([lbalmaceda](https://github.com/lbalmaceda))
-- Add getter for all the Payload's Claims [\#124](https://github.com/auth0/java-jwt/pull/124) ([lbalmaceda](https://github.com/lbalmaceda))
-- Accept Array type on verification and creation. [\#123](https://github.com/auth0/java-jwt/pull/123) ([lbalmaceda](https://github.com/lbalmaceda))
-
-## [3.0.2](https://github.com/auth0/java-jwt/tree/3.0.2) (2016-12-13)
-[Full Changelog](https://github.com/auth0/java-jwt/compare/3.0.1...3.0.2)
-
-**Fixed**
-- Add targetCompatibility to 1.7 [\#121](https://github.com/auth0/java-jwt/pull/121) ([hzalaz](https://github.com/hzalaz))
-
-## [3.0.1](https://github.com/auth0/java-jwt/tree/3.0.0) (2016-12-05)
-[Full Changelog](https://github.com/auth0/java-jwt/compare/3.0.0...3.0.1)
-
-Update to allow sync with Maven Central
-
-## [3.0.0](https://github.com/auth0/java-jwt/tree/3.0.0) (2016-12-05)
-
-Reimplemented java-jwt to improve API and include more signing algorithms
-
-## Installation
-
-### Maven
-
-```xml
-
- com.auth0
- java-jwt
- 3.0.0
-
-```
-
-### Gradle
-
-```gradle
-compile 'com.auth0:java-jwt:3.0.0'
-```
-
-## Available Algorithms
-
-The library implements JWT Verification and Signing using the following algorithms:
-
-| JWS | Algorithm | Description |
-| :-------------: | :-------------: | :----- |
-| HS256 | HMAC256 | HMAC with SHA-256 |
-| HS384 | HMAC384 | HMAC with SHA-384 |
-| HS512 | HMAC512 | HMAC with SHA-512 |
-| RS256 | RSA256 | RSASSA-PKCS1-v1_5 with SHA-256 |
-| RS384 | RSA384 | RSASSA-PKCS1-v1_5 with SHA-384 |
-| RS512 | RSA512 | RSASSA-PKCS1-v1_5 with SHA-512 |
-| ES256 | ECDSA256 | ECDSA with curve P-256 and SHA-256 |
-| ES384 | ECDSA384 | ECDSA with curve P-384 and SHA-384 |
-| ES512 | ECDSA512 | ECDSA with curve P-521 and SHA-512 |
diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md
deleted file mode 100644
index 6d364e1..0000000
--- a/CONTRIBUTING.md
+++ /dev/null
@@ -1,23 +0,0 @@
-# How to Contribute
-
-We'd love to accept your patches and contributions to this project. There are
-just a few small guidelines you need to follow.
-
-## Contributor License Agreement
-
-Contributions to this project must be accompanied by a Contributor License
-Agreement. You (or your employer) retain the copyright to your contribution,
-this simply gives us permission to use and redistribute your contributions as
-part of the project. Head over to to see
-your current agreements on file or to sign a new one.
-
-You generally only need to submit a CLA once, so if you've already submitted one
-(even if it was for a different project), you probably don't need to do it
-again.
-
-## Code reviews
-
-All submissions, including submissions by project members, require review. We
-use GitHub pull requests for this purpose. Consult
-[GitHub Help](https://help.github.com/articles/about-pull-requests/) for more
-information on using pull requests.
\ No newline at end of file
diff --git a/LICENSE b/LICENSE.txt
similarity index 99%
rename from LICENSE
rename to LICENSE.txt
index 4a7a13a..bcd1854 100644
--- a/LICENSE
+++ b/LICENSE.txt
@@ -18,4 +18,4 @@ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
-SOFTWARE.
\ No newline at end of file
+SOFTWARE.
diff --git a/README.md b/README.md
index 487c06d..93236bb 100644
--- a/README.md
+++ b/README.md
@@ -1,13 +1,11 @@
-# JWTs for Java
-This is not an officially supported Google product
+# Java JWT
-[](https://circleci.com/gh/auth0/java-jwt/tree/master)
-[](https://codecov.io/github/auth0/java-jwt)
+[](https://travis-ci.org/auth0/java-jwt)
+[](https://codecov.io/github/auth0/java-jwt)
[](http://doge.mit-license.org)
+[](http://search.maven.org/#search%7Cga%7C1%7Ca%3A%22java-jwt%22)
-A Java implementation of [JSON Web Tokens (draft-ietf-oauth-json-web-token-08)](http://self-issued.info/docs/draft-ietf-oauth-json-web-token.html).
-
-If you're looking for an **Android** version of the JWT Decoder take a look at our [JWTDecode.Android](https://github.com/auth0/JWTDecode.Android) library.
+An implementation of [JSON Web Tokens](http://self-issued.info/docs/draft-ietf-oauth-json-web-token.html) developed against `draft-ietf-oauth-json-web-token-08`.
## Installation
@@ -17,450 +15,74 @@ If you're looking for an **Android** version of the JWT Decoder take a look at o
com.auth0java-jwt
- 3.3.0
+ 2.2.1
```
### Gradle
```gradle
-compile 'com.auth0:java-jwt:3.3.0'
+compile 'com.auth0:java-jwt:2.2.1'
```
-## Available Algorithms
-
-The library implements JWT Verification and Signing using the following algorithms:
-
-| JWS | Algorithm | Description |
-| :-------------: | :-------------: | :----- |
-| HS256 | HMAC256 | HMAC with SHA-256 |
-| HS384 | HMAC384 | HMAC with SHA-384 |
-| HS512 | HMAC512 | HMAC with SHA-512 |
-| RS256 | RSA256 | RSASSA-PKCS1-v1_5 with SHA-256 |
-| RS384 | RSA384 | RSASSA-PKCS1-v1_5 with SHA-384 |
-| RS512 | RSA512 | RSASSA-PKCS1-v1_5 with SHA-512 |
-| ES256 | ECDSA256 | ECDSA with curve P-256 and SHA-256 |
-| ES384 | ECDSA384 | ECDSA with curve P-384 and SHA-384 |
-| ES512 | ECDSA512 | ECDSA with curve P-521 and SHA-512 |
-
-## Supported token profile types
-
-#### Basic Token
-
-- Standard claims: *iss, sub, iat, jti*
-- Nonstandard claims: *aud, exp, nbf*
-
-#### Extended Token
-- Standard claims: *name, email, picture, iss, sub, iat*
-- Nonstandard claims: *aud, exp, nbf*
-
-#### Access Token
-- Standard claims: *iss, sub, iat*
-- Nonstandard claims: *aud, exp*
-
-#### Facebook Token
-- Standard claims: *user_id, app_id, issued_at*
-- Nonstandard claims: *expired_at*
-
-#### Google Token
-- Standard claims: *name, email, picture, iss, sub, iat*
-- Nonstandard claims: *exp, aud*
-
-#### Implicit Access Token
-- Standard claims: *iss, sub, iat*
-- Nonstandard claims: *aud*
+## Usage
-#### Refresh Token
-- Standard claims: *refresh_token, access_token*
-
-#### Risc Token
-- Standard claims: *jti, iss, sub, iat*
-- Nonstandard claims: *aud, nbf, exp*
-
-#### Scoped Access Token
-- Standard claims: *iss, sub, iat, scope*
-- Nonstandard claims: *aud, exp*
-
-### Pick the Algorithm
-
-The Algorithm defines how a token is signed and verified. It can be instantiated with the raw value of the secret in the case of HMAC algorithms, or the key pairs or `KeyProvider` in the case of RSA and ECDSA algorithms. Once created, the instance is reusable for token signing and verification operations.
-
-When using RSA or ECDSA algorithms and you just need to **sign** JWTs you can avoid specifying a Public Key by passing a `null` value. The same can be done with the Private Key when you just need to **verify** JWTs.
-
-
-#### Using static secrets or keys:
+### Sign JWT (HS256)
```java
-//HMAC
-Algorithm algorithmHS = Algorithm.HMAC256("secret");
-
-//RSA
-RSAPublicKey publicKey = //Get the key instance
-RSAPrivateKey privateKey = //Get the key instance
-Algorithm algorithmRS = Algorithm.RSA256(publicKey, privateKey);
-```
-
-#### Using a KeyProvider:
+final String issuer = "https://mydomain.com/";
+final String secret = "{{secret used for signing}}";
-By using a `KeyProvider` you can change in runtime the key used either to verify the token signature or to sign a new token for RSA or ECDSA algorithms. This is achieved by implementing either `RSAKeyProvider` or `ECDSAKeyProvider` methods:
+final long iat = System.currentTimeMillis() / 1000L; // issued at claim
+final long exp = iat + 60L; // expires claim. In this case the token expires in 60 seconds
-- `getPublicKeyById(String kid)`: Its called during token signature verification and it should return the key used to verify the token. If key rotation is being used, e.g. [JWK](https://tools.ietf.org/html/rfc7517) it can fetch the correct rotation key using the id. (Or just return the same key all the time).
-- `getPrivateKey()`: Its called during token signing and it should return the key that will be used to sign the JWT.
-- `getPrivateKeyId()`: Its called during token signing and it should return the id of the key that identifies the one returned by `getPrivateKey()`. This value is preferred over the one set in the `JWTCreator.Builder#withKeyId(String)` method. If you don't need to set a `kid` value avoid instantiating an Algorithm using a `KeyProvider`.
+final JWTSigner signer = new JWTSigner(secret);
+final HashMap claims = new HashMap();
+claims.put("iss", issuer);
+claims.put("exp", exp);
+claims.put("iat", iat);
-
-The following snippet uses example classes showing how this would work:
-
-
-```java
-final JwkStore jwkStore = new JwkStore("{JWKS_FILE_HOST}");
-final RSAPrivateKey privateKey = //Get the key instance
-final String privateKeyId = //Create an Id for the above key
-
-RSAKeyProvider keyProvider = new RSAKeyProvider() {
- @Override
- public RSAPublicKey getPublicKeyById(String kid) {
- //Received 'kid' value might be null if it wasn't defined in the Token's header
- RSAPublicKey publicKey = jwkStore.get(kid);
- return (RSAPublicKey) publicKey;
- }
-
- @Override
- public RSAPrivateKey getPrivateKey() {
- return privateKey;
- }
-
- @Override
- public String getPrivateKeyId() {
- return privateKeyId;
- }
-};
-
-Algorithm algorithm = Algorithm.RSA256(keyProvider);
-//Use the Algorithm to create and verify JWTs.
+final String jwt = signer.sign(claims);
```
-> For simple key rotation using JWKs try the [jwks-rsa-java](https://github.com/auth0/jwks-rsa-java) library.
-
-
-### Create and Sign a Token
-
-You'll first need to create a `JWTCreator` instance by calling `JWT.create()`. Use the builder to define the custom Claims your token needs to have. Finally to get the String token call `sign()` and pass the `Algorithm` instance.
-
-* Example using `HS256`
+### Verify JWT (HS256)
```java
+final String secret = "{{secret used for signing}}";
try {
- Algorithm algorithm = Algorithm.HMAC256("secret");
- String token = JWT.create()
- .withIssuer("auth0")
- .sign(algorithm);
-} catch (UnsupportedEncodingException exception){
- //UTF-8 encoding not supported
-} catch (JWTCreationException exception){
- //Invalid Signing configuration / Couldn't convert Claims.
+ final JWTVerifier verifier = new JWTVerifier(secret);
+ final Map claims= verifier.verify(jwt);
+} catch (JWTVerifyException e) {
+ // Invalid Token
}
```
-* Example using `RS256`
+### Validate aud & iss claims
```java
-RSAPublicKey publicKey = //Get the key instance
-RSAPrivateKey privateKey = //Get the key instance
+final String secret = "{{secret used for signing}}";
try {
- Algorithm algorithm = Algorithm.RSA256(publicKey, privateKey);
- String token = JWT.create()
- .withIssuer("auth0")
- .sign(algorithm);
-} catch (JWTCreationException exception){
- //Invalid Signing configuration / Couldn't convert Claims.
+ final JWTVerifier verifier = new JWTVerifier(secret, "{{my-audience}}", "{{my-issuer}}");
+ final Map claims= verifier.verify(jwt);
+} catch (JWTVerifyException e) {
+ // Invalid Token
}
```
-If a Claim couldn't be converted to JSON or the Key used in the signing process was invalid a `JWTCreationException` will raise.
-
-NOTE: Each token has a NoneAlgorithm boolean value which is set to False by default unless set explicitly.
-
-```java
-GoogleJwtCreator.build().setIsNoneAlgorithmAllowed(true)
-```
-
-If the none algorithm property is set to true as done above, the following error will be thrown when algorithm 'none' is used:
-"None algorithm isn't allowed".
-
-### Serializing a token
-
-When signing, you can encode via a 16-byte, 32-byte, the standard 64-byte, and a JSON encoding.
-When you call the method standard `sign()` as in the example above, the token is 64-byte encoded.
-To encode via a 16-byte, call `signBase16Encoding()`, via a 32-byte, call `signBase32Encoding()`, and
-via a JSON encoding, call `signJSONEncoding()`.
-
-### Verify a Token
-
-You'll first need to create a `Verification` instance by calling `JWT.require()` and passing the `Algorithm` instance. Once you have the `Verification` instance, you can call the corresponding verifier method. For the example of Google,
-you would have a `GoogleVerificiation` instance that has inherited from the `Verification` instance in order to call `createVerifierForGoogle()`, and you would pass in the claims that you would want to be verified.
-Once you call `build`, you would get back a `JWT` object and with that, you would call `decode()` while passing in the token that was created after signing. You will get back a `DecodedJWT` object, which contains all of the claims, and you can verify
-those claims against what's the expected claims by calling `verifyClaims()`.
-
-* Example using `HS256`
-
-```java
-String token = "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXUyJ9.eyJpc3MiOiJhdXRoMCJ9.AbIJTDMFc7yUa5MhvcP03nJPyCPzZtQcGEp-zWfOkEE";
-Algorithm algorithm = Algorithm.HMAC256("secret");
-GoogleVerification verification = GoogleJWT.require(algorithm);
-JWT verifier = verification.createVerifierForGoogle(PICTURE, EMAIL, asList("accounts.fake.com"), asList("audience"),
- NAME, 1, 1).build();
-DecodedJWT jwt = verifier.decode(token);
-Map claims = jwt.getClaims();
-verifyClaims(claims, exp);
-```
-
-* Example using `RS256`
-
-```java
-String token = "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXUyJ9.eyJpc3MiOiJhdXRoMCJ9.AbIJTDMFc7yUa5MhvcP03nJPyCPzZtQcGEp-zWfOkEE";
-RSAPublicKey publicKey = //Get the key instance
-RSAPrivateKey privateKey = //Get the key instance
-
-Algorithm algorithm = Algorithm.RSA256(publicKey, privateKey);
-GoogleVerification verification = GoogleJWT.require(algorithm);
-JWT verifier = verification.createVerifierForGoogle(PICTURE, EMAIL, asList("accounts.fake.com"), asList("audience"),
- NAME, 1, 1).build();
-DecodedJWT jwt = verifier.decode(token);
-Map claims = jwt.getClaims();
-verifyClaims(claims, exp);
-```
-
-If the token has a Claim requirement that has not been met, an `InvalidClaimException` will raise.
-If the token has an invalid signature, an `AlgorithmMismatchException` will raise.
-
-### Deserializing a token
-
-In order to recover the DecodedJWT after signing, you need to decode with the appropriate decode method
-corresponding to the appropriate encode method. For the standard 64-byte encoding, to recover the DecodedJWT,
-you call `decode()` as in the example above. When you encode via 16-bytes, you call `decode16Bytes()`,
-via 32-bytes, call `decode32Bytes()`, and via a JSON encoding, call `decodeJSON()`.
-
-#### Time Validation
-
-The JWT token may include DateNumber fields that can be used to validate that:
-* The token was issued in a past date `"iat" < TODAY`
-* The token hasn't expired yet `"exp" > TODAY` and
-* The token can already be used. `"nbf" > TODAY`
-
-When verifying a token the time validation occurs automatically, resulting in a `JWTVerificationException` being throw when the values are invalid. If any of the previous fields are missing they won't be considered in this validation.
-
-To specify a **nbf value** in which the Token should still be considered valid, use the `withNbf()` method in the respective `Creator` builder and pass a Date object. This applies to every item listed above.
-**NOTE:** `Nbf` and `iat` date values should be in the past, but the `exp` value should be in the future.
-```java
-Verification verifier = JWT.require(algorithm)
- .withNbf(new Date(2016,1,1))
- .build();
-```
-
-You can also specify a custom value for a given Date claim and override the default one for only that claim.
-
-```java
-Verification verifier = JWT.require(algorithm)
- .withNbf(new Date(2016,1,1))
- .withExp(new Date(2100,1,1))
- .build();
-```
-
-If you need to test this behaviour in your lib/app cast the `Verification` instance to a `BaseVerification` to gain visibility of the `verification.build()` method that accepts a custom `Clock`. e.g.:
-
-```java
-BaseVerification verification = (BaseVerification) JWT.require(algorithm)
- .acceptLeeway(1)
- .acceptExpiresAt(5);
-Clock clock = new CustomClock(); //Must implement Clock interface
-JWT verifier = verification.build(clock);
-```
-
-### Decode a Token
-
-This example is for an Implicit JWT token and can be applied to all the types of tokens:
-```java
-String token = "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOlsic3ViamVjdCJdLCJpc3MiOlsiYWNjb3VudHMuZmFrZS5jb20iXSwiYXVkIjoiYXVkaWVuY2UiLCJpYXQiOi0xMjQ1MjgxNTI3fQ.-eRoMolUy7PnEcpvfs-jTEvP6qagBZ1G_lqp1jY3Nqg";
-Verification verification = ImplicitJWT.require(algorithm);
-JWT verifier = verification.createVerifierForImplicit(asList("accounts.fake.com"), asList("audience"), 1).build();
-DecodedJWT jwt = verifier.decode(token);
-```
-
-If the token has an invalid syntax or the header or payload are not JSONs, a `JWTDecodeException` will raise.
-
-
-### Header Claims
-
-#### Algorithm ("alg")
-
-Returns the Algorithm value or null if it's not defined in the Header.
-
-```java
-String algorithm = jwt.getAlgorithm();
-```
-
-#### Type ("typ")
-
-Returns the Type value or null if it's not defined in the Header.
-
-```java
-String type = jwt.getType();
-```
-
-#### Content Type ("cty")
-
-Returns the Content Type value or null if it's not defined in the Header.
-
-```java
-String contentType = jwt.getContentType();
-```
-
-#### Key Id ("kid")
-
-Returns the Key Id value or null if it's not defined in the Header.
-
-```java
-String keyId = jwt.getKeyId();
-```
-
-#### Private Claims
-
-Additional Claims defined in the token's Header can be obtained by calling `getHeaderClaim()` and passing the Claim name. A Claim will always be returned, even if it can't be found. You can check if a Claim's value is null by calling `claim.isNull()`.
-
-```java
-Claim claim = jwt.getHeaderClaim("owner");
-```
-
-When creating a Token with the `JWTCreator.init()` you can specify header Claims by calling `withHeader()` and passing both the map of claims.
-
-```java
-Map headerClaims = new HashMap();
-headerClaims.put("owner", "auth0");
-String token = JWTCreator.init()
- .withHeader(headerClaims)
- .sign(algorithm);
-```
-
-> The `alg` and `typ` values will always be included in the Header after the signing process.
-
-
-### Payload Claims
-
-#### Issuer ("iss")
-
-Returns the Issuer value or null if it's not defined in the Payload.
-
-```java
-String issuer = jwt.getIssuer();
-```
-
-#### Subject ("sub")
-
-Returns the Subject value or null if it's not defined in the Payload.
-
-```java
-String subject = jwt.getSubject();
-```
-
-#### Audience ("aud")
-
-Returns the Audience value or null if it's not defined in the Payload.
-
-```java
-List audience = jwt.getAudience();
-```
-
-#### Expiration Time ("exp")
-
-Returns the Expiration Time value or null if it's not defined in the Payload.
-
-```java
-Date expiresAt = jwt.getExpiresAt();
-```
-
-#### Not Before ("nbf")
-
-Returns the Not Before value or null if it's not defined in the Payload.
-
-```java
-Date notBefore = jwt.getNotBefore();
-```
-
-#### Issued At ("iat")
-
-Returns the Issued At value or null if it's not defined in the Payload.
-
-```java
-Date issuedAt = jwt.getIssuedAt();
-```
-
-#### JWT ID ("jti")
-
-Returns the JWT ID value or null if it's not defined in the Payload.
-
-```java
-String id = jwt.getId();
-```
-
-#### Nonstandard Claims
-
-Nonstandard Claims defined in the token's Payload can be obtained by calling `getClaims()` or `getClaim()` and passing the Claim name. A Claim will always be returned, even if it can't be found. You can check if a Claim's value is null by calling `claim.isNull()`.
-
-```java
-Map claims = jwt.getClaims(); //Key is the Claim name
-Claim claim = claims.get("isAdmin");
-```
-
-or
-
-```java
-Claim claim = jwt.getClaim("isAdmin");
-```
-
-When creating an Implicit Token for example with the `ImplicitJwtCreator.build()` you can specify a custom Claim by calling `withNonStandardClaim()` and passing both the name and the value.
-
-```java
-String token = ImplicitJwtCreator.build()
- .withNonStandardClaim("nonStandardClaim", 123)
- .withArrayClaim("array", new Integer[]{1, 2, 3})
- .sign(algorithm);
-```
-
-**NOTE:** Nonstandard claims aside from `aud`, `exp`, and `nbf` do not need to verified.
-
-> Currently supported classes for custom JWT Claim creation and verification are: Boolean, Integer, Double, String, Date and Arrays of type String and Integer.
-
-
-### Claim Class
-The Claim class is a wrapper for the Claim values. It allows you to get the Claim as different class types. The available helpers are:
-
-#### Primitives
-* **asBoolean()**: Returns the Boolean value or null if it can't be converted.
-* **asInt()**: Returns the Integer value or null if it can't be converted.
-* **asDouble()**: Returns the Double value or null if it can't be converted.
-* **asLong()**: Returns the Long value or null if it can't be converted.
-* **asString()**: Returns the String value or null if it can't be converted.
-* **asDate()**: Returns the Date value or null if it can't be converted. This must be a NumericDate (Unix Epoch/Timestamp). Note that the [JWT Standard](https://tools.ietf.org/html/rfc7519#section-2) specified that all the *NumericDate* values must be in seconds.
-
-#### Custom Classes and Collections
-To obtain a Claim as a Collection you'll need to provide the **Class Type** of the contents to convert from.
-* **as(class)**: Returns the value parsed as **Class Type**. For collections you should use the `asArray` and `asList` methods.
-* **asMap()**: Returns the value parsed as **Map**.
-* **asArray(class)**: Returns the value parsed as an Array of elements of type **Class Type**, or null if the value isn't a JSON Array.
-* **asList(class)**: Returns the value parsed as a List of elements of type **Class Type**, or null if the value isn't a JSON Array.
+### Why another JSON Web Token implementation for Java?
-If the values can't be converted to the given **Class Type** a `JWTDecodeException` will raise.
+We believe existing JWT implementations in Java are either too complex or not tested enough.
+This library aims to be simple and achieve the right level of abstraction.
## Issue Reporting
-If you have found a bug or if you have a feature request, please report them at this repository issues section. Please do not report security vulnerabilities on the public GitHub issue tracker.
+If you have found a bug or if you have a feature request, please report them at this repository issues section. Please do not report security vulnerabilities on the public GitHub issue tracker. The [Responsible Disclosure Program](https://auth0.com/whitehat) details the procedure for disclosing security issues.
-## Authors
+## Author
-Auth0 LLC, Google LLC
+[Auth0](https://auth0.com/)
## License
-This project is licensed under the MIT license. See the [LICENSE](LICENSE) file for more info.
+This project is licensed under the MIT license. See the [LICENSE](LICENSE.txt) file for more info.
diff --git a/build.gradle b/build.gradle
deleted file mode 100644
index b18f759..0000000
--- a/build.gradle
+++ /dev/null
@@ -1,19 +0,0 @@
-// Top-level build file where you can add configuration options common to all sub-projects/modules.
-
-buildscript {
- repositories {
- jcenter()
- }
- dependencies {
- classpath 'com.android.tools.build:gradle:2.2.2'
- classpath 'com.jfrog.bintray.gradle:gradle-bintray-plugin:1.7'
- }
-}
-
-allprojects {
- group = 'com.auth0'
-
- repositories {
- jcenter()
- }
-}
diff --git a/.codecov.yml b/codecov.yml
similarity index 100%
rename from .codecov.yml
rename to codecov.yml
diff --git a/gradle.properties b/gradle.properties
deleted file mode 100644
index aac7c9b..0000000
--- a/gradle.properties
+++ /dev/null
@@ -1,17 +0,0 @@
-# Project-wide Gradle settings.
-
-# IDE (e.g. Android Studio) users:
-# Gradle settings configured through the IDE *will override*
-# any settings specified in this file.
-
-# For more details on how to configure your build environment visit
-# http://www.gradle.org/docs/current/userguide/build_environment.html
-
-# Specifies the JVM arguments used for the daemon process.
-# The setting is particularly useful for tweaking memory settings.
-org.gradle.jvmargs=-Xmx1536m
-
-# When configured, Gradle will run in incubating parallel mode.
-# This option should only be used with decoupled projects. More details, visit
-# http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects
-# org.gradle.parallel=true
diff --git a/gradle/wrapper/gradle-wrapper.jar b/gradle/wrapper/gradle-wrapper.jar
deleted file mode 100644
index 13372ae..0000000
Binary files a/gradle/wrapper/gradle-wrapper.jar and /dev/null differ
diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties
deleted file mode 100644
index 04e285f..0000000
--- a/gradle/wrapper/gradle-wrapper.properties
+++ /dev/null
@@ -1,6 +0,0 @@
-#Mon Dec 28 10:00:20 PST 2015
-distributionBase=GRADLE_USER_HOME
-distributionPath=wrapper/dists
-zipStoreBase=GRADLE_USER_HOME
-zipStorePath=wrapper/dists
-distributionUrl=https\://services.gradle.org/distributions/gradle-2.14.1-all.zip
diff --git a/gradlew b/gradlew
deleted file mode 100755
index 9d82f78..0000000
--- a/gradlew
+++ /dev/null
@@ -1,160 +0,0 @@
-#!/usr/bin/env bash
-
-##############################################################################
-##
-## Gradle start up script for UN*X
-##
-##############################################################################
-
-# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
-DEFAULT_JVM_OPTS=""
-
-APP_NAME="Gradle"
-APP_BASE_NAME=`basename "$0"`
-
-# Use the maximum available, or set MAX_FD != -1 to use that value.
-MAX_FD="maximum"
-
-warn ( ) {
- echo "$*"
-}
-
-die ( ) {
- echo
- echo "$*"
- echo
- exit 1
-}
-
-# OS specific support (must be 'true' or 'false').
-cygwin=false
-msys=false
-darwin=false
-case "`uname`" in
- CYGWIN* )
- cygwin=true
- ;;
- Darwin* )
- darwin=true
- ;;
- MINGW* )
- msys=true
- ;;
-esac
-
-# Attempt to set APP_HOME
-# Resolve links: $0 may be a link
-PRG="$0"
-# Need this for relative symlinks.
-while [ -h "$PRG" ] ; do
- ls=`ls -ld "$PRG"`
- link=`expr "$ls" : '.*-> \(.*\)$'`
- if expr "$link" : '/.*' > /dev/null; then
- PRG="$link"
- else
- PRG=`dirname "$PRG"`"/$link"
- fi
-done
-SAVED="`pwd`"
-cd "`dirname \"$PRG\"`/" >/dev/null
-APP_HOME="`pwd -P`"
-cd "$SAVED" >/dev/null
-
-CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar
-
-# Determine the Java command to use to start the JVM.
-if [ -n "$JAVA_HOME" ] ; then
- if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
- # IBM's JDK on AIX uses strange locations for the executables
- JAVACMD="$JAVA_HOME/jre/sh/java"
- else
- JAVACMD="$JAVA_HOME/bin/java"
- fi
- if [ ! -x "$JAVACMD" ] ; then
- die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME
-
-Please set the JAVA_HOME variable in your environment to match the
-location of your Java installation."
- fi
-else
- JAVACMD="java"
- which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
-
-Please set the JAVA_HOME variable in your environment to match the
-location of your Java installation."
-fi
-
-# Increase the maximum file descriptors if we can.
-if [ "$cygwin" = "false" -a "$darwin" = "false" ] ; then
- MAX_FD_LIMIT=`ulimit -H -n`
- if [ $? -eq 0 ] ; then
- if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then
- MAX_FD="$MAX_FD_LIMIT"
- fi
- ulimit -n $MAX_FD
- if [ $? -ne 0 ] ; then
- warn "Could not set maximum file descriptor limit: $MAX_FD"
- fi
- else
- warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT"
- fi
-fi
-
-# For Darwin, add options to specify how the application appears in the dock
-if $darwin; then
- GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\""
-fi
-
-# For Cygwin, switch paths to Windows format before running java
-if $cygwin ; then
- APP_HOME=`cygpath --path --mixed "$APP_HOME"`
- CLASSPATH=`cygpath --path --mixed "$CLASSPATH"`
- JAVACMD=`cygpath --unix "$JAVACMD"`
-
- # We build the pattern for arguments to be converted via cygpath
- ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null`
- SEP=""
- for dir in $ROOTDIRSRAW ; do
- ROOTDIRS="$ROOTDIRS$SEP$dir"
- SEP="|"
- done
- OURCYGPATTERN="(^($ROOTDIRS))"
- # Add a user-defined pattern to the cygpath arguments
- if [ "$GRADLE_CYGPATTERN" != "" ] ; then
- OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)"
- fi
- # Now convert the arguments - kludge to limit ourselves to /bin/sh
- i=0
- for arg in "$@" ; do
- CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -`
- CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option
-
- if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition
- eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"`
- else
- eval `echo args$i`="\"$arg\""
- fi
- i=$((i+1))
- done
- case $i in
- (0) set -- ;;
- (1) set -- "$args0" ;;
- (2) set -- "$args0" "$args1" ;;
- (3) set -- "$args0" "$args1" "$args2" ;;
- (4) set -- "$args0" "$args1" "$args2" "$args3" ;;
- (5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;;
- (6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;;
- (7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;;
- (8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;;
- (9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;;
- esac
-fi
-
-# Split up the JVM_OPTS And GRADLE_OPTS values into an array, following the shell quoting and substitution rules
-function splitJvmOpts() {
- JVM_OPTS=("$@")
-}
-eval splitJvmOpts $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS
-JVM_OPTS[${#JVM_OPTS[*]}]="-Dorg.gradle.appname=$APP_BASE_NAME"
-
-exec "$JAVACMD" "${JVM_OPTS[@]}" -classpath "$CLASSPATH" org.gradle.wrapper.GradleWrapperMain "$@"
diff --git a/gradlew.bat b/gradlew.bat
deleted file mode 100644
index aec9973..0000000
--- a/gradlew.bat
+++ /dev/null
@@ -1,90 +0,0 @@
-@if "%DEBUG%" == "" @echo off
-@rem ##########################################################################
-@rem
-@rem Gradle startup script for Windows
-@rem
-@rem ##########################################################################
-
-@rem Set local scope for the variables with windows NT shell
-if "%OS%"=="Windows_NT" setlocal
-
-@rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
-set DEFAULT_JVM_OPTS=
-
-set DIRNAME=%~dp0
-if "%DIRNAME%" == "" set DIRNAME=.
-set APP_BASE_NAME=%~n0
-set APP_HOME=%DIRNAME%
-
-@rem Find java.exe
-if defined JAVA_HOME goto findJavaFromJavaHome
-
-set JAVA_EXE=java.exe
-%JAVA_EXE% -version >NUL 2>&1
-if "%ERRORLEVEL%" == "0" goto init
-
-echo.
-echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
-echo.
-echo Please set the JAVA_HOME variable in your environment to match the
-echo location of your Java installation.
-
-goto fail
-
-:findJavaFromJavaHome
-set JAVA_HOME=%JAVA_HOME:"=%
-set JAVA_EXE=%JAVA_HOME%/bin/java.exe
-
-if exist "%JAVA_EXE%" goto init
-
-echo.
-echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME%
-echo.
-echo Please set the JAVA_HOME variable in your environment to match the
-echo location of your Java installation.
-
-goto fail
-
-:init
-@rem Get command-line arguments, handling Windowz variants
-
-if not "%OS%" == "Windows_NT" goto win9xME_args
-if "%@eval[2+2]" == "4" goto 4NT_args
-
-:win9xME_args
-@rem Slurp the command line arguments.
-set CMD_LINE_ARGS=
-set _SKIP=2
-
-:win9xME_args_slurp
-if "x%~1" == "x" goto execute
-
-set CMD_LINE_ARGS=%*
-goto execute
-
-:4NT_args
-@rem Get arguments from the 4NT Shell from JP Software
-set CMD_LINE_ARGS=%$
-
-:execute
-@rem Setup the command line
-
-set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar
-
-@rem Execute Gradle
-"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS%
-
-:end
-@rem End local scope for the variables with windows NT shell
-if "%ERRORLEVEL%"=="0" goto mainEnd
-
-:fail
-rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of
-rem the _cmd.exe /c_ return code!
-if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1
-exit /b 1
-
-:mainEnd
-if "%OS%"=="Windows_NT" endlocal
-
-:omega
diff --git a/lib/.gitignore b/lib/.gitignore
deleted file mode 100644
index 796b96d..0000000
--- a/lib/.gitignore
+++ /dev/null
@@ -1 +0,0 @@
-/build
diff --git a/lib/build.gradle b/lib/build.gradle
deleted file mode 100644
index 2a7694c..0000000
--- a/lib/build.gradle
+++ /dev/null
@@ -1,64 +0,0 @@
-apply plugin: 'jacoco'
-apply plugin: 'java'
-apply from: '../scripts/release.gradle'
-apply from: '../scripts/maven.gradle'
-apply from: '../scripts/bintray.gradle'
-
-logger.lifecycle("Using version ${version} for ${group}.${name}")
-
-auth0 {
- name "java jwt"
- repo "java-jwt"
- description "Java implementation of JSON Web Token (JWT)"
- url 'http://www.jwt.io'
- developer {
- id = "auth0"
- name = "Auth0"
- email = "oss@auth0.com"
- }
- developer {
- id = "lbalmaceda"
- name = "Luciano Balmaceda"
- email = "luciano.balmaceda@auth0.com"
- }
- developer {
- id = "hzalaz"
- name = "Hernan Zalazar"
- email = "hernan@auth0.com"
- }
-}
-
-compileJava {
- sourceCompatibility '1.7'
- targetCompatibility '1.7'
-}
-
-dependencies {
- compile 'com.fasterxml.jackson.core:jackson-databind:2.9.2'
- compile 'commons-codec:commons-codec:1.11'
- compile 'com.google.code.gson:gson:2.8.2'
- testCompile 'org.bouncycastle:bcprov-jdk15on:1.58'
- testCompile 'junit:junit:4.12'
- testCompile 'net.jodah:concurrentunit:0.4.3'
- testCompile 'org.hamcrest:java-hamcrest:2.0.0.0'
- testCompile 'org.mockito:mockito-core:2.11.0'
-}
-
-jacocoTestReport {
- reports {
- xml.enabled = true
- html.enabled = true
- }
-}
-
-test {
- testLogging {
- events "skipped", "failed", "standardError"
- exceptionFormat "short"
- }
-}
-
-task clean(type: Delete) {
- delete rootProject.buildDir
- delete 'CHANGELOG.md.release'
-}
diff --git a/lib/src/main/java/com/auth0/jwt/ClockImpl.java b/lib/src/main/java/com/auth0/jwt/ClockImpl.java
deleted file mode 100644
index 250c6a0..0000000
--- a/lib/src/main/java/com/auth0/jwt/ClockImpl.java
+++ /dev/null
@@ -1,35 +0,0 @@
-// Copyright (c) 2017 The Authors of 'JWTS for Java'
-//
-// Permission is hereby granted, free of charge, to any person obtaining a copy of
-// this software and associated documentation files (the "Software"), to deal in
-// the Software without restriction, including without limitation the rights to
-// use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
-// the Software, and to permit persons to whom the Software is furnished to do so,
-// subject to the following conditions:
-//
-// The above copyright notice and this permission notice shall be included in all
-// copies or substantial portions of the Software.
-//
-// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
-// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
-// FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
-// COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
-// IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
-// CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
-
-package com.auth0.jwt;
-
-import com.auth0.jwt.interfaces.Clock;
-
-import java.util.Date;
-
-public final class ClockImpl implements Clock {
-
- public ClockImpl() {
- }
-
- @Override
- public Date getToday() {
- return new Date();
- }
-}
diff --git a/lib/src/main/java/com/auth0/jwt/JWTDecoder.java b/lib/src/main/java/com/auth0/jwt/JWTDecoder.java
deleted file mode 100644
index 7a967fb..0000000
--- a/lib/src/main/java/com/auth0/jwt/JWTDecoder.java
+++ /dev/null
@@ -1,164 +0,0 @@
-// Copyright (c) 2017 The Authors of 'JWTS for Java'
-//
-// Permission is hereby granted, free of charge, to any person obtaining a copy of
-// this software and associated documentation files (the "Software"), to deal in
-// the Software without restriction, including without limitation the rights to
-// use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
-// the Software, and to permit persons to whom the Software is furnished to do so,
-// subject to the following conditions:
-//
-// The above copyright notice and this permission notice shall be included in all
-// copies or substantial portions of the Software.
-//
-// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
-// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
-// FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
-// COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
-// IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
-// CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
-
-package com.auth0.jwt;
-
-import com.auth0.jwt.creators.EncodeType;
-import com.auth0.jwt.creators.JWTCreator;
-import com.auth0.jwt.exceptions.JWTDecodeException;
-import com.auth0.jwt.impl.JWTParser;
-import com.auth0.jwt.interfaces.Claim;
-import com.auth0.jwt.interfaces.DecodedJWT;
-import com.auth0.jwt.interfaces.Header;
-import com.auth0.jwt.interfaces.Payload;
-import org.apache.commons.codec.binary.Base32;
-import org.apache.commons.codec.binary.Base64;
-import org.apache.commons.codec.binary.Hex;
-import org.apache.commons.codec.binary.StringUtils;
-
-import java.net.URLDecoder;
-import java.net.URLEncoder;
-import java.util.Date;
-import java.util.List;
-import java.util.Map;
-
-/**
- * The JWTDecoder class holds the decode method to parse a given JWT token into it's JWT representation.
- */
-@SuppressWarnings("WeakerAccess")
-public final class JWTDecoder implements DecodedJWT {
-
- private final String[] parts;
- private final Header header;
- private final Payload payload;
-
- public JWTDecoder(String jwt, EncodeType encodeType) throws Exception {
- parts = TokenUtils.splitToken(jwt);
- final JWTParser converter = new JWTParser();
- String headerJson = null;
- String payloadJson = null;
- switch (encodeType) {
- case Base16:
- headerJson = URLDecoder.decode(new String(Hex.decodeHex(parts[0])), "UTF-8");
- payloadJson = URLDecoder.decode(new String(Hex.decodeHex(parts[1])), "UTF-8");
- break;
- case Base32:
- Base32 base32 = new Base32();
- headerJson = URLDecoder.decode(new String(base32.decode(parts[0]), "UTF-8"));
- payloadJson = URLDecoder.decode(new String(base32.decode(parts[1]), "UTF-8"));
- break;
- case Base64:
- headerJson = StringUtils.newStringUtf8(Base64.decodeBase64(parts[0]));
- payloadJson = StringUtils.newStringUtf8(Base64.decodeBase64(parts[1]));
- break;
- }
- header = converter.parseHeader(headerJson);
- payload = converter.parsePayload(payloadJson);
- }
-
- @Override
- public String getAlgorithm() {
- return header.getAlgorithm();
- }
-
- @Override
- public String getType() {
- return header.getType();
- }
-
- @Override
- public String getContentType() {
- return header.getContentType();
- }
-
- @Override
- public String getKeyId() {
- return header.getKeyId();
- }
-
- @Override
- public Claim getHeaderClaim(String name) {
- return header.getHeaderClaim(name);
- }
-
- @Override
- public List getIssuer() {
- return payload.getIssuer();
- }
-
- @Override
- public List getSubject() {
- return payload.getSubject();
- }
-
- @Override
- public List getAudience() {
- return payload.getAudience();
- }
-
- @Override
- public Date getExpiresAt() {
- return payload.getExpiresAt();
- }
-
- @Override
- public Date getNotBefore() {
- return payload.getNotBefore();
- }
-
- @Override
- public Date getIssuedAt() {
- return payload.getIssuedAt();
- }
-
- @Override
- public String getId() {
- return payload.getId();
- }
-
- @Override
- public Claim getClaim(String name) {
- return payload.getClaim(name);
- }
-
- @Override
- public Map getClaims() {
- return payload.getClaims();
- }
-
- @Override
- public String getHeader() {
- return parts[0];
- }
-
- @Override
- public String getPayload() {
- return parts[1];
- }
-
- @Override
- public String getSignature() {
- return parts[2];
- }
-
- @Override
- public String getToken() {
- return String.format("%s.%s.%s", parts[0], parts[1], parts[2]);
- }
-}
diff --git a/lib/src/main/java/com/auth0/jwt/TokenUtils.java b/lib/src/main/java/com/auth0/jwt/TokenUtils.java
deleted file mode 100644
index ed691be..0000000
--- a/lib/src/main/java/com/auth0/jwt/TokenUtils.java
+++ /dev/null
@@ -1,44 +0,0 @@
-// Copyright (c) 2017 The Authors of 'JWTS for Java'
-//
-// Permission is hereby granted, free of charge, to any person obtaining a copy of
-// this software and associated documentation files (the "Software"), to deal in
-// the Software without restriction, including without limitation the rights to
-// use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
-// the Software, and to permit persons to whom the Software is furnished to do so,
-// subject to the following conditions:
-//
-// The above copyright notice and this permission notice shall be included in all
-// copies or substantial portions of the Software.
-//
-// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
-// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
-// FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
-// COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
-// IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
-// CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
-
-package com.auth0.jwt;
-
-import com.auth0.jwt.exceptions.JWTDecodeException;
-
-public abstract class TokenUtils {
-
- /**
- * Splits the given token on the "." chars into a String array with 3 parts.
- *
- * @param token the string to split.
- * @return the array representing the 3 parts of the token.
- * @throws JWTDecodeException if the Token doesn't have 3 parts.
- */
- public static String[] splitToken(String token) throws JWTDecodeException {
- String[] parts = token.split("\\.");
- if (parts.length == 2 && token.endsWith(".")) {
- //Tokens with alg='none' have empty String as Signature.
- parts = new String[]{parts[0], parts[1], ""};
- }
- if (parts.length != 3) {
- throw new JWTDecodeException(String.format("The token was expected to have 3 parts, but got %s.", parts.length));
- }
- return parts;
- }
-}
diff --git a/lib/src/main/java/com/auth0/jwt/algorithms/Algorithm.java b/lib/src/main/java/com/auth0/jwt/algorithms/Algorithm.java
deleted file mode 100644
index a63c454..0000000
--- a/lib/src/main/java/com/auth0/jwt/algorithms/Algorithm.java
+++ /dev/null
@@ -1,409 +0,0 @@
-// Copyright (c) 2017 The Authors of 'JWTS for Java'
-//
-// Permission is hereby granted, free of charge, to any person obtaining a copy of
-// this software and associated documentation files (the "Software"), to deal in
-// the Software without restriction, including without limitation the rights to
-// use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
-// the Software, and to permit persons to whom the Software is furnished to do so,
-// subject to the following conditions:
-//
-// The above copyright notice and this permission notice shall be included in all
-// copies or substantial portions of the Software.
-//
-// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
-// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
-// FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
-// COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
-// IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
-// CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
-
-package com.auth0.jwt.algorithms;
-
-import com.auth0.jwt.creators.EncodeType;
-import com.auth0.jwt.exceptions.SignatureGenerationException;
-import com.auth0.jwt.exceptions.SignatureVerificationException;
-import com.auth0.jwt.interfaces.DecodedJWT;
-import com.auth0.jwt.interfaces.ECDSAKeyProvider;
-import com.auth0.jwt.interfaces.RSAKeyProvider;
-
-import java.io.UnsupportedEncodingException;
-import java.security.interfaces.*;
-
-/**
- * The Algorithm class represents an algorithm to be used in the Signing or Verification process of a Token.
- */
-@SuppressWarnings("WeakerAccess")
-public abstract class Algorithm {
-
- private final String name;
- private final String description;
-
- /**
- * Creates a new Algorithm instance using SHA256withRSA. Tokens specify this as "RS256".
- *
- * @param keyProvider the provider of the Public Key and Private Key for the verify and signing instance.
- * @return a valid RSA256 Algorithm.
- * @throws IllegalArgumentException if the provided Key is null.
- */
- public static Algorithm RSA256(RSAKeyProvider keyProvider) throws IllegalArgumentException {
- return new RSAAlgorithm("RS256", "SHA256withRSA", keyProvider);
- }
-
- /**
- * Creates a new Algorithm instance using SHA256withRSA. Tokens specify this as "RS256".
- *
- * @param publicKey the key to use in the verify instance.
- * @param privateKey the key to use in the signing instance.
- * @return a valid RSA256 Algorithm.
- * @throws IllegalArgumentException if both provided Keys are null.
- */
- public static Algorithm RSA256(RSAPublicKey publicKey, RSAPrivateKey privateKey) throws IllegalArgumentException {
- return RSA256(RSAAlgorithm.providerForKeys(publicKey, privateKey));
- }
-
- /**
- * Creates a new Algorithm instance using SHA256withRSA. Tokens specify this as "RS256".
- *
- * @param key the key to use in the verify or signing instance.
- * @return a valid RSA256 Algorithm.
- * @throws IllegalArgumentException if the Key Provider is null.
- * @deprecated use {@link #RSA256(RSAPublicKey, RSAPrivateKey)} or {@link #RSA256(RSAKeyProvider)}
- */
- @Deprecated
- public static Algorithm RSA256(RSAKey key) throws IllegalArgumentException {
- RSAPublicKey publicKey = key instanceof RSAPublicKey ? (RSAPublicKey) key : null;
- RSAPrivateKey privateKey = key instanceof RSAPrivateKey ? (RSAPrivateKey) key : null;
- return RSA256(publicKey, privateKey);
- }
-
- /**
- * Creates a new Algorithm instance using SHA384withRSA. Tokens specify this as "RS384".
- *
- * @param keyProvider the provider of the Public Key and Private Key for the verify and signing instance.
- * @return a valid RSA384 Algorithm.
- * @throws IllegalArgumentException if the Key Provider is null.
- */
- public static Algorithm RSA384(RSAKeyProvider keyProvider) throws IllegalArgumentException {
- return new RSAAlgorithm("RS384", "SHA384withRSA", keyProvider);
- }
-
- /**
- * Creates a new Algorithm instance using SHA384withRSA. Tokens specify this as "RS384".
- *
- * @param publicKey the key to use in the verify instance.
- * @param privateKey the key to use in the signing instance.
- * @return a valid RSA384 Algorithm.
- * @throws IllegalArgumentException if both provided Keys are null.
- */
- public static Algorithm RSA384(RSAPublicKey publicKey, RSAPrivateKey privateKey) throws IllegalArgumentException {
- return RSA384(RSAAlgorithm.providerForKeys(publicKey, privateKey));
- }
-
- /**
- * Creates a new Algorithm instance using SHA384withRSA. Tokens specify this as "RS384".
- *
- * @param key the key to use in the verify or signing instance.
- * @return a valid RSA384 Algorithm.
- * @throws IllegalArgumentException if the provided Key is null.
- * @deprecated use {@link #RSA384(RSAPublicKey, RSAPrivateKey)} or {@link #RSA384(RSAKeyProvider)}
- */
- @Deprecated
- public static Algorithm RSA384(RSAKey key) throws IllegalArgumentException {
- RSAPublicKey publicKey = key instanceof RSAPublicKey ? (RSAPublicKey) key : null;
- RSAPrivateKey privateKey = key instanceof RSAPrivateKey ? (RSAPrivateKey) key : null;
- return RSA384(publicKey, privateKey);
- }
-
- /**
- * Creates a new Algorithm instance using SHA512withRSA. Tokens specify this as "RS512".
- *
- * @param keyProvider the provider of the Public Key and Private Key for the verify and signing instance.
- * @return a valid RSA512 Algorithm.
- * @throws IllegalArgumentException if the Key Provider is null.
- */
- public static Algorithm RSA512(RSAKeyProvider keyProvider) throws IllegalArgumentException {
- return new RSAAlgorithm("RS512", "SHA512withRSA", keyProvider);
- }
-
- /**
- * Creates a new Algorithm instance using SHA512withRSA. Tokens specify this as "RS512".
- *
- * @param publicKey the key to use in the verify instance.
- * @param privateKey the key to use in the signing instance.
- * @return a valid RSA512 Algorithm.
- * @throws IllegalArgumentException if both provided Keys are null.
- */
- public static Algorithm RSA512(RSAPublicKey publicKey, RSAPrivateKey privateKey) throws IllegalArgumentException {
- return RSA512(RSAAlgorithm.providerForKeys(publicKey, privateKey));
- }
-
- /**
- * Creates a new Algorithm instance using SHA512withRSA. Tokens specify this as "RS512".
- *
- * @param key the key to use in the verify or signing instance.
- * @return a valid RSA512 Algorithm.
- * @throws IllegalArgumentException if the provided Key is null.
- * @deprecated use {@link #RSA512(RSAPublicKey, RSAPrivateKey)} or {@link #RSA512(RSAKeyProvider)}
- */
- @Deprecated
- public static Algorithm RSA512(RSAKey key) throws IllegalArgumentException {
- RSAPublicKey publicKey = key instanceof RSAPublicKey ? (RSAPublicKey) key : null;
- RSAPrivateKey privateKey = key instanceof RSAPrivateKey ? (RSAPrivateKey) key : null;
- return RSA512(publicKey, privateKey);
- }
-
- /**
- * Creates a new Algorithm instance using HmacSHA256. Tokens specify this as "HS256".
- *
- * @param secret the secret to use in the verify or signing instance.
- * @return a valid HMAC256 Algorithm.
- * @throws IllegalArgumentException if the provided Secret is null.
- * @throws UnsupportedEncodingException if the current Java platform implementation doesn't support the UTF-8 character encoding.
- */
- public static Algorithm HMAC256(String secret) throws IllegalArgumentException, UnsupportedEncodingException {
- return new HMACAlgorithm("HS256", "HmacSHA256", secret);
- }
-
- /**
- * Creates a new Algorithm instance using HmacSHA384. Tokens specify this as "HS384".
- *
- * @param secret the secret to use in the verify or signing instance.
- * @return a valid HMAC384 Algorithm.
- * @throws IllegalArgumentException if the provided Secret is null.
- * @throws UnsupportedEncodingException if the current Java platform implementation doesn't support the UTF-8 character encoding.
- */
- public static Algorithm HMAC384(String secret) throws IllegalArgumentException, UnsupportedEncodingException {
- return new HMACAlgorithm("HS384", "HmacSHA384", secret);
- }
-
- /**
- * Creates a new Algorithm instance using HmacSHA512. Tokens specify this as "HS512".
- *
- * @param secret the secret to use in the verify or signing instance.
- * @return a valid HMAC512 Algorithm.
- * @throws IllegalArgumentException if the provided Secret is null.
- * @throws UnsupportedEncodingException if the current Java platform implementation doesn't support the UTF-8 character encoding.
- */
- public static Algorithm HMAC512(String secret) throws IllegalArgumentException, UnsupportedEncodingException {
- return new HMACAlgorithm("HS512", "HmacSHA512", secret);
- }
-
- /**
- * Creates a new Algorithm instance using HmacSHA256. Tokens specify this as "HS256".
- *
- * @param secret the secret bytes to use in the verify or signing instance.
- * @return a valid HMAC256 Algorithm.
- * @throws IllegalArgumentException if the provided Secret is null.
- */
- public static Algorithm HMAC256(byte[] secret) throws IllegalArgumentException {
- return new HMACAlgorithm("HS256", "HmacSHA256", secret);
- }
-
- /**
- * Creates a new Algorithm instance using HmacSHA384. Tokens specify this as "HS384".
- *
- * @param secret the secret bytes to use in the verify or signing instance.
- * @return a valid HMAC384 Algorithm.
- * @throws IllegalArgumentException if the provided Secret is null.
- */
- public static Algorithm HMAC384(byte[] secret) throws IllegalArgumentException {
- return new HMACAlgorithm("HS384", "HmacSHA384", secret);
- }
-
- /**
- * Creates a new Algorithm instance using HmacSHA512. Tokens specify this as "HS512".
- *
- * @param secret the secret bytes to use in the verify or signing instance.
- * @return a valid HMAC512 Algorithm.
- * @throws IllegalArgumentException if the provided Secret is null.
- */
- public static Algorithm HMAC512(byte[] secret) throws IllegalArgumentException {
- return new HMACAlgorithm("HS512", "HmacSHA512", secret);
- }
-
- /**
- * Creates a new Algorithm instance using SHA256withECDSA. Tokens specify this as "ES256".
- *
- * @param keyProvider the provider of the Public Key and Private Key for the verify and signing instance.
- * @return a valid ECDSA256 Algorithm.
- * @throws IllegalArgumentException if the Key Provider is null.
- */
- public static Algorithm ECDSA256(ECDSAKeyProvider keyProvider) throws IllegalArgumentException {
- return new ECDSAAlgorithm("ES256", "SHA256withECDSA", 32, keyProvider);
- }
-
- /**
- * Creates a new Algorithm instance using SHA256withECDSA. Tokens specify this as "ES256".
- *
- * @param publicKey the key to use in the verify instance.
- * @param privateKey the key to use in the signing instance.
- * @return a valid ECDSA256 Algorithm.
- * @throws IllegalArgumentException if the provided Key is null.
- */
- public static Algorithm ECDSA256(ECPublicKey publicKey, ECPrivateKey privateKey) throws IllegalArgumentException {
- return ECDSA256(ECDSAAlgorithm.providerForKeys(publicKey, privateKey));
- }
-
- /**
- * Creates a new Algorithm instance using SHA256withECDSA. Tokens specify this as "ES256".
- *
- * @param key the key to use in the verify or signing instance.
- * @return a valid ECDSA256 Algorithm.
- * @throws IllegalArgumentException if the provided Key is null.
- * @deprecated use {@link #ECDSA256(ECPublicKey, ECPrivateKey)} or {@link #ECDSA256(ECDSAKeyProvider)}
- */
- @Deprecated
- public static Algorithm ECDSA256(ECKey key) throws IllegalArgumentException {
- ECPublicKey publicKey = key instanceof ECPublicKey ? (ECPublicKey) key : null;
- ECPrivateKey privateKey = key instanceof ECPrivateKey ? (ECPrivateKey) key : null;
- return ECDSA256(publicKey, privateKey);
- }
-
- /**
- * Creates a new Algorithm instance using SHA384withECDSA. Tokens specify this as "ES384".
- *
- * @param keyProvider the provider of the Public Key and Private Key for the verify and signing instance.
- * @return a valid ECDSA384 Algorithm.
- * @throws IllegalArgumentException if the Key Provider is null.
- */
- public static Algorithm ECDSA384(ECDSAKeyProvider keyProvider) throws IllegalArgumentException {
- return new ECDSAAlgorithm("ES384", "SHA384withECDSA", 48, keyProvider);
- }
-
- /**
- * Creates a new Algorithm instance using SHA384withECDSA. Tokens specify this as "ES384".
- *
- * @param publicKey the key to use in the verify instance.
- * @param privateKey the key to use in the signing instance.
- * @return a valid ECDSA384 Algorithm.
- * @throws IllegalArgumentException if the provided Key is null.
- */
- public static Algorithm ECDSA384(ECPublicKey publicKey, ECPrivateKey privateKey) throws IllegalArgumentException {
- return ECDSA384(ECDSAAlgorithm.providerForKeys(publicKey, privateKey));
- }
-
- /**
- * Creates a new Algorithm instance using SHA384withECDSA. Tokens specify this as "ES384".
- *
- * @param key the key to use in the verify or signing instance.
- * @return a valid ECDSA384 Algorithm.
- * @throws IllegalArgumentException if the provided Key is null.
- * @deprecated use {@link #ECDSA384(ECPublicKey, ECPrivateKey)} or {@link #ECDSA384(ECDSAKeyProvider)}
- */
- @Deprecated
- public static Algorithm ECDSA384(ECKey key) throws IllegalArgumentException {
- ECPublicKey publicKey = key instanceof ECPublicKey ? (ECPublicKey) key : null;
- ECPrivateKey privateKey = key instanceof ECPrivateKey ? (ECPrivateKey) key : null;
- return ECDSA384(publicKey, privateKey);
- }
-
- /**
- * Creates a new Algorithm instance using SHA512withECDSA. Tokens specify this as "ES512".
- *
- * @param keyProvider the provider of the Public Key and Private Key for the verify and signing instance.
- * @return a valid ECDSA512 Algorithm.
- * @throws IllegalArgumentException if the Key Provider is null.
- */
- public static Algorithm ECDSA512(ECDSAKeyProvider keyProvider) throws IllegalArgumentException {
- return new ECDSAAlgorithm("ES512", "SHA512withECDSA", 66, keyProvider);
- }
-
- /**
- * Creates a new Algorithm instance using SHA512withECDSA. Tokens specify this as "ES512".
- *
- * @param publicKey the key to use in the verify instance.
- * @param privateKey the key to use in the signing instance.
- * @return a valid ECDSA512 Algorithm.
- * @throws IllegalArgumentException if the provided Key is null.
- */
- public static Algorithm ECDSA512(ECPublicKey publicKey, ECPrivateKey privateKey) throws IllegalArgumentException {
- return ECDSA512(ECDSAAlgorithm.providerForKeys(publicKey, privateKey));
- }
-
- /**
- * Creates a new Algorithm instance using SHA512withECDSA. Tokens specify this as "ES512".
- *
- * @param key the key to use in the verify or signing instance.
- * @return a valid ECDSA512 Algorithm.
- * @throws IllegalArgumentException if the provided Key is null.
- * @deprecated use {@link #ECDSA512(ECPublicKey, ECPrivateKey)} or {@link #ECDSA512(ECDSAKeyProvider)}
- */
- @Deprecated
- public static Algorithm ECDSA512(ECKey key) throws IllegalArgumentException {
- ECPublicKey publicKey = key instanceof ECPublicKey ? (ECPublicKey) key : null;
- ECPrivateKey privateKey = key instanceof ECPrivateKey ? (ECPrivateKey) key : null;
- return ECDSA512(publicKey, privateKey);
- }
-
-
- public static Algorithm none() {
- return new NoneAlgorithm();
- }
-
- protected Algorithm(String name, String description) {
- this.name = name;
- this.description = description;
- }
-
- /**
- * Getter for the Id of the Private Key used to sign the tokens. This is usually specified as the `kid` claim in the Header.
- *
- * @return the Key Id that identifies the Signing Key or null if it's not specified.
- */
- public String getSigningKeyId() {
- return null;
- }
-
- /**
- * Getter for the name of this Algorithm, as defined in the JWT Standard. i.e. "HS256"
- *
- * @return the algorithm name.
- */
- public String getName() {
- return name;
- }
-
- /**
- * Getter for the description of this Algorithm, required when instantiating a Mac or Signature object. i.e. "HmacSHA256"
- *
- * @return the algorithm description.
- */
- String getDescription() {
- return description;
- }
-
- @Override
- public String toString() {
- return description;
- }
-
- /**
- * Verify the given token using this Algorithm instance.
- *
- * @param jwt the already decoded JWT that it's going to be verified.
- * @throws SignatureVerificationException if the Token's Signature is invalid, meaning that it doesn't match the signatureBytes, or if the Key is invalid.
- */
- public abstract void verify(DecodedJWT jwt, EncodeType encodeType) throws Exception;
-
- /**
- * Sign the given content using this Algorithm instance.
- *
- * @param contentBytes an array of bytes representing the base64 encoded content to be verified against the signature.
- * @return the signature in a base64 encoded array of bytes
- * @throws SignatureGenerationException if the Key is invalid.
- */
- public abstract byte[] sign(byte[] contentBytes) throws SignatureGenerationException;
-
- @Override
- public boolean equals(Object algorithmParam) {
- if(this == algorithmParam)
- return true;
- if(algorithmParam == null)
- return false;
- if(getClass() != algorithmParam.getClass())
- return false;
-
- Algorithm algorithm = (Algorithm) algorithmParam;
- return this.description.equals(algorithm.description) && this.name.equals(algorithm.name);
- }
-}
diff --git a/lib/src/main/java/com/auth0/jwt/algorithms/CryptoHelper.java b/lib/src/main/java/com/auth0/jwt/algorithms/CryptoHelper.java
deleted file mode 100644
index 43b6f82..0000000
--- a/lib/src/main/java/com/auth0/jwt/algorithms/CryptoHelper.java
+++ /dev/null
@@ -1,51 +0,0 @@
-// Copyright (c) 2017 The Authors of 'JWTS for Java'
-//
-// Permission is hereby granted, free of charge, to any person obtaining a copy of
-// this software and associated documentation files (the "Software"), to deal in
-// the Software without restriction, including without limitation the rights to
-// use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
-// the Software, and to permit persons to whom the Software is furnished to do so,
-// subject to the following conditions:
-//
-// The above copyright notice and this permission notice shall be included in all
-// copies or substantial portions of the Software.
-//
-// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
-// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
-// FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
-// COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
-// IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
-// CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
-
-package com.auth0.jwt.algorithms;
-
-import javax.crypto.Mac;
-import javax.crypto.spec.SecretKeySpec;
-import java.security.*;
-
-class CryptoHelper {
-
- boolean verifySignatureFor(String algorithm, byte[] secretBytes, byte[] contentBytes, byte[] signatureBytes) throws NoSuchAlgorithmException, InvalidKeyException {
- return MessageDigest.isEqual(createSignatureFor(algorithm, secretBytes, contentBytes), signatureBytes);
- }
-
- byte[] createSignatureFor(String algorithm, byte[] secretBytes, byte[] contentBytes) throws NoSuchAlgorithmException, InvalidKeyException {
- final Mac mac = Mac.getInstance(algorithm);
- mac.init(new SecretKeySpec(secretBytes, algorithm));
- return mac.doFinal(contentBytes);
- }
-
- boolean verifySignatureFor(String algorithm, PublicKey publicKey, byte[] contentBytes, byte[] signatureBytes) throws NoSuchAlgorithmException, InvalidKeyException, SignatureException {
- final Signature s = Signature.getInstance(algorithm);
- s.initVerify(publicKey);
- s.update(contentBytes);
- return s.verify(signatureBytes);
- }
-
- byte[] createSignatureFor(String algorithm, PrivateKey privateKey, byte[] contentBytes) throws NoSuchAlgorithmException, InvalidKeyException, SignatureException {
- final Signature s = Signature.getInstance(algorithm);
- s.initSign(privateKey);
- s.update(contentBytes);
- return s.sign();
- }
-}
diff --git a/lib/src/main/java/com/auth0/jwt/algorithms/ECDSAAlgorithm.java b/lib/src/main/java/com/auth0/jwt/algorithms/ECDSAAlgorithm.java
deleted file mode 100644
index 91a7fef..0000000
--- a/lib/src/main/java/com/auth0/jwt/algorithms/ECDSAAlgorithm.java
+++ /dev/null
@@ -1,261 +0,0 @@
-// Copyright (c) 2017 The Authors of 'JWTS for Java'
-//
-// Permission is hereby granted, free of charge, to any person obtaining a copy of
-// this software and associated documentation files (the "Software"), to deal in
-// the Software without restriction, including without limitation the rights to
-// use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
-// the Software, and to permit persons to whom the Software is furnished to do so,
-// subject to the following conditions:
-//
-// The above copyright notice and this permission notice shall be included in all
-// copies or substantial portions of the Software.
-//
-// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
-// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
-// FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
-// COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
-// IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
-// CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
-
-package com.auth0.jwt.algorithms;
-
-import com.auth0.jwt.creators.EncodeType;
-import com.auth0.jwt.exceptions.SignatureGenerationException;
-import com.auth0.jwt.exceptions.SignatureVerificationException;
-import com.auth0.jwt.interfaces.DecodedJWT;
-import com.auth0.jwt.interfaces.ECDSAKeyProvider;
-import org.apache.commons.codec.binary.Base32;
-import org.apache.commons.codec.binary.Base64;
-import org.apache.commons.codec.binary.Hex;
-import org.apache.commons.codec.binary.StringUtils;
-
-import java.net.URLDecoder;
-import java.nio.charset.StandardCharsets;
-import java.security.InvalidKeyException;
-import java.security.NoSuchAlgorithmException;
-import java.security.SignatureException;
-import java.security.interfaces.ECPrivateKey;
-import java.security.interfaces.ECPublicKey;
-
-class ECDSAAlgorithm extends Algorithm {
-
- private final ECDSAKeyProvider keyProvider;
- private final CryptoHelper crypto;
- private final int ecNumberSize;
-
- //Visible for testing
- ECDSAAlgorithm(CryptoHelper crypto, String id, String algorithm, int ecNumberSize, ECDSAKeyProvider keyProvider) throws IllegalArgumentException {
- super(id, algorithm);
- if (keyProvider == null) {
- throw new IllegalArgumentException("The Key Provider cannot be null.");
- }
- this.keyProvider = keyProvider;
- this.crypto = crypto;
- this.ecNumberSize = ecNumberSize;
- }
-
- ECDSAAlgorithm(String id, String algorithm, int ecNumberSize, ECDSAKeyProvider keyProvider) throws IllegalArgumentException {
- this(new CryptoHelper(), id, algorithm, ecNumberSize, keyProvider);
- }
-
- @Override
- public void verify(DecodedJWT jwt, EncodeType encodeType) throws Exception {
- byte[] contentBytes = String.format("%s.%s", jwt.getHeader(), jwt.getPayload()).getBytes(StandardCharsets.UTF_8);
- byte[] signatureBytes = null;
- String signature = jwt.getSignature();
- String urlDecoded = null;
- switch (encodeType) {
- case Base16:
- urlDecoded = URLDecoder.decode(signature, "UTF-8");
- signatureBytes = Hex.decodeHex(urlDecoded);
- break;
- case Base32:
- Base32 base32 = new Base32();
- urlDecoded = URLDecoder.decode(signature, "UTF-8");
- signatureBytes = base32.decode(urlDecoded);
- break;
- case Base64:
- signatureBytes = Base64.decodeBase64(signature);
- break;
- }
-
- try {
- ECPublicKey publicKey = keyProvider.getPublicKeyById(jwt.getKeyId());
- if (publicKey == null) {
- throw new IllegalStateException("The given Public Key is null.");
- }
- boolean valid = crypto.verifySignatureFor(getDescription(), publicKey, contentBytes, JOSEToDER(signatureBytes));
-
- if (!valid) {
- throw new SignatureVerificationException(this);
- }
- } catch (NoSuchAlgorithmException | SignatureException | InvalidKeyException | IllegalStateException e) {
- throw new SignatureVerificationException(this, e);
- }
- }
-
- @Override
- public byte[] sign(byte[] contentBytes) throws SignatureGenerationException {
- try {
- ECPrivateKey privateKey = keyProvider.getPrivateKey();
- if (privateKey == null) {
- throw new IllegalStateException("The given Private Key is null.");
- }
- byte[] signature = crypto.createSignatureFor(getDescription(), privateKey, contentBytes);
- return DERToJOSE(signature);
- } catch (NoSuchAlgorithmException | SignatureException | InvalidKeyException | IllegalStateException e) {
- throw new SignatureGenerationException(this, e);
- }
- }
-
- @Override
- public String getSigningKeyId() {
- return keyProvider.getPrivateKeyId();
- }
-
- //Visible for testing
- byte[] DERToJOSE(byte[] derSignature) throws SignatureException {
- // DER Structure: http://crypto.stackexchange.com/a/1797
- boolean derEncoded = derSignature[0] == 0x30 && derSignature.length != ecNumberSize * 2;
- if (!derEncoded) {
- throw new SignatureException("Invalid DER signature format.");
- }
-
- final byte[] joseSignature = new byte[ecNumberSize * 2];
-
- //Skip 0x30
- int offset = 1;
- if (derSignature[1] == (byte) 0x81) {
- //Skip sign
- offset++;
- }
-
- //Convert to unsigned. Should match DER length - offset
- int encodedLength = derSignature[offset++] & 0xff;
- if (encodedLength != derSignature.length - offset) {
- throw new SignatureException("Invalid DER signature format.");
- }
-
- //Skip 0x02
- offset++;
-
- //Obtain R number length (Includes padding) and skip it
- int rLength = derSignature[offset++];
- if (rLength > ecNumberSize + 1) {
- throw new SignatureException("Invalid DER signature format.");
- }
- int rPadding = ecNumberSize - rLength;
- //Retrieve R number
- System.arraycopy(derSignature, offset + Math.max(-rPadding, 0), joseSignature, Math.max(rPadding, 0), rLength + Math.min(rPadding, 0));
-
- //Skip R number and 0x02
- offset += rLength + 1;
-
- //Obtain S number length. (Includes padding)
- int sLength = derSignature[offset++];
- if (sLength > ecNumberSize + 1) {
- throw new SignatureException("Invalid DER signature format.");
- }
- int sPadding = ecNumberSize - sLength;
- //Retrieve R number
- System.arraycopy(derSignature, offset + Math.max(-sPadding, 0), joseSignature, ecNumberSize + Math.max(sPadding, 0), sLength + Math.min(sPadding, 0));
-
- return joseSignature;
- }
-
- //Visible for testing
- byte[] JOSEToDER(byte[] joseSignature) throws SignatureException {
- if (joseSignature.length != ecNumberSize * 2) {
- throw new SignatureException("Invalid JOSE signature format.");
- }
-
- // Retrieve R and S number's length and padding.
- int rPadding = countPadding(joseSignature, 0, ecNumberSize);
- int sPadding = countPadding(joseSignature, ecNumberSize, joseSignature.length);
- int rLength = ecNumberSize - rPadding;
- int sLength = ecNumberSize - sPadding;
-
- int length = 2 + rLength + 2 + sLength;
- if (length > 255) {
- throw new SignatureException("Invalid JOSE signature format.");
- }
-
- final byte[] derSignature;
- int offset;
- if (length > 0x7f) {
- derSignature = new byte[3 + length];
- derSignature[1] = (byte) 0x81;
- offset = 2;
- } else {
- derSignature = new byte[2 + length];
- offset = 1;
- }
-
- // DER Structure: http://crypto.stackexchange.com/a/1797
- // Header with signature length info
- derSignature[0] = (byte) 0x30;
- derSignature[offset++] = (byte) (length & 0xff);
-
- // Header with "min R" number length
- derSignature[offset++] = (byte) 0x02;
- derSignature[offset++] = (byte) rLength;
-
- // R number
- if (rPadding < 0) {
- //Sign
- derSignature[offset++] = (byte) 0x00;
- System.arraycopy(joseSignature, 0, derSignature, offset, ecNumberSize);
- offset += ecNumberSize;
- } else {
- int copyLength = Math.min(ecNumberSize, rLength);
- System.arraycopy(joseSignature, rPadding, derSignature, offset, copyLength);
- offset += copyLength;
- }
-
- // Header with "min S" number length
- derSignature[offset++] = (byte) 0x02;
- derSignature[offset++] = (byte) sLength;
-
- // S number
- if (sPadding < 0) {
- //Sign
- derSignature[offset++] = (byte) 0x00;
- System.arraycopy(joseSignature, ecNumberSize, derSignature, offset, ecNumberSize);
- } else {
- System.arraycopy(joseSignature, ecNumberSize + sPadding, derSignature, offset, Math.min(ecNumberSize, sLength));
- }
-
- return derSignature;
- }
-
- private int countPadding(byte[] bytes, int fromIndex, int toIndex) {
- int padding = 0;
- while (fromIndex + padding < toIndex && bytes[fromIndex + padding] == 0) {
- padding++;
- }
- return (bytes[fromIndex + padding] & 0xff) > 0x7f ? padding - 1 : padding;
- }
-
- //Visible for testing
- static ECDSAKeyProvider providerForKeys(final ECPublicKey publicKey, final ECPrivateKey privateKey) {
- if (publicKey == null && privateKey == null) {
- throw new IllegalArgumentException("Both provided Keys cannot be null.");
- }
- return new ECDSAKeyProvider() {
- @Override
- public ECPublicKey getPublicKeyById(String keyId) {
- return publicKey;
- }
-
- @Override
- public ECPrivateKey getPrivateKey() {
- return privateKey;
- }
-
- @Override
- public String getPrivateKeyId() {
- return null;
- }
- };
- }
-}
diff --git a/lib/src/main/java/com/auth0/jwt/algorithms/HMACAlgorithm.java b/lib/src/main/java/com/auth0/jwt/algorithms/HMACAlgorithm.java
deleted file mode 100644
index b7ee04a..0000000
--- a/lib/src/main/java/com/auth0/jwt/algorithms/HMACAlgorithm.java
+++ /dev/null
@@ -1,111 +0,0 @@
-// Copyright (c) 2017 The Authors of 'JWTS for Java'
-//
-// Permission is hereby granted, free of charge, to any person obtaining a copy of
-// this software and associated documentation files (the "Software"), to deal in
-// the Software without restriction, including without limitation the rights to
-// use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
-// the Software, and to permit persons to whom the Software is furnished to do so,
-// subject to the following conditions:
-//
-// The above copyright notice and this permission notice shall be included in all
-// copies or substantial portions of the Software.
-//
-// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
-// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
-// FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
-// COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
-// IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
-// CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
-
-package com.auth0.jwt.algorithms;
-
-import com.auth0.jwt.creators.EncodeType;
-import com.auth0.jwt.creators.JWTCreator;
-import com.auth0.jwt.exceptions.SignatureGenerationException;
-import com.auth0.jwt.exceptions.SignatureVerificationException;
-import com.auth0.jwt.interfaces.DecodedJWT;
-import org.apache.commons.codec.CharEncoding;
-import org.apache.commons.codec.binary.Base32;
-import org.apache.commons.codec.binary.Base64;
-import org.apache.commons.codec.binary.Hex;
-import org.apache.commons.codec.binary.StringUtils;
-
-import java.io.UnsupportedEncodingException;
-import java.net.URLDecoder;
-import java.nio.charset.Charset;
-import java.nio.charset.StandardCharsets;
-import java.security.InvalidKeyException;
-import java.security.NoSuchAlgorithmException;
-
-class HMACAlgorithm extends Algorithm {
-
- private final CryptoHelper crypto;
- private final byte[] secret;
-
- //Visible for testing
- HMACAlgorithm(CryptoHelper crypto, String id, String algorithm, byte[] secretBytes) throws IllegalArgumentException {
- super(id, algorithm);
- if (secretBytes == null) {
- throw new IllegalArgumentException("The Secret cannot be null");
- }
- this.secret = secretBytes;
- this.crypto = crypto;
- }
-
- HMACAlgorithm(String id, String algorithm, byte[] secretBytes) throws IllegalArgumentException {
- this(new CryptoHelper(), id, algorithm, secretBytes);
- }
-
- HMACAlgorithm(String id, String algorithm, String secret) throws IllegalArgumentException, UnsupportedEncodingException {
- this(new CryptoHelper(), id, algorithm, getSecretBytes(secret));
- }
-
- //Visible for testing
- static byte[] getSecretBytes(String secret) throws IllegalArgumentException, UnsupportedEncodingException {
- if (secret == null) {
- throw new IllegalArgumentException("The Secret cannot be null");
- }
- return secret.getBytes(CharEncoding.UTF_8);
- }
-
- @Override
- public void verify(DecodedJWT jwt, EncodeType encodeType) throws Exception {
- byte[] contentBytes = String.format("%s.%s", jwt.getHeader(), jwt.getPayload()).getBytes(StandardCharsets.UTF_8);
- byte[] signatureBytes = null;
- String signature = jwt.getSignature();
- String urlDecoded = null;
- switch (encodeType) {
- case Base16:
- urlDecoded = URLDecoder.decode(signature, "UTF-8");
- signatureBytes = Hex.decodeHex(urlDecoded);
- break;
- case Base32:
- Base32 base32 = new Base32();
- urlDecoded = URLDecoder.decode(signature, "UTF-8");
- signatureBytes = base32.decode(urlDecoded);
- break;
- case Base64:
- signatureBytes = Base64.decodeBase64(signature);
- break;
- }
-
- try {
- boolean valid = crypto.verifySignatureFor(getDescription(), secret, contentBytes, signatureBytes);
- if (!valid) {
- throw new SignatureVerificationException(this);
- }
- } catch (IllegalStateException | InvalidKeyException | NoSuchAlgorithmException e) {
- throw new SignatureVerificationException(this, e);
- }
- }
-
- @Override
- public byte[] sign(byte[] contentBytes) throws SignatureGenerationException {
- try {
- return crypto.createSignatureFor(getDescription(), secret, contentBytes);
- } catch (NoSuchAlgorithmException | InvalidKeyException e) {
- throw new SignatureGenerationException(this, e);
- }
- }
-
-}
diff --git a/lib/src/main/java/com/auth0/jwt/algorithms/NoneAlgorithm.java b/lib/src/main/java/com/auth0/jwt/algorithms/NoneAlgorithm.java
deleted file mode 100644
index 5c7e23a..0000000
--- a/lib/src/main/java/com/auth0/jwt/algorithms/NoneAlgorithm.java
+++ /dev/null
@@ -1,66 +0,0 @@
-// Copyright (c) 2017 The Authors of 'JWTS for Java'
-//
-// Permission is hereby granted, free of charge, to any person obtaining a copy of
-// this software and associated documentation files (the "Software"), to deal in
-// the Software without restriction, including without limitation the rights to
-// use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
-// the Software, and to permit persons to whom the Software is furnished to do so,
-// subject to the following conditions:
-//
-// The above copyright notice and this permission notice shall be included in all
-// copies or substantial portions of the Software.
-//
-// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
-// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
-// FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
-// COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
-// IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
-// CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
-
-package com.auth0.jwt.algorithms;
-
-import com.auth0.jwt.creators.EncodeType;
-import com.auth0.jwt.exceptions.SignatureGenerationException;
-import com.auth0.jwt.exceptions.SignatureVerificationException;
-import com.auth0.jwt.interfaces.DecodedJWT;
-import org.apache.commons.codec.binary.Base32;
-import org.apache.commons.codec.binary.Base64;
-import org.apache.commons.codec.binary.Hex;
-
-import java.net.URLDecoder;
-
-class NoneAlgorithm extends Algorithm {
-
- NoneAlgorithm() {
- super("none", "none");
- }
-
- @Override
- public void verify(DecodedJWT jwt, EncodeType encodeType) throws Exception {
- byte[] signatureBytes = null;
- String signature = jwt.getSignature();
- String urlDecoded = null;
- switch (encodeType) {
- case Base16:
- urlDecoded = URLDecoder.decode(signature, "UTF-8");
- signatureBytes = Hex.decodeHex(urlDecoded);
- break;
- case Base32:
- Base32 base32 = new Base32();
- urlDecoded = URLDecoder.decode(signature, "UTF-8");
- signatureBytes = base32.decode(urlDecoded);
- break;
- case Base64:
- signatureBytes = Base64.decodeBase64(signature);
- break;
- }
- if (signatureBytes.length > 0) {
- throw new SignatureVerificationException(this);
- }
- }
-
- @Override
- public byte[] sign(byte[] contentBytes) throws SignatureGenerationException {
- return new byte[0];
- }
-}
diff --git a/lib/src/main/java/com/auth0/jwt/algorithms/RSAAlgorithm.java b/lib/src/main/java/com/auth0/jwt/algorithms/RSAAlgorithm.java
deleted file mode 100644
index bc312a2..0000000
--- a/lib/src/main/java/com/auth0/jwt/algorithms/RSAAlgorithm.java
+++ /dev/null
@@ -1,133 +0,0 @@
-// Copyright (c) 2017 The Authors of 'JWTS for Java'
-//
-// Permission is hereby granted, free of charge, to any person obtaining a copy of
-// this software and associated documentation files (the "Software"), to deal in
-// the Software without restriction, including without limitation the rights to
-// use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
-// the Software, and to permit persons to whom the Software is furnished to do so,
-// subject to the following conditions:
-//
-// The above copyright notice and this permission notice shall be included in all
-// copies or substantial portions of the Software.
-//
-// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
-// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
-// FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
-// COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
-// IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
-// CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
-
-package com.auth0.jwt.algorithms;
-
-import com.auth0.jwt.creators.EncodeType;
-import com.auth0.jwt.exceptions.SignatureGenerationException;
-import com.auth0.jwt.exceptions.SignatureVerificationException;
-import com.auth0.jwt.interfaces.DecodedJWT;
-import com.auth0.jwt.interfaces.RSAKeyProvider;
-import org.apache.commons.codec.binary.Base32;
-import org.apache.commons.codec.binary.Base64;
-import org.apache.commons.codec.binary.Hex;
-
-import java.net.URLDecoder;
-import java.nio.charset.StandardCharsets;
-import java.security.InvalidKeyException;
-import java.security.NoSuchAlgorithmException;
-import java.security.SignatureException;
-import java.security.interfaces.RSAPrivateKey;
-import java.security.interfaces.RSAPublicKey;
-
-class RSAAlgorithm extends Algorithm {
-
- private final RSAKeyProvider keyProvider;
- private final CryptoHelper crypto;
-
- //Visible for testing
- RSAAlgorithm(CryptoHelper crypto, String id, String algorithm, RSAKeyProvider keyProvider) throws IllegalArgumentException {
- super(id, algorithm);
- if (keyProvider == null) {
- throw new IllegalArgumentException("The Key Provider cannot be null.");
- }
- this.keyProvider = keyProvider;
- this.crypto = crypto;
- }
-
- RSAAlgorithm(String id, String algorithm, RSAKeyProvider keyProvider) throws IllegalArgumentException {
- this(new CryptoHelper(), id, algorithm, keyProvider);
- }
-
- @Override
- public void verify(DecodedJWT jwt, EncodeType encodeType) throws Exception {
- byte[] contentBytes = String.format("%s.%s", jwt.getHeader(), jwt.getPayload()).getBytes(StandardCharsets.UTF_8);
- byte[] signatureBytes = null;
- String signature = jwt.getSignature();
- String urlDecoded = null;
- switch (encodeType) {
- case Base16:
- urlDecoded = URLDecoder.decode(signature, "UTF-8");
- signatureBytes = Hex.decodeHex(urlDecoded);
- break;
- case Base32:
- Base32 base32 = new Base32();
- urlDecoded = URLDecoder.decode(signature, "UTF-8");
- signatureBytes = base32.decode(urlDecoded);
- break;
- case Base64:
- signatureBytes = Base64.decodeBase64(signature);
- break;
- }
-
- try {
- RSAPublicKey publicKey = keyProvider.getPublicKeyById(jwt.getKeyId());
- if (publicKey == null) {
- throw new IllegalStateException("The given Public Key is null.");
- }
- boolean valid = crypto.verifySignatureFor(getDescription(), publicKey, contentBytes, signatureBytes);
- if (!valid) {
- throw new SignatureVerificationException(this);
- }
- } catch (NoSuchAlgorithmException | SignatureException | InvalidKeyException | IllegalStateException e) {
- throw new SignatureVerificationException(this, e);
- }
- }
-
- @Override
- public byte[] sign(byte[] contentBytes) throws SignatureGenerationException {
- try {
- RSAPrivateKey privateKey = keyProvider.getPrivateKey();
- if (privateKey == null) {
- throw new IllegalStateException("The given Private Key is null.");
- }
- return crypto.createSignatureFor(getDescription(), privateKey, contentBytes);
- } catch (NoSuchAlgorithmException | SignatureException | InvalidKeyException | IllegalStateException e) {
- throw new SignatureGenerationException(this, e);
- }
- }
-
- @Override
- public String getSigningKeyId() {
- return keyProvider.getPrivateKeyId();
- }
-
- //Visible for testing
- static RSAKeyProvider providerForKeys(final RSAPublicKey publicKey, final RSAPrivateKey privateKey) {
- if (publicKey == null && privateKey == null) {
- throw new IllegalArgumentException("Both provided Keys cannot be null.");
- }
- return new RSAKeyProvider() {
- @Override
- public RSAPublicKey getPublicKeyById(String keyId) {
- return publicKey;
- }
-
- @Override
- public RSAPrivateKey getPrivateKey() {
- return privateKey;
- }
-
- @Override
- public String getPrivateKeyId() {
- return null;
- }
- };
- }
-}
diff --git a/lib/src/main/java/com/auth0/jwt/creators/AccessJwtCreator.java b/lib/src/main/java/com/auth0/jwt/creators/AccessJwtCreator.java
deleted file mode 100644
index 4b126c4..0000000
--- a/lib/src/main/java/com/auth0/jwt/creators/AccessJwtCreator.java
+++ /dev/null
@@ -1,292 +0,0 @@
-// Copyright (c) 2017 The Authors of 'JWTS for Java'
-//
-// Permission is hereby granted, free of charge, to any person obtaining a copy of
-// this software and associated documentation files (the "Software"), to deal in
-// the Software without restriction, including without limitation the rights to
-// use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
-// the Software, and to permit persons to whom the Software is furnished to do so,
-// subject to the following conditions:
-//
-// The above copyright notice and this permission notice shall be included in all
-// copies or substantial portions of the Software.
-//
-// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
-// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
-// FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
-// COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
-// IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
-// CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
-
-package com.auth0.jwt.creators;
-
-import com.auth0.jwt.algorithms.Algorithm;
-import com.auth0.jwt.exceptions.JWTCreationException;
-import com.auth0.jwt.impl.PublicClaims;
-import com.auth0.jwt.jwts.JWT;
-
-import java.util.Date;
-import java.util.HashMap;
-import java.util.HashSet;
-import java.util.Set;
-
-/**
- * The AccessJwtCreator class holds the sign method to generate a complete Access JWT (with Signature) from a given Header and Payload content.
- */
-public class AccessJwtCreator {
-
- protected JWTCreator.Builder jwt;
- protected HashMap addedClaims;
- protected Set publicClaims;
-
- public AccessJwtCreator() {
- jwt = JWT.create();
- addedClaims = new HashMap() {{
- put("Issuer", false);
- put("Subject", false);
- put("Iat", false);
- }};
- publicClaims = new HashSet() {{
- add(PublicClaims.ISSUER);
- add(PublicClaims.SUBJECT);
- add(PublicClaims.EXPIRES_AT);
- add(PublicClaims.NOT_BEFORE);
- add(PublicClaims.ISSUED_AT);
- add(PublicClaims.JWT_ID);
- add(PublicClaims.AUDIENCE);
- }};
- }
-
- /**
- * Add a specific Issuer ("issuer") claim to the Payload.
- * Allows for multiple issuers
- *
- * @param issuer the Issuer value.
- * @return this same Builder instance.
- */
- public AccessJwtCreator withIssuer(String... issuer) {
- jwt.withIssuer(issuer);
- addedClaims.put("Issuer", true);
- return this;
- }
-
- /**
- * Add a specific Subject ("subject") claim to the Payload.
- * Allows for multiple subjects
- *
- * @param subject the Subject value.
- * @return this same Builder instance.
- */
- public AccessJwtCreator withSubject(String... subject) {
- jwt.withSubject(subject);
- addedClaims.put("Subject", true);
- return this;
- }
-
- /**
- * Add a specific Audience ("audience") claim to the Payload.
- * Allows for multiple audience
- *
- * @param audience the Audience value.
- * @return this same Builder instance.
- */
- public AccessJwtCreator withAudience(String... audience) {
- jwt.withAudience(audience);
- return this;
- }
-
- /**
- * Add a specific Issued At ("iat") claim to the Payload.
- *
- * @param iat the Issued At value.
- * @return this same Builder instance.
- */
- public AccessJwtCreator withIat(Date iat) {
- jwt.withIssuedAt(iat);
- addedClaims.put("Iat", true);
- return this;
- }
-
- /**
- * Add a specific Expires At ("exp") claim to the Payload.
- *
- * @param exp the Expires At value.
- * @return this same Builder instance.
- */
- public AccessJwtCreator withExp(Date exp) {
- jwt.withExpiresAt(exp);
- return this;
- }
-
- /**
- * Require a specific Claim value.
- *
- * @param name the Claim's name.
- * @param value the Claim's value.
- * @return this same Verification instance.
- * @throws IllegalArgumentException if the name is null.
- */
- public AccessJwtCreator withNonStandardClaim(String name, String value) {
- jwt.withNonStandardClaim(name, value);
- return this;
- }
-
- /**
- * Add a custom Claim value.
- *
- * @param name the Claim's name.
- * @param value the Claim's value.
- * @return this same Builder instance.
- * @throws IllegalArgumentException if the name is null.
- */
- public AccessJwtCreator withNonStandardClaim(String name, Boolean value) throws IllegalArgumentException {
- jwt.withNonStandardClaim(name, value);
- return this;
- }
-
- /**
- * Add a custom Claim value.
- *
- * @param name the Claim's name.
- * @param value the Claim's value.
- * @return this same Builder instance.
- * @throws IllegalArgumentException if the name is null.
- */
- public AccessJwtCreator withNonStandardClaim(String name, Integer value) throws IllegalArgumentException {
- jwt.withNonStandardClaim(name, value);
- return this;
- }
-
- /**
- * Add a custom Claim value.
- *
- * @param name the Claim's name.
- * @param value the Claim's value.
- * @return this same Builder instance.
- * @throws IllegalArgumentException if the name is null.
- */
- public AccessJwtCreator withNonStandardClaim(String name, Long value) throws IllegalArgumentException {
- jwt.withNonStandardClaim(name, value);
- return this;
- }
-
- /**
- * Add a custom Claim value.
- *
- * @param name the Claim's name.
- * @param value the Claim's value.
- * @return this same Builder instance.
- * @throws IllegalArgumentException if the name is null.
- */
- public AccessJwtCreator withNonStandardClaim(String name, Double value) throws IllegalArgumentException {
- jwt.withNonStandardClaim(name, value);
- return this;
- }
-
- /**
- * Add a custom Claim value.
- *
- * @param name the Claim's name.
- * @param value the Claim's value.
- * @return this same Builder instance.
- * @throws IllegalArgumentException if the name is null.
- */
- public AccessJwtCreator withNonStandardClaim(String name, Date value) throws IllegalArgumentException {
- jwt.withNonStandardClaim(name, value);
- return this;
- }
-
- /**
- * Require a specific Array Claim to contain at least the given items.
- *
- * @param name the Claim's name.
- * @param items the items the Claim must contain.
- * @return this same Verification instance.
- * @throws IllegalArgumentException if the name is null.
- */
- public AccessJwtCreator withArrayClaim(String name, String... items) throws IllegalArgumentException {
- jwt.withArrayClaim(name, items);
- if(publicClaims.contains(name))
- addedClaims.put(name, true);
- return this;
- }
-
- /**
- * Developer explicitly specifies whether they want to accept
- * NONE algorithms or not.
- *
- * @param isNoneAlgorithmAllowed
- * @return
- */
- public AccessJwtCreator setIsNoneAlgorithmAllowed(boolean isNoneAlgorithmAllowed) {
- jwt.setIsNoneAlgorithmAllowed(isNoneAlgorithmAllowed);
- return this;
- }
-
- /**
- * Creates a new JWT and signs it with the given algorithm.
- *
- * @param algorithm used to sign the JWT
- * @return a new JWT token
- * @throws IllegalAccessException if the developer didn't want NONE algorithm to be allowed and it was passed in
- * @throws IllegalArgumentException if the provided algorithm is null.
- * @throws JWTCreationException if the claims could not be converted to a valid JSON or there was a problem with the signing key.
- */
- public String sign(Algorithm algorithm) throws Exception {
- if(!jwt.getIsNoneAlgorithmAllowed() && algorithm.equals(Algorithm.none())) {
- throw new IllegalAccessException("None algorithm isn't allowed");
- }
- String JWS = jwt.sign(algorithm);
- verifyClaims();
- return JWS;
- }
-
- /**
- * Creates a new JWT and signs it with the given algorithm.
- *
- * @param algorithm used to sign the JWT
- * @return a new JWT token
- * @throws IllegalAccessException if the developer didn't want NONE algorithm to be allowed and it was passed in
- * @throws IllegalArgumentException if the provided algorithm is null.
- * @throws JWTCreationException if the claims could not be converted to a valid JSON or there was a problem with the signing key.
- */
- public String signBase16Encoding(Algorithm algorithm) throws Exception {
- if(!jwt.getIsNoneAlgorithmAllowed() && algorithm.equals(Algorithm.none())) {
- throw new IllegalAccessException("None algorithm isn't allowed");
- }
- String JWS = jwt.sign(algorithm, EncodeType.Base16);
- verifyClaims();
- return JWS;
- }
-
- /**
- * Creates a new JWT and signs it with the given algorithm.
- *
- * @param algorithm used to sign the JWT
- * @return a new JWT token
- * @throws IllegalAccessException if the developer didn't want NONE algorithm to be allowed and it was passed in
- * @throws IllegalArgumentException if the provided algorithm is null.
- * @throws JWTCreationException if the claims could not be converted to a valid JSON or there was a problem with the signing key.
- */
- public String signBase32Encoding(Algorithm algorithm) throws Exception {
- if(!jwt.getIsNoneAlgorithmAllowed() && algorithm.equals(Algorithm.none())) {
- throw new IllegalAccessException("None algorithm isn't allowed");
- }
- String JWS = jwt.sign(algorithm, EncodeType.Base32);
- verifyClaims();
- return JWS;
- }
-
- /**
- * Verifies that all the standard claims were provided
- * @throws Exception if all the standard claims weren't provided
- */
- private void verifyClaims() throws Exception {
- for(String claim : addedClaims.keySet())
- if(!addedClaims.get(claim))
- throw new Exception("Standard claim: " + claim + " has not been set");
- }
-
- public static AccessJwtCreator build() {
- return new AccessJwtCreator();
- }
-}
diff --git a/lib/src/main/java/com/auth0/jwt/creators/EncodeType.java b/lib/src/main/java/com/auth0/jwt/creators/EncodeType.java
deleted file mode 100644
index 9a4bd4d..0000000
--- a/lib/src/main/java/com/auth0/jwt/creators/EncodeType.java
+++ /dev/null
@@ -1,24 +0,0 @@
-// Copyright (c) 2017 The Authors of 'JWTS for Java'
-//
-// Permission is hereby granted, free of charge, to any person obtaining a copy of
-// this software and associated documentation files (the "Software"), to deal in
-// the Software without restriction, including without limitation the rights to
-// use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
-// the Software, and to permit persons to whom the Software is furnished to do so,
-// subject to the following conditions:
-//
-// The above copyright notice and this permission notice shall be included in all
-// copies or substantial portions of the Software.
-//
-// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
-// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
-// FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
-// COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
-// IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
-// CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
-
-package com.auth0.jwt.creators;
-
-public enum EncodeType {
- Base16, Base32, Base64, JsonEncode;
-}
diff --git a/lib/src/main/java/com/auth0/jwt/creators/ExtendedJwtCreator.java b/lib/src/main/java/com/auth0/jwt/creators/ExtendedJwtCreator.java
deleted file mode 100644
index 18e6917..0000000
--- a/lib/src/main/java/com/auth0/jwt/creators/ExtendedJwtCreator.java
+++ /dev/null
@@ -1,114 +0,0 @@
-// Copyright (c) 2017 The Authors of 'JWTS for Java'
-//
-// Permission is hereby granted, free of charge, to any person obtaining a copy of
-// this software and associated documentation files (the "Software"), to deal in
-// the Software without restriction, including without limitation the rights to
-// use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
-// the Software, and to permit persons to whom the Software is furnished to do so,
-// subject to the following conditions:
-//
-// The above copyright notice and this permission notice shall be included in all
-// copies or substantial portions of the Software.
-//
-// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
-// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
-// FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
-// COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
-// IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
-// CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
-
-package com.auth0.jwt.creators;
-
-import com.auth0.jwt.algorithms.Algorithm;
-import com.auth0.jwt.exceptions.JWTCreationException;
-
-import java.util.Date;
-
-/**
- * The ExtendedJwtCreator class holds the sign method to generate a complete Extended JWT (with Signature) from a given Header and Payload content.
- */
-public class ExtendedJwtCreator extends GoogleJwtCreator{
-
- public ExtendedJwtCreator() {
- super();
- }
-
- /**
- * Add a specific Note Before ("nbf") claim to the Payload.
- *
- * @param nbf the nbf value.
- * @return this same Builder instance.
- */
- public GoogleJwtCreator withNbf(Date nbf) {
- jwt.withNotBefore(nbf);
- return this;
- }
-
- /**
- * Creates a new JWT and signs it with the given algorithm.
- *
- * @param algorithm used to sign the JWT
- * @return a new JWT token
- * @throws IllegalAccessException if the developer didn't want NONE algorithm to be allowed and it was passed in
- * @throws IllegalArgumentException if the provided algorithm is null.
- * @throws JWTCreationException if the claims could not be converted to a valid JSON or there was a problem with the signing key.
- */
- public String sign(Algorithm algorithm) throws Exception {
- if(!jwt.getIsNoneAlgorithmAllowed() && algorithm.equals(Algorithm.none())) {
- throw new IllegalAccessException("None algorithm isn't allowed");
- }
- String JWS = jwt.sign(algorithm);
- verifyClaims();
- return JWS;
- }
-
- /**
- * Creates a new JWT and signs it with the given algorithm.
- *
- * @param algorithm used to sign the JWT
- * @return a new JWT token
- * @throws IllegalAccessException if the developer didn't want NONE algorithm to be allowed and it was passed in
- * @throws IllegalArgumentException if the provided algorithm is null.
- * @throws JWTCreationException if the claims could not be converted to a valid JSON or there was a problem with the signing key.
- */
- public String signBase16Encoding(Algorithm algorithm) throws Exception {
- if(!jwt.getIsNoneAlgorithmAllowed() && algorithm.equals(Algorithm.none())) {
- throw new IllegalAccessException("None algorithm isn't allowed");
- }
- String JWS = jwt.sign(algorithm, EncodeType.Base16);
- verifyClaims();
- return JWS;
- }
-
- /**
- * Creates a new JWT and signs it with the given algorithm.
- *
- * @param algorithm used to sign the JWT
- * @return a new JWT token
- * @throws IllegalAccessException if the developer didn't want NONE algorithm to be allowed and it was passed in
- * @throws IllegalArgumentException if the provided algorithm is null.
- * @throws JWTCreationException if the claims could not be converted to a valid JSON or there was a problem with the signing key.
- */
- public String signBase32Encoding(Algorithm algorithm) throws Exception {
- if(!jwt.getIsNoneAlgorithmAllowed() && algorithm.equals(Algorithm.none())) {
- throw new IllegalAccessException("None algorithm isn't allowed");
- }
- String JWS = jwt.sign(algorithm, EncodeType.Base32);
- verifyClaims();
- return JWS;
- }
-
- /**
- * Verifies that all the standard claims were provided
- * @throws Exception if all the standard claims weren't provided
- */
- private void verifyClaims() throws Exception {
- for(String claim : addedClaims.keySet())
- if(!addedClaims.get(claim))
- throw new Exception("Standard claim: " + claim + " has not been set");
- }
-
- public static ExtendedJwtCreator build() {
- return new ExtendedJwtCreator();
- }
-}
diff --git a/lib/src/main/java/com/auth0/jwt/creators/FbJwtCreator.java b/lib/src/main/java/com/auth0/jwt/creators/FbJwtCreator.java
deleted file mode 100644
index e4ff44e..0000000
--- a/lib/src/main/java/com/auth0/jwt/creators/FbJwtCreator.java
+++ /dev/null
@@ -1,273 +0,0 @@
-// Copyright (c) 2017 The Authors of 'JWTS for Java'
-//
-// Permission is hereby granted, free of charge, to any person obtaining a copy of
-// this software and associated documentation files (the "Software"), to deal in
-// the Software without restriction, including without limitation the rights to
-// use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
-// the Software, and to permit persons to whom the Software is furnished to do so,
-// subject to the following conditions:
-//
-// The above copyright notice and this permission notice shall be included in all
-// copies or substantial portions of the Software.
-//
-// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
-// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
-// FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
-// COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
-// IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
-// CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
-
-package com.auth0.jwt.creators;
-
-import com.auth0.jwt.algorithms.Algorithm;
-import com.auth0.jwt.exceptions.JWTCreationException;
-import com.auth0.jwt.impl.PublicClaims;
-import com.auth0.jwt.jwts.JWT;
-
-import java.util.Date;
-import java.util.HashMap;
-import java.util.HashSet;
-import java.util.Set;
-
-/**
- * The FbJwtCreator class holds the sign method to generate a complete FB JWT (with Signature) from a given Header and Payload content.
- */
-public class FbJwtCreator {
-
- protected JWTCreator.Builder jwt;
- protected HashMap addedClaims;
- protected Set publicClaims;
-
- public FbJwtCreator() {
- jwt = JWT.create();
- addedClaims = new HashMap() {{
- put("UserId", false);
- put("AppId", false);
- put("Iat", false);
- }};
- publicClaims = new HashSet() {{
- add(PublicClaims.ISSUED_AT);
- add(PublicClaims.EXPIRES_AT);
- }};
- }
-
- /**
- * Add a specific Issued At ("iat") claim to the Payload.
- *
- * @param iat the Issued At value.
- * @return this same Builder instance.
- */
- public FbJwtCreator withIat(Date iat) {
- jwt.withIssuedAt(iat);
- addedClaims.put("Iat", true);
- return this;
- }
-
- /**
- * Add a specific Expires At ("exp") claim to the Payload.
- *
- * @param exp the Expires At value.
- * @return this same Builder instance.
- */
- public FbJwtCreator withExp(Date exp) {
- jwt.withExpiresAt(exp);
- return this;
- }
-
- /**
- * Require a specific userId ("userId") claim.
- *
- * @param userId the required userId value
- * @return this same Verification instance.
- */
- public FbJwtCreator withUserId(String userId) {
- jwt.withNonStandardClaim("userId", userId);
- addedClaims.put("UserId", true);
- return this;
- }
-
- /**
- * Require a specific appId ("appId") claim.
- *
- * @param appId the required appId value
- * @return this same Verification instance.
- */
- public FbJwtCreator withAppId(String appId) {
- jwt.withNonStandardClaim("appId", appId);
- addedClaims.put("AppId", true);
- return this;
- }
-
- /**
- * Require a specific Claim value.
- *
- * @param name the Claim's name.
- * @param value the Claim's value.
- * @return this same Verification instance.
- * @throws IllegalArgumentException if the name is null.
- */
- public FbJwtCreator withNonStandardClaim(String name, String value) {
- jwt.withNonStandardClaim(name, value);
- return this;
- }
-
- /**
- * Add a custom Claim value.
- *
- * @param name the Claim's name.
- * @param value the Claim's value.
- * @return this same Builder instance.
- * @throws IllegalArgumentException if the name is null.
- */
- public FbJwtCreator withNonStandardClaim(String name, Boolean value) throws IllegalArgumentException {
- jwt.withNonStandardClaim(name, value);
- return this;
- }
-
- /**
- * Add a custom Claim value.
- *
- * @param name the Claim's name.
- * @param value the Claim's value.
- * @return this same Builder instance.
- * @throws IllegalArgumentException if the name is null.
- */
- public FbJwtCreator withNonStandardClaim(String name, Integer value) throws IllegalArgumentException {
- jwt.withNonStandardClaim(name, value);
- return this;
- }
-
- /**
- * Add a custom Claim value.
- *
- * @param name the Claim's name.
- * @param value the Claim's value.
- * @return this same Builder instance.
- * @throws IllegalArgumentException if the name is null.
- */
- public FbJwtCreator withNonStandardClaim(String name, Long value) throws IllegalArgumentException {
- jwt.withNonStandardClaim(name, value);
- return this;
- }
-
- /**
- * Add a custom Claim value.
- *
- * @param name the Claim's name.
- * @param value the Claim's value.
- * @return this same Builder instance.
- * @throws IllegalArgumentException if the name is null.
- */
- public FbJwtCreator withNonStandardClaim(String name, Double value) throws IllegalArgumentException {
- jwt.withNonStandardClaim(name, value);
- return this;
- }
-
- /**
- * Add a custom Claim value.
- *
- * @param name the Claim's name.
- * @param value the Claim's value.
- * @return this same Builder instance.
- * @throws IllegalArgumentException if the name is null.
- */
- public FbJwtCreator withNonStandardClaim(String name, Date value) throws IllegalArgumentException {
- jwt.withNonStandardClaim(name, value);
- return this;
- }
-
- /**
- * Require a specific Array Claim to contain at least the given items.
- *
- * @param name the Claim's name.
- * @param items the items the Claim must contain.
- * @return this same Verification instance.
- * @throws IllegalArgumentException if the name is null.
- */
- public FbJwtCreator withArrayClaim(String name, String... items) throws IllegalArgumentException {
- jwt.withArrayClaim(name, items);
- if(publicClaims.contains(name))
- addedClaims.put(name, true);
- return this;
- }
-
- /**
- * Developer explicitly specifies whether they want to accept
- * NONE algorithms or not.
- *
- * @param isNoneAlgorithmAllowed
- * @return
- */
- public FbJwtCreator setIsNoneAlgorithmAllowed(boolean isNoneAlgorithmAllowed) {
- jwt.setIsNoneAlgorithmAllowed(isNoneAlgorithmAllowed);
- return this;
- }
-
- /**
- * Creates a new JWT and signs it with the given algorithm.
- *
- * @param algorithm used to sign the JWT
- * @return a new JWT token
- * @throws IllegalAccessException if the developer didn't want NONE algorithm to be allowed and it was passed in
- * @throws IllegalArgumentException if the provided algorithm is null.
- * @throws JWTCreationException if the claims could not be converted to a valid JSON or there was a problem with the signing key.
- */
- public String sign(Algorithm algorithm) throws Exception {
- if(!jwt.getIsNoneAlgorithmAllowed() && algorithm.equals(Algorithm.none())) {
- throw new IllegalAccessException("None algorithm isn't allowed");
- }
- String JWS = jwt.sign(algorithm);
- verifyClaims();
- return JWS;
- }
-
- /**
- * Creates a new JWT and signs it with the given algorithm.
- *
- * @param algorithm used to sign the JWT
- * @return a new JWT token
- * @throws IllegalAccessException if the developer didn't want NONE algorithm to be allowed and it was passed in
- * @throws IllegalArgumentException if the provided algorithm is null.
- * @throws JWTCreationException if the claims could not be converted to a valid JSON or there was a problem with the signing key.
- */
- public String signBase16Encoding(Algorithm algorithm) throws Exception {
- if(!jwt.getIsNoneAlgorithmAllowed() && algorithm.equals(Algorithm.none())) {
- throw new IllegalAccessException("None algorithm isn't allowed");
- }
- String JWS = jwt.sign(algorithm, EncodeType.Base16);
- verifyClaims();
- return JWS;
- }
-
- /**
- * Creates a new JWT and signs it with the given algorithm.
- *
- * @param algorithm used to sign the JWT
- * @return a new JWT token
- * @throws IllegalAccessException if the developer didn't want NONE algorithm to be allowed and it was passed in
- * @throws IllegalArgumentException if the provided algorithm is null.
- * @throws JWTCreationException if the claims could not be converted to a valid JSON or there was a problem with the signing key.
- */
- public String signBase32Encoding(Algorithm algorithm) throws Exception {
- if(!jwt.getIsNoneAlgorithmAllowed() && algorithm.equals(Algorithm.none())) {
- throw new IllegalAccessException("None algorithm isn't allowed");
- }
- String JWS = jwt.sign(algorithm, EncodeType.Base32);
- verifyClaims();
- return JWS;
- }
-
- /**
- * Verifies that all the standard claims were provided
- * @throws Exception if all the standard claims weren't provided
- */
- private void verifyClaims() throws Exception {
- for(String claim : addedClaims.keySet())
- if(!addedClaims.get(claim))
- throw new Exception("Standard claim: " + claim + " has not been set");
- }
-
- public static FbJwtCreator build() {
- return new FbJwtCreator();
- }
-}
diff --git a/lib/src/main/java/com/auth0/jwt/creators/GoogleJwtCreator.java b/lib/src/main/java/com/auth0/jwt/creators/GoogleJwtCreator.java
deleted file mode 100644
index ffd9e66..0000000
--- a/lib/src/main/java/com/auth0/jwt/creators/GoogleJwtCreator.java
+++ /dev/null
@@ -1,332 +0,0 @@
-// Copyright (c) 2017 The Authors of 'JWTS for Java'
-//
-// Permission is hereby granted, free of charge, to any person obtaining a copy of
-// this software and associated documentation files (the "Software"), to deal in
-// the Software without restriction, including without limitation the rights to
-// use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
-// the Software, and to permit persons to whom the Software is furnished to do so,
-// subject to the following conditions:
-//
-// The above copyright notice and this permission notice shall be included in all
-// copies or substantial portions of the Software.
-//
-// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
-// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
-// FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
-// COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
-// IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
-// CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
-
-package com.auth0.jwt.creators;
-
-import com.auth0.jwt.algorithms.Algorithm;
-import com.auth0.jwt.exceptions.JWTCreationException;
-import com.auth0.jwt.impl.PublicClaims;
-import com.auth0.jwt.jwts.JWT;
-
-import java.util.Date;
-import java.util.HashMap;
-import java.util.HashSet;
-import java.util.Set;
-
-/**
- * The GoogleJwtCreator class holds the sign method to generate a complete Google JWT (with Signature) from a given Header and Payload content.
- */
-public class GoogleJwtCreator {
-
- protected JWTCreator.Builder jwt;
- protected HashMap addedClaims;
- protected Set publicClaims;
-
- public GoogleJwtCreator() {
- jwt = JWT.create();
- addedClaims = new HashMap() {{
- put("Name", false);
- put("Email", false);
- put("Picture", false);
- put("Issuer", false);
- put("Subject", false);
- put("Iat", false);
- }};
- publicClaims = new HashSet() {{
- add(PublicClaims.ISSUER);
- add(PublicClaims.SUBJECT);
- add(PublicClaims.EXPIRES_AT);
- add(PublicClaims.NOT_BEFORE);
- add(PublicClaims.ISSUED_AT);
- add(PublicClaims.JWT_ID);
- add(PublicClaims.AUDIENCE);
- }};
- }
-
-
- /**
- * Add a specific Name ("name") claim to the Payload.
- *
- * @param name the Name value.
- * @return this same Builder instance.
- */
- public GoogleJwtCreator withName(String name) {
- jwt.withNonStandardClaim("name", name);
- addedClaims.put("Name", true);
- return this;
- }
-
- /**
- * Add a specific Email ("email") claim to the Payload.
- *
- * @param email the Email value.
- * @return this same Builder instance.
- */
- public GoogleJwtCreator withEmail(String email) {
- jwt.withNonStandardClaim("email", email);
- addedClaims.put("Email", true);
- return this;
- }
-
- /**
- * Add a specific Picture ("picture") claim to the Payload.
- *
- * @param picture the Picture value.
- * @return this same Builder instance.
- */
- public GoogleJwtCreator withPicture(String picture) {
- jwt.withNonStandardClaim("picture", picture);
- addedClaims.put("Picture", true);
- return this;
- }
-
- /**
- * Add a specific Issuer ("issuer") claim to the Payload.
- * Allows for multiple issuers
- *
- * @param issuer the Issuer value.
- * @return this same Builder instance.
- */
- public GoogleJwtCreator withIssuer(String... issuer) {
- jwt.withIssuer(issuer);
- addedClaims.put("Issuer", true);
- return this;
- }
-
- /**
- * Add a specific Subject ("subject") claim to the Payload.
- * Allows for multiple subjects
- *
- * @param subject the Subject value.
- * @return this same Builder instance.
- */
- public GoogleJwtCreator withSubject(String... subject) {
- jwt.withSubject(subject);
- addedClaims.put("Subject", true);
- return this;
- }
-
- /**
- * Add a specific Audience ("audience") claim to the Payload.
- * Allows for multiple audience
- *
- * @param audience the Audience value.
- * @return this same Builder instance.
- */
- public GoogleJwtCreator withAudience(String... audience) {
- jwt.withAudience(audience);
- return this;
- }
-
- /**
- * Add a specific Issued At ("iat") claim to the Payload.
- *
- * @param iat the Issued At value.
- * @return this same Builder instance.
- */
- public GoogleJwtCreator withIat(Date iat) {
- jwt.withIssuedAt(iat);
- addedClaims.put("Iat", true);
- return this;
- }
-
- /**
- * Add a specific Expires At ("exp") claim to the Payload.
- *
- * @param exp the Expires At value.
- * @return this same Builder instance.
- */
- public GoogleJwtCreator withExp(Date exp) {
- jwt.withExpiresAt(exp);
- return this;
- }
-
- /**
- * Require a specific Claim value.
- *
- * @param name the Claim's name.
- * @param value the Claim's value.
- * @return this same Verification instance.
- * @throws IllegalArgumentException if the name is null.
- */
- public GoogleJwtCreator withNonStandardClaim(String name, String value) {
- jwt.withNonStandardClaim(name, value);
- return this;
- }
-
- /**
- * Add a custom Claim value.
- *
- * @param name the Claim's name.
- * @param value the Claim's value.
- * @return this same Builder instance.
- * @throws IllegalArgumentException if the name is null.
- */
- public GoogleJwtCreator withNonStandardClaim(String name, Boolean value) throws IllegalArgumentException {
- jwt.withNonStandardClaim(name, value);
- return this;
- }
-
- /**
- * Add a custom Claim value.
- *
- * @param name the Claim's name.
- * @param value the Claim's value.
- * @return this same Builder instance.
- * @throws IllegalArgumentException if the name is null.
- */
- public GoogleJwtCreator withNonStandardClaim(String name, Integer value) throws IllegalArgumentException {
- jwt.withNonStandardClaim(name, value);
- return this;
- }
-
- /**
- * Add a custom Claim value.
- *
- * @param name the Claim's name.
- * @param value the Claim's value.
- * @return this same Builder instance.
- * @throws IllegalArgumentException if the name is null.
- */
- public GoogleJwtCreator withNonStandardClaim(String name, Long value) throws IllegalArgumentException {
- jwt.withNonStandardClaim(name, value);
- return this;
- }
-
- /**
- * Add a custom Claim value.
- *
- * @param name the Claim's name.
- * @param value the Claim's value.
- * @return this same Builder instance.
- * @throws IllegalArgumentException if the name is null.
- */
- public GoogleJwtCreator withNonStandardClaim(String name, Double value) throws IllegalArgumentException {
- jwt.withNonStandardClaim(name, value);
- return this;
- }
-
- /**
- * Add a custom Claim value.
- *
- * @param name the Claim's name.
- * @param value the Claim's value.
- * @return this same Builder instance.
- * @throws IllegalArgumentException if the name is null.
- */
- public GoogleJwtCreator withNonStandardClaim(String name, Date value) throws IllegalArgumentException {
- jwt.withNonStandardClaim(name, value);
- return this;
- }
-
- /**
- * Require a specific Array Claim to contain at least the given items.
- *
- * @param name the Claim's name.
- * @param items the items the Claim must contain.
- * @return this same Verification instance.
- * @throws IllegalArgumentException if the name is null.
- */
- public GoogleJwtCreator withArrayClaim(String name, String... items) throws IllegalArgumentException {
- jwt.withArrayClaim(name, items);
- if(publicClaims.contains(name))
- addedClaims.put(name, true);
- return this;
- }
-
- /**
- * Developer explicitly specifies whether they want to accept
- * NONE algorithms or not.
- *
- * @param isNoneAlgorithmAllowed
- * @return
- */
- public GoogleJwtCreator setIsNoneAlgorithmAllowed(boolean isNoneAlgorithmAllowed) {
- jwt.setIsNoneAlgorithmAllowed(isNoneAlgorithmAllowed);
- return this;
- }
-
- /**
- * Creates a new JWT and signs it with the given algorithm.
- *
- * @param algorithm used to sign the JWT
- * @return a new JWT token
- * @throws IllegalAccessException if the developer didn't want NONE algorithm to be allowed and it was passed in
- * @throws IllegalArgumentException if the provided algorithm is null.
- * @throws JWTCreationException if the claims could not be converted to a valid JSON or there was a problem with the signing key.
- */
- public String sign(Algorithm algorithm) throws Exception {
- if(!jwt.getIsNoneAlgorithmAllowed() && algorithm.equals(Algorithm.none())) {
- throw new IllegalAccessException("None algorithm isn't allowed");
- }
- String JWS = jwt.sign(algorithm);
- verifyClaims();
- return JWS;
- }
-
- /**
- * Creates a new JWT and signs it with the given algorithm.
- *
- * @param algorithm used to sign the JWT
- * @return a new JWT token
- * @throws IllegalAccessException if the developer didn't want NONE algorithm to be allowed and it was passed in
- * @throws IllegalArgumentException if the provided algorithm is null.
- * @throws JWTCreationException if the claims could not be converted to a valid JSON or there was a problem with the signing key.
- */
- public String signBase16Encoding(Algorithm algorithm) throws Exception {
- if(!jwt.getIsNoneAlgorithmAllowed() && algorithm.equals(Algorithm.none())) {
- throw new IllegalAccessException("None algorithm isn't allowed");
- }
- String JWS = jwt.sign(algorithm, EncodeType.Base16);
- verifyClaims();
- return JWS;
- }
-
- /**
- * Creates a new JWT and signs it with the given algorithm.
- *
- * @param algorithm used to sign the JWT
- * @return a new JWT token
- * @throws IllegalAccessException if the developer didn't want NONE algorithm to be allowed and it was passed in
- * @throws IllegalArgumentException if the provided algorithm is null.
- * @throws JWTCreationException if the claims could not be converted to a valid JSON or there was a problem with the signing key.
- */
- public String signBase32Encoding(Algorithm algorithm) throws Exception {
- if(!jwt.getIsNoneAlgorithmAllowed() && algorithm.equals(Algorithm.none())) {
- throw new IllegalAccessException("None algorithm isn't allowed");
- }
- String JWS = jwt.sign(algorithm, EncodeType.Base32);
- verifyClaims();
- return JWS;
- }
-
- /**
- * Verifies that all the standard claims were provided
- * @throws Exception if all the standard claims weren't provided
- */
- private void verifyClaims() throws Exception {
- for(String claim : addedClaims.keySet())
- if(!addedClaims.get(claim))
- throw new Exception("Standard claim: " + claim + " has not been set");
- }
-
- public static GoogleJwtCreator build() {
- return new GoogleJwtCreator();
- }
-}
diff --git a/lib/src/main/java/com/auth0/jwt/creators/ImplicitJwtCreator.java b/lib/src/main/java/com/auth0/jwt/creators/ImplicitJwtCreator.java
deleted file mode 100644
index 0130e4e..0000000
--- a/lib/src/main/java/com/auth0/jwt/creators/ImplicitJwtCreator.java
+++ /dev/null
@@ -1,278 +0,0 @@
-// Copyright (c) 2017 The Authors of 'JWTS for Java'
-//
-// Permission is hereby granted, free of charge, to any person obtaining a copy of
-// this software and associated documentation files (the "Software"), to deal in
-// the Software without restriction, including without limitation the rights to
-// use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
-// the Software, and to permit persons to whom the Software is furnished to do so,
-// subject to the following conditions:
-//
-// The above copyright notice and this permission notice shall be included in all
-// copies or substantial portions of the Software.
-//
-// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
-// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
-// FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
-// COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
-// IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
-// CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
-
-package com.auth0.jwt.creators;
-
-import com.auth0.jwt.algorithms.Algorithm;
-import com.auth0.jwt.exceptions.JWTCreationException;
-import com.auth0.jwt.impl.PublicClaims;
-import com.auth0.jwt.jwts.JWT;
-
-import java.util.Date;
-import java.util.HashMap;
-import java.util.HashSet;
-import java.util.Set;
-
-/**
- * The ImplicitJwtCreator class holds the sign method to generate a complete Implicit JWT (with Signature) from a given Header and Payload content.
- */
-public class ImplicitJwtCreator {
-
- protected JWTCreator.Builder jwt;
- protected HashMap addedClaims;
- protected Set publicClaims;
-
- public ImplicitJwtCreator() {
- jwt = JWT.create();
- addedClaims = new HashMap() {{
- put("Issuer", false);
- put("Subject", false);
- put("Iat", false);
- }};
- publicClaims = new HashSet() {{
- add(PublicClaims.ISSUER);
- add(PublicClaims.SUBJECT);
- add(PublicClaims.ISSUED_AT);
- add(PublicClaims.AUDIENCE);
- }};
- }
-
- /**
- * Add a specific Issuer ("issuer") claim to the Payload.
- * Allows for multiple issuers
- *
- * @param issuer the Issuer value.
- * @return this same Builder instance.
- */
- public ImplicitJwtCreator withIssuer(String... issuer) {
- jwt.withIssuer(issuer);
- addedClaims.put("Issuer", true);
- return this;
- }
-
- /**
- * Add a specific Subject ("subject") claim to the Payload.
- * Allows for multiple subjects
- *
- * @param subject the Subject value.
- * @return this same Builder instance.
- */
- public ImplicitJwtCreator withSubject(String... subject) {
- jwt.withSubject(subject);
- addedClaims.put("Subject", true);
- return this;
- }
-
- /**
- * Add a specific Audience ("audience") claim to the Payload.
- * Allows for multiple audience
- *
- * @param audience the Audience value.
- * @return this same Builder instance.
- */
- public ImplicitJwtCreator withAudience(String... audience) {
- jwt.withAudience(audience);
- return this;
- }
-
- /**
- * Add a specific Issued At ("iat") claim to the Payload.
- *
- * @param iat the Issued At value.
- * @return this same Builder instance.
- */
- public ImplicitJwtCreator withIat(Date iat) {
- jwt.withIssuedAt(iat);
- addedClaims.put("Iat", true);
- return this;
- }
-
- /**
- * Require a specific Claim value.
- *
- * @param name the Claim's name.
- * @param value the Claim's value.
- * @return this same Verification instance.
- * @throws IllegalArgumentException if the name is null.
- */
- public ImplicitJwtCreator withNonStandardClaim(String name, String value) {
- jwt.withNonStandardClaim(name, value);
- return this;
- }
-
- /**
- * Add a custom Claim value.
- *
- * @param name the Claim's name.
- * @param value the Claim's value.
- * @return this same Builder instance.
- * @throws IllegalArgumentException if the name is null.
- */
- public ImplicitJwtCreator withNonStandardClaim(String name, Boolean value) throws IllegalArgumentException {
- jwt.withNonStandardClaim(name, value);
- return this;
- }
-
- /**
- * Add a custom Claim value.
- *
- * @param name the Claim's name.
- * @param value the Claim's value.
- * @return this same Builder instance.
- * @throws IllegalArgumentException if the name is null.
- */
- public ImplicitJwtCreator withNonStandardClaim(String name, Integer value) throws IllegalArgumentException {
- jwt.withNonStandardClaim(name, value);
- return this;
- }
-
- /**
- * Add a custom Claim value.
- *
- * @param name the Claim's name.
- * @param value the Claim's value.
- * @return this same Builder instance.
- * @throws IllegalArgumentException if the name is null.
- */
- public ImplicitJwtCreator withNonStandardClaim(String name, Long value) throws IllegalArgumentException {
- jwt.withNonStandardClaim(name, value);
- return this;
- }
-
- /**
- * Add a custom Claim value.
- *
- * @param name the Claim's name.
- * @param value the Claim's value.
- * @return this same Builder instance.
- * @throws IllegalArgumentException if the name is null.
- */
- public ImplicitJwtCreator withNonStandardClaim(String name, Double value) throws IllegalArgumentException {
- jwt.withNonStandardClaim(name, value);
- return this;
- }
-
- /**
- * Add a custom Claim value.
- *
- * @param name the Claim's name.
- * @param value the Claim's value.
- * @return this same Builder instance.
- * @throws IllegalArgumentException if the name is null.
- */
- public ImplicitJwtCreator withNonStandardClaim(String name, Date value) throws IllegalArgumentException {
- jwt.withNonStandardClaim(name, value);
- return this;
- }
-
- /**
- * Require a specific Array Claim to contain at least the given items.
- *
- * @param name the Claim's name.
- * @param items the items the Claim must contain.
- * @return this same Verification instance.
- * @throws IllegalArgumentException if the name is null.
- */
- public ImplicitJwtCreator withArrayClaim(String name, String... items) throws IllegalArgumentException {
- jwt.withArrayClaim(name, items);
- if(publicClaims.contains(name))
- addedClaims.put(name, true);
- return this;
- }
-
- /**
- * Developer explicitly specifies whether they want to accept
- * NONE algorithms or not.
- *
- * @param isNoneAlgorithmAllowed
- * @return
- */
- public ImplicitJwtCreator setIsNoneAlgorithmAllowed(boolean isNoneAlgorithmAllowed) {
- jwt.setIsNoneAlgorithmAllowed(isNoneAlgorithmAllowed);
- return this;
- }
-
- /**
- * Creates a new JWT and signs it with the given algorithm.
- *
- * @param algorithm used to sign the JWT
- * @return a new JWT token
- * @throws IllegalAccessException if the developer didn't want NONE algorithm to be allowed and it was passed in
- * @throws IllegalArgumentException if the provided algorithm is null.
- * @throws JWTCreationException if the claims could not be converted to a valid JSON or there was a problem with the signing key.
- */
- public String sign(Algorithm algorithm) throws Exception {
- if(!jwt.getIsNoneAlgorithmAllowed() && algorithm.equals(Algorithm.none())) {
- throw new IllegalAccessException("None algorithm isn't allowed");
- }
- String JWS = jwt.sign(algorithm);
- verifyClaims();
- return JWS;
- }
-
- /**
- * Creates a new JWT and signs it with the given algorithm.
- *
- * @param algorithm used to sign the JWT
- * @return a new JWT token
- * @throws IllegalAccessException if the developer didn't want NONE algorithm to be allowed and it was passed in
- * @throws IllegalArgumentException if the provided algorithm is null.
- * @throws JWTCreationException if the claims could not be converted to a valid JSON or there was a problem with the signing key.
- */
- public String signBase16Encoding(Algorithm algorithm) throws Exception {
- if(!jwt.getIsNoneAlgorithmAllowed() && algorithm.equals(Algorithm.none())) {
- throw new IllegalAccessException("None algorithm isn't allowed");
- }
- String JWS = jwt.sign(algorithm, EncodeType.Base16);
- verifyClaims();
- return JWS;
- }
-
- /**
- * Creates a new JWT and signs it with the given algorithm.
- *
- * @param algorithm used to sign the JWT
- * @return a new JWT token
- * @throws IllegalAccessException if the developer didn't want NONE algorithm to be allowed and it was passed in
- * @throws IllegalArgumentException if the provided algorithm is null.
- * @throws JWTCreationException if the claims could not be converted to a valid JSON or there was a problem with the signing key.
- */
- public String signBase32Encoding(Algorithm algorithm) throws Exception {
- if(!jwt.getIsNoneAlgorithmAllowed() && algorithm.equals(Algorithm.none())) {
- throw new IllegalAccessException("None algorithm isn't allowed");
- }
- String JWS = jwt.sign(algorithm, EncodeType.Base32);
- verifyClaims();
- return JWS;
- }
-
- /**
- * Verifies that all the standard claims were provided
- * @throws Exception if all the standard claims weren't provided
- */
- private void verifyClaims() throws Exception {
- for(String claim : addedClaims.keySet())
- if(!addedClaims.get(claim))
- throw new Exception("Standard claim: " + claim + " has not been set");
- }
-
- public static ImplicitJwtCreator build() {
- return new ImplicitJwtCreator();
- }
-}
diff --git a/lib/src/main/java/com/auth0/jwt/creators/JWTCreator.java b/lib/src/main/java/com/auth0/jwt/creators/JWTCreator.java
deleted file mode 100644
index 54e4f13..0000000
--- a/lib/src/main/java/com/auth0/jwt/creators/JWTCreator.java
+++ /dev/null
@@ -1,454 +0,0 @@
-// Copyright (c) 2017 The Authors of 'JWTS for Java'
-//
-// Permission is hereby granted, free of charge, to any person obtaining a copy of
-// this software and associated documentation files (the "Software"), to deal in
-// the Software without restriction, including without limitation the rights to
-// use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
-// the Software, and to permit persons to whom the Software is furnished to do so,
-// subject to the following conditions:
-//
-// The above copyright notice and this permission notice shall be included in all
-// copies or substantial portions of the Software.
-//
-// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
-// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
-// FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
-// COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
-// IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
-// CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
-
-package com.auth0.jwt.creators;
-
-import com.auth0.jwt.algorithms.Algorithm;
-import com.auth0.jwt.exceptions.JWTCreationException;
-import com.auth0.jwt.exceptions.SignatureGenerationException;
-import com.auth0.jwt.impl.ClaimsHolder;
-import com.auth0.jwt.impl.PayloadSerializer;
-import com.auth0.jwt.impl.PublicClaims;
-import com.fasterxml.jackson.core.JsonProcessingException;
-import com.fasterxml.jackson.databind.MapperFeature;
-import com.fasterxml.jackson.databind.ObjectMapper;
-import com.fasterxml.jackson.databind.module.SimpleModule;
-import org.apache.commons.codec.Encoder;
-import org.apache.commons.codec.binary.Base32;
-import org.apache.commons.codec.binary.Base64;
-import org.apache.commons.codec.binary.Hex;
-import org.apache.commons.codec.binary.StringUtils;
-
-import java.io.*;
-import java.net.URLDecoder;
-import java.net.URLEncoder;
-import java.nio.charset.StandardCharsets;
-import java.util.Date;
-import java.util.HashMap;
-import java.util.Map;
-
-/**
- * The JWTCreator class holds the sign method to generate a complete JWT (with Signature) from a given Header and Payload content.
- */
-@SuppressWarnings("WeakerAccess")
-public final class JWTCreator {
-
- private final Algorithm algorithm;
- private final String headerJson;
- private final String payloadJson;
-
- private JWTCreator(Algorithm algorithm, Map headerClaims, Map payloadClaims) throws JWTCreationException {
- this.algorithm = algorithm;
- try {
- ObjectMapper mapper = new ObjectMapper();
- SimpleModule module = new SimpleModule();
- module.addSerializer(ClaimsHolder.class, new PayloadSerializer());
- mapper.registerModule(module);
- mapper.configure(MapperFeature.SORT_PROPERTIES_ALPHABETICALLY, true);
- headerJson = mapper.writeValueAsString(headerClaims);
- payloadJson = mapper.writeValueAsString(new ClaimsHolder(payloadClaims));
- } catch (JsonProcessingException e) {
- throw new JWTCreationException("Some of the Claims couldn't be converted to a valid JSON format.", e);
- }
- }
-
-
- /**
- * Initialize a JWTCreator instance.
- *
- * @return a JWTCreator.Builder instance to configure.
- */
- public static JWTCreator.Builder init() {
- return new Builder();
- }
-
- /**
- * The Builder class holds the Claims that defines the JWT to be created.
- */
- public static class Builder {
- private final Map payloadClaims;
- private Map headerClaims;
- private boolean isNoneAlgorithmAllowed;
-
- Builder() {
- this.payloadClaims = new HashMap<>();
- this.headerClaims = new HashMap<>();
- this.isNoneAlgorithmAllowed = false;
- }
-
- /**
- * Add specific Claims to set as the Header.
- *
- * @param headerClaims the values to use as Claims in the token's Header.
- * @return this same Builder instance.
- */
- public Builder withHeader(Map headerClaims) {
- this.headerClaims = new HashMap<>(headerClaims);
- return this;
- }
-
- /**
- * Add a specific Key Id ("kid") claim to the Header.
- * If the {@link Algorithm} used to sign this token was instantiated with a KeyProvider, the 'kid' value will be taken from that provider and this one will be ignored.
- *
- * @param keyId the Key Id value.
- * @return this same Builder instance.
- */
- public Builder withKeyId(String keyId) {
- this.headerClaims.put(PublicClaims.KEY_ID, keyId);
- return this;
- }
-
- /**
- * Add a specific Issuer ("iss") claim to the Payload.
- * Allows for multiple issuers
- *
- * @param issuer the Issuer value.
- * @return this same Builder instance.
- */
- public Builder withIssuer(String... issuer) {
- addClaim(PublicClaims.ISSUER, issuer);
- return this;
- }
-
- /**
- * Add a specific Subject ("sub") claim to the Payload.
- * Allows for multiple subjects
- *
- * @param subject the Subject value.
- * @return this same Builder instance.
- */
- public Builder withSubject(String... subject) {
- addClaim(PublicClaims.SUBJECT, subject);
- return this;
- }
-
- /**
- * Add a specific Audience ("aud") claim to the Payload.
- * Allows for multiple audience
- *
- * @param audience the Audience value.
- * @return this same Builder instance.
- */
- public Builder withAudience(String... audience) {
- addClaim(PublicClaims.AUDIENCE, audience);
- return this;
- }
-
- /**
- * Add a specific Expires At ("exp") claim to the Payload.
- *
- * @param expiresAt the Expires At value.
- * @return this same Builder instance.
- */
- public Builder withExpiresAt(Date expiresAt) {
- addClaim(PublicClaims.EXPIRES_AT, expiresAt);
- return this;
- }
-
- /**
- * Add a specific Not Before ("nbf") claim to the Payload.
- *
- * @param notBefore the Not Before value.
- * @return this same Builder instance.
- */
- public Builder withNotBefore(Date notBefore) {
- addClaim(PublicClaims.NOT_BEFORE, notBefore);
- return this;
- }
-
- /**
- * Add a specific Issued At ("iat") claim to the Payload.
- *
- * @param issuedAt the Issued At value.
- * @return this same Builder instance.
- */
- public Builder withIssuedAt(Date issuedAt) {
- addClaim(PublicClaims.ISSUED_AT, issuedAt);
- return this;
- }
-
- /**
- * Add a specific JWT Id ("jti") claim to the Payload.
- *
- * @param jwtId the Token Id value.
- * @return this same Builder instance.
- */
- public Builder withJWTId(String jwtId) {
- addClaim(PublicClaims.JWT_ID, jwtId);
- return this;
- }
-
- /**
- * Developer specifies whether they want to accept
- * NONE algorithms or not.
- *
- * @param isNoneAlgorithmAllowed
- * @return
- */
- public Builder setIsNoneAlgorithmAllowed(boolean isNoneAlgorithmAllowed) {
- this.isNoneAlgorithmAllowed = isNoneAlgorithmAllowed;
- return this;
- }
-
- public boolean getIsNoneAlgorithmAllowed() {
- return this.isNoneAlgorithmAllowed;
- }
-
- /**
- * Add a custom Claim value.
- *
- * @param name the Claim's name.
- * @param value the Claim's value.
- * @return this same Builder instance.
- * @throws IllegalArgumentException if the name is null.
- */
- public Builder withNonStandardClaim(String name, Boolean value) throws IllegalArgumentException {
- assertNonNull(name);
- addClaim(name, value);
- return this;
- }
-
- /**
- * Add a custom Claim value.
- *
- * @param name the Claim's name.
- * @param value the Claim's value.
- * @return this same Builder instance.
- * @throws IllegalArgumentException if the name is null.
- */
- public Builder withNonStandardClaim(String name, Integer value) throws IllegalArgumentException {
- assertNonNull(name);
- addClaim(name, value);
- return this;
- }
-
- /**
- * Add a custom Claim value.
- *
- * @param name the Claim's name.
- * @param value the Claim's value.
- * @return this same Builder instance.
- * @throws IllegalArgumentException if the name is null.
- */
- public Builder withNonStandardClaim(String name, Long value) throws IllegalArgumentException {
- assertNonNull(name);
- addClaim(name, value);
- return this;
- }
-
- /**
- * Add a custom Claim value.
- *
- * @param name the Claim's name.
- * @param value the Claim's value.
- * @return this same Builder instance.
- * @throws IllegalArgumentException if the name is null.
- */
- public Builder withNonStandardClaim(String name, Double value) throws IllegalArgumentException {
- assertNonNull(name);
- addClaim(name, value);
- return this;
- }
-
- /**
- * Add a custom Claim value.
- *
- * @param name the Claim's name.
- * @param value the Claim's value.
- * @return this same Builder instance.
- * @throws IllegalArgumentException if the name is null.
- */
- public Builder withNonStandardClaim(String name, String value) throws IllegalArgumentException {
- assertNonNull(name);
- addClaim(name, value);
- return this;
- }
-
- /**
- * Add a custom Claim value.
- *
- * @param name the Claim's name.
- * @param value the Claim's value.
- * @return this same Builder instance.
- * @throws IllegalArgumentException if the name is null.
- */
- public Builder withNonStandardClaim(String name, Date value) throws IllegalArgumentException {
- assertNonNull(name);
- addClaim(name, value);
- return this;
- }
-
- /**
- * Add a custom Array Claim with the given items.
- *
- * @param name the Claim's name.
- * @param items the Claim's value.
- * @return this same Builder instance.
- * @throws IllegalArgumentException if the name is null.
- */
- public Builder withArrayClaim(String name, String[] items) throws IllegalArgumentException {
- assertNonNull(name);
- addClaim(name, items);
- return this;
- }
-
- /**
- * Add a custom Array Claim with the given items.
- *
- * @param name the Claim's name.
- * @param items the Claim's value.
- * @return this same Builder instance.
- * @throws IllegalArgumentException if the name is null.
- */
- public Builder withArrayClaim(String name, Integer[] items) throws IllegalArgumentException {
- assertNonNull(name);
- addClaim(name, items);
- return this;
- }
-
- /**
- * Add a custom Array Claim with the given items.
- *
- * @param name the Claim's name.
- * @param items the Claim's value.
- * @return this same Builder instance.
- * @throws IllegalArgumentException if the name is null.
- */
- public Builder withArrayClaim(String name, Long[] items) throws IllegalArgumentException {
- assertNonNull(name);
- addClaim(name, items);
- return this;
- }
-
- /**
- * Creates a new JWT and signs it with the given algorithm
- * Defaults to Base64 encoding
- *
- * @param algorithm used to sign the JWT
- * @return a new JWT token
- * @throws IllegalArgumentException if the provided algorithm is null.
- * @throws JWTCreationException if the claims could not be converted to a valid JSON or there was a problem with the signing key.
- */
- public String sign(Algorithm algorithm) throws Exception{
- return sign(algorithm, EncodeType.Base64);
- }
-
- /**
- * Creates a new JWT and signs it with the given algorithm
- *
- * @param algorithm used to sign the JWT
- * @param encodeType specifies which base encoding is required
- * @return a new JWT token
- * @throws IllegalArgumentException if the provided algorithm is null.
- * @throws JWTCreationException if the claims could not be converted to a valid JSON or there was a problem with the signing key.
- */
- public String sign(Algorithm algorithm, EncodeType encodeType) throws Exception {
- if (algorithm == null) {
- throw new IllegalArgumentException("The Algorithm cannot be null.");
- }
- if(encodeType == null) {
- throw new IllegalArgumentException("Encodetype cannot be null.");
- }
- headerClaims.put(PublicClaims.ALGORITHM, algorithm.getName());
- headerClaims.put(PublicClaims.TYPE, "JWT");
- String signingKeyId = algorithm.getSigningKeyId();
- if (signingKeyId != null) {
- withKeyId(signingKeyId);
- }
- JWTCreator jwtCreator = new JWTCreator(algorithm, headerClaims, payloadClaims);
- String token = null;
- switch (encodeType) {
- case Base16:
- token = jwtCreator.signBase16Encoding();
- break;
- case Base32:
- token = jwtCreator.signBase32Encoding();
- break;
- case Base64:
- token = jwtCreator.defaultSign();
- break;
- }
-
- return token;
- }
-
- protected void assertNonNull(String name) {
- if (name == null) {
- throw new IllegalArgumentException("The Custom Claim's name can't be null.");
- }
- }
-
- private void addClaim(String name, Object value) {
- if (value == null) {
- payloadClaims.remove(name);
- return;
- }
- payloadClaims.put(name, value);
- }
- }
-
- private String signBase16Encoding() throws UnsupportedEncodingException {
- String header = URLEncoder.encode(headerJson, "UTF-8");
- String payload = URLEncoder.encode(payloadJson, "UTF-8");
-
- byte[] bHeader = header.getBytes("UTF-8");
- String encodedHeader = Hex.encodeHexString(bHeader);
-
- byte[] bPayload = payload.getBytes("UTF-8");
- String encodedPayload = Hex.encodeHexString(bPayload);
-
- String content = String.format("%s.%s", encodedHeader, encodedPayload);
- byte[] signatureBytes = algorithm.sign(content.getBytes(StandardCharsets.UTF_8));
- String signature = Hex.encodeHexString(signatureBytes);
- String signatureFinal = URLEncoder.encode(signature, "UTF-8");
-
- return String.format("%s.%s", content, signatureFinal);
- }
-
- private String signBase32Encoding() throws UnsupportedEncodingException{
- Base32 base32 = new Base32();
- String header = URLEncoder.encode(headerJson, "UTF-8");
- String payload = URLEncoder.encode(payloadJson, "UTF-8");
-
- byte[] bHeader = header.getBytes("UTF-8");
- String encodedHeader = base32.encodeAsString(bHeader);
-
- byte[] bPayload = payload.getBytes("UTF-8");
- String encodedPayload = base32.encodeAsString(bPayload);
-
- String content = String.format("%s.%s", encodedHeader, encodedPayload);
- byte[] signatureBytes = algorithm.sign(content.getBytes(StandardCharsets.UTF_8));
- String signature = base32.encodeAsString(signatureBytes);
- String signatureFinal = URLEncoder.encode(signature, "UTF-8");
-
- return String.format("%s.%s", content, signatureFinal);
- }
-
- private String defaultSign() throws SignatureGenerationException {
- String header = Base64.encodeBase64URLSafeString(headerJson.getBytes(StandardCharsets.UTF_8));
- String payload = Base64.encodeBase64URLSafeString(payloadJson.getBytes(StandardCharsets.UTF_8));
- String content = String.format("%s.%s", header, payload);
-
- byte[] signatureBytes = algorithm.sign(content.getBytes(StandardCharsets.UTF_8));
- String signature = Base64.encodeBase64URLSafeString(signatureBytes);
-
- return String.format("%s.%s", content, signature);
- }
-}
diff --git a/lib/src/main/java/com/auth0/jwt/creators/Message.java b/lib/src/main/java/com/auth0/jwt/creators/Message.java
deleted file mode 100644
index 45d252c..0000000
--- a/lib/src/main/java/com/auth0/jwt/creators/Message.java
+++ /dev/null
@@ -1,51 +0,0 @@
-// Copyright (c) 2017 The Authors of 'JWTS for Java'
-//
-// Permission is hereby granted, free of charge, to any person obtaining a copy of
-// this software and associated documentation files (the "Software"), to deal in
-// the Software without restriction, including without limitation the rights to
-// use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
-// the Software, and to permit persons to whom the Software is furnished to do so,
-// subject to the following conditions:
-//
-// The above copyright notice and this permission notice shall be included in all
-// copies or substantial portions of the Software.
-//
-// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
-// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
-// FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
-// COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
-// IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
-// CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
-
-package com.auth0.jwt.creators;
-
-import com.fasterxml.jackson.core.type.TypeReference;
-import com.fasterxml.jackson.databind.ObjectMapper;
-import com.google.gson.Gson;
-
-import java.io.IOException;
-import java.io.UnsupportedEncodingException;
-import java.net.URLDecoder;
-import java.net.URLEncoder;
-import java.util.HashMap;
-import java.util.Map;
-
-public class Message {
-
- public String toUrlEncoded(String json) throws UnsupportedEncodingException {
- return URLEncoder.encode(json, "UTF-8");
- }
-
- public String toUrlDecoded(String urlEncoded) throws UnsupportedEncodingException {
- return URLDecoder.decode(urlEncoded, "UTF-8");
- }
-
- public String toJSON(HashMap hashMap) {
- return new Gson().toJson(hashMap);
- }
-
- public HashMap fromJSON(String json) throws IOException {
- return new ObjectMapper().readValue(json, new TypeReference