Skip to content

Commit

Permalink
add a new java file
Browse files Browse the repository at this point in the history
  • Loading branch information
sebastianrevuelta committed Oct 24, 2023
1 parent b9e462c commit 63b68a5
Showing 1 changed file with 52 additions and 0 deletions.
52 changes: 52 additions & 0 deletions App.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
package jwt_test.jwt_test_1;

import com.auth0.jwt.JWT;
import com.auth0.jwt.algorithms.Algorithm;
import com.auth0.jwt.exceptions.JWTCreationException;

public class App
{

private static void bad1() {
try {
// ruleid: java-jwt-none-alg
Algorithm algorithm = Algorithm.none();
String token = JWT.create()
.withIssuer("auth0")
.sign(algorithm);
} catch (JWTCreationException exception){
//Invalid Signing configuration / Couldn't convert Claims.
}
}

private static void bad2() {
try {
// ruleid: java-jwt-none-alg
String token = JWT.create()
.withIssuer("auth0")
.sign(Algorithm.none());
} catch (JWTCreationException exception){
//Invalid Signing configuration / Couldn't convert Claims.
}
}

private static void ok1(String secretKey) {
try {
// ok: java-jwt-none-alg
Algorithm algorithm = Algorithm.HMAC256(secretKey);
String token = JWT.create()
.withIssuer("auth0")
.sign(algorithm);
} catch (JWTCreationException exception){
//Invalid Signing configuration / Couldn't convert Claims.
}
}

public static void main( String[] args )
{
bad1();
bad2();
ok1(args[0]);
}
}

0 comments on commit 63b68a5

Please sign in to comment.