use of com.auth0.android.jwt.Claim in project balcaovirtual by trf2-jus-br.
the class CertidaoObterTokenGet method jwt.
public static String jwt(String certidao, String requisitante, String cpfcnpj) throws Exception {
final String issuer = Utils.getJwtIssuer();
// issued at claim
final long iat = System.currentTimeMillis() / 1000L;
// token expires in 12h
final long exp = iat + 12 * 60 * 60L;
final JWTSigner signer = new JWTSigner(Utils.getApiPassword());
final HashMap<String, Object> claims = new HashMap<String, Object>();
if (issuer != null)
claims.put("iss", issuer);
claims.put("exp", exp);
claims.put("iat", iat);
claims.put("certidao", certidao);
claims.put("requisitante", requisitante);
claims.put("cpfcnpj", cpfcnpj);
claims.put("typ", "consulta-certidao");
final String jwt = signer.sign(claims);
return jwt;
}
use of com.auth0.android.jwt.Claim in project bank-of-sirius by nginxinc.
the class JWTAuthenticator method extractClaimFromBearerToken.
Claim extractClaimFromBearerToken(final String bearerToken, final String claimName) {
final DecodedJWT jwt;
try {
jwt = verifier.verify(bearerToken);
} catch (JWTVerificationException e) {
throw new AuthenticationException("Unable to decode or verify JWT bearer token", e);
}
final Claim claim = jwt.getClaim(claimName);
if (claim.isNull()) {
throw new AuthenticationException("Unable to extract account id claim from JWT bearer token");
}
return claim;
}
use of com.auth0.android.jwt.Claim in project kikaha.rocker by jmilagroso.
the class Security method valid.
/**
* Validates token
* @param token The token string parameter.
* @param id The id string/integer parameter.
* @param claim The claim string parameter.
* @param issuer The issuer string parameter.
* @return boolean Is valid.
*/
public boolean valid(String token, String id, String claim, String issuer) {
boolean valid = false;
try {
verifier = JWT.require(algorithm).withJWTId(id).withClaim("name", claim).withIssuer(issuer).build();
DecodedJWT jwt = verifier.verify(token);
valid = true;
} catch (Exception e) {
throw new IllegalStateException(e.getLocalizedMessage());
}
return valid;
}
use of com.auth0.android.jwt.Claim in project yyl_example by Relucent.
the class JwtDemo method main.
public static void main(String[] args) throws Exception {
long currentMillis = System.currentTimeMillis();
// JWT 生存时间(5秒)
long ttl = 5000;
// 生成JWT的时间
Date iat = new Date(currentMillis);
// 生成JWT失效时间
Date exp = new Date(currentMillis + ttl);
// 签名秘钥
String secret = "key";
// 签发人
String issuer = "root";
// 算法
Algorithm algorithm = Algorithm.HMAC256(secret);
// 本地的密码解码
JWTCreator.Builder builder = JWT.create();
// 签发时间
builder.withIssuedAt(iat);
// 签发人
builder.withIssuer(issuer);
// 过期时间
builder.withExpiresAt(exp);
// 主题
builder.withClaim("subject", "MySubject");
String token = builder.sign(algorithm);
System.out.println(token);
// 解密
JWTVerifier verifier = JWT.require(algorithm).withIssuer(issuer).build();
DecodedJWT jwt = verifier.verify(token);
Map<String, Claim> claims = jwt.getClaims();
NullClaim nullClaim = new NullClaim();
System.out.println(claims.getOrDefault("subject", nullClaim).asString());
// 等待5秒
System.out.println("Wait 5 seconds!");
Thread.sleep(5000);
try {
// 这时候Token已经超时了,会抛出异常
verifier.verify(token);
} catch (JWTVerificationException e) {
System.err.println(e);
}
}
use of com.auth0.android.jwt.Claim in project cryptography by norkator.
the class JWT method createECDSA256Jwt.
/**
* Create elliptic curve based JWT
*
* @param privatePem of EC keypair
* @param issuer party name
* @return json web token
* @throws JWTCreationException if jwt creation fails
*/
public static String createECDSA256Jwt(String privatePem, String issuer) throws InvalidKeySpecException, NoSuchAlgorithmException {
ECKey privateKey = (ECKey) PEMToKey.getPemPrivateKey(privatePem, "ECDSA");
Algorithm algorithm = Algorithm.ECDSA256(privateKey);
return com.auth0.jwt.JWT.create().withIssuer(issuer).withClaim("test claim", "test claim value").sign(algorithm);
}
Aggregations