本文整理汇总了Java中com.auth0.jwt.algorithms.Algorithm.HMAC256属性的典型用法代码示例。如果您正苦于以下问题:Java Algorithm.HMAC256属性的具体用法?Java Algorithm.HMAC256怎么用?Java Algorithm.HMAC256使用的例子?那么, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在类com.auth0.jwt.algorithms.Algorithm
的用法示例。
在下文中一共展示了Algorithm.HMAC256属性的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: testImplicitJwtCreatorNonStandardClaimLongValue
@Test
public void testImplicitJwtCreatorNonStandardClaimLongValue() throws Exception {
Algorithm algorithm = Algorithm.HMAC256("secret");
String token = ImplicitJwtCreator.build()
.withIssuer("issuer")
.withSubject("subject")
.withAudience("audience")
.withIat(TimeUtil.generateRandomIatDateInPast())
.withNonStandardClaim("nonStandardClaim", 999L)
.sign(algorithm);
Verification verification = ImplicitJWT.require(algorithm);
JWT verifier = verification.createVerifierForImplicit(asList("issuer"), asList("audience"), 1).build();
DecodedJWT jwt = verifier.decode(token);
Map<String, Claim> claims = jwt.getClaims();
verifyClaims(claims);
}
示例2: testRiscJwtCreatorNonStandardClaimIntegerValue
@Test
public void testRiscJwtCreatorNonStandardClaimIntegerValue() throws Exception {
Algorithm algorithm = Algorithm.HMAC256("secret");
String token = RiscJwtCreator.build()
.withJWTId(jti)
.withIssuer("issuer")
.withSubject("subject")
.withAudience("audience")
.withNonStandardClaim("nonStandardClaim", 999)
.withExp(exp)
.withIat(iat)
.sign(algorithm);
Verification verification = RiscJWT.require(algorithm);
JWT verifier = verification.createVerifierForRisc(jti, asList("issuer"), asList("audience"), 1, 1, 1).build();
DecodedJWT jwt = verifier.decode(token);
Map<String, Claim> claims = jwt.getClaims();
verifyClaims(claims, exp);
}
示例3: testExtendedJwtCreatorBase32Encoding
@Test
public void testExtendedJwtCreatorBase32Encoding() throws Exception {
Algorithm algorithm = Algorithm.HMAC256("secret");
String token = ExtendedJwtCreator.build()
.withNbf(nbf) //this must be called first since ExtendedJwtCreator.build() returns an instance of ExtendedJwtCreator
.withPicture(PICTURE)
.withEmail(EMAIL)
.withIssuer("issuer")
.withSubject("subject")
.withAudience("audience")
.withExp(exp)
.withIat(iat)
.withName(NAME)
.signBase32Encoding(algorithm);
GoogleVerification verification = ExtendedJWT.require(algorithm);
JWT verifier = verification.createVerifierForExtended(PICTURE, EMAIL, asList("issuer"), asList("audience"),
NAME, 1, 1, 1).build();
DecodedJWT jwt = verifier.decode32Bytes(token);
Map<String, Claim> claims = jwt.getClaims();
verifyClaims(claims, exp);
}
示例4: testRiscJwtCreatorInvalidIssuer
@Test
public void testRiscJwtCreatorInvalidIssuer() throws Exception {
thrown.expect(InvalidClaimException.class);
thrown.expectMessage("The Claim 'iss' value doesn't match the required one.");
Algorithm algorithm = Algorithm.HMAC256("secret");
String token = RiscJwtCreator.build()
.withJWTId(jti)
.withNbf(nbf)
.withIssuer("invalid")
.withSubject("subject")
.withAudience("audience")
.withExp(exp)
.withIat(iat)
.sign(algorithm);
Verification verification = RiscJWT.require(algorithm);
JWT verifier = verification.createVerifierForRisc(jti, asList("issuer"), asList("audience"), 1, 1, 1).build();
DecodedJWT jwt = verifier.decode(token);
}
示例5: testAccessJwtCreatorNonStandardClaimDateValue
@Test
public void testAccessJwtCreatorNonStandardClaimDateValue() throws Exception {
Algorithm algorithm = Algorithm.HMAC256("secret");
String token = AccessJwtCreator.build()
.withIssuer("issuer")
.withSubject("subject")
.withAudience("audience")
.withNonStandardClaim("nonStandardClaim", new Date())
.withExp(exp)
.withIat(iat)
.sign(algorithm);
Verification verification = AccessJWT.require(algorithm);
JWT verifier = verification.createVerifierForAccess(asList("issuer"), asList("audience"), 1, 1).build();
DecodedJWT jwt = verifier.decode(token);
Map<String, Claim> claims = jwt.getClaims();
verifyClaims(claims, exp);
}
示例6: testImplicitJwtCreatorNonStandardClaimIntegerValue
@Test
public void testImplicitJwtCreatorNonStandardClaimIntegerValue() throws Exception {
Algorithm algorithm = Algorithm.HMAC256("secret");
String token = ImplicitJwtCreator.build()
.withIssuer("issuer")
.withSubject("subject")
.withAudience("audience")
.withIat(TimeUtil.generateRandomIatDateInPast())
.withNonStandardClaim("nonStandardClaim", 999)
.sign(algorithm);
Verification verification = ImplicitJWT.require(algorithm);
JWT verifier = verification.createVerifierForImplicit(asList("issuer"), asList("audience"), 1).build();
DecodedJWT jwt = verifier.decode(token);
Map<String, Claim> claims = jwt.getClaims();
verifyClaims(claims);
}
示例7: testImplicitJwtCreatorNonStandardClaimStringValue
@Test
public void testImplicitJwtCreatorNonStandardClaimStringValue() throws Exception {
Algorithm algorithm = Algorithm.HMAC256("secret");
String token = ImplicitJwtCreator.build()
.withIssuer("issuer")
.withSubject("subject")
.withAudience("audience")
.withIat(TimeUtil.generateRandomIatDateInPast())
.withNonStandardClaim("nonStandardClaim", "nonStandardClaimValue")
.sign(algorithm);
Verification verification = ImplicitJWT.require(algorithm);
JWT verifier = verification.createVerifierForImplicit(asList("issuer"), asList("audience"), 1).build();
DecodedJWT jwt = verifier.decode(token);
Map<String, Claim> claims = jwt.getClaims();
verifyClaims(claims);
}
示例8: testAccessJwtCreatorNonStandardClaimDoubleValue
@Test
public void testAccessJwtCreatorNonStandardClaimDoubleValue() throws Exception {
Algorithm algorithm = Algorithm.HMAC256("secret");
String token = AccessJwtCreator.build()
.withIssuer("issuer")
.withSubject("subject")
.withAudience("audience")
.withNonStandardClaim("nonStandardClaim", 9.99)
.withExp(exp)
.withIat(iat)
.sign(algorithm);
Verification verification = AccessJWT.require(algorithm);
JWT verifier = verification.createVerifierForAccess(asList("issuer"), asList("audience"), 1, 1).build();
DecodedJWT jwt = verifier.decode(token);
Map<String, Claim> claims = jwt.getClaims();
verifyClaims(claims, exp);
}
示例9: signToken
private String signToken(User user) {
try {
Algorithm algorithm = Algorithm.HMAC256(Constants.JWT_TOKEN_KEY);
Date expirationDate = Date.from(ZonedDateTime.now().plusHours(24).toInstant());
Date issuedAt = Date.from(ZonedDateTime.now().toInstant());
return JWT.create()
.withIssuedAt(issuedAt)
.withExpiresAt(expirationDate)
.withClaim("userId", user.getId())
.withIssuer("jwtauth")
.sign(algorithm);
} catch (UnsupportedEncodingException | JWTCreationException e) {
LOGGER.error(e.getMessage(), e);
}
return null;
}
示例10: testRiscJwtCreatorNonStandardClaimStringValue
@Test
public void testRiscJwtCreatorNonStandardClaimStringValue() throws Exception {
Algorithm algorithm = Algorithm.HMAC256("secret");
String token = RiscJwtCreator.build()
.withJWTId(jti)
.withIssuer("issuer")
.withSubject("subject")
.withAudience("audience")
.withNonStandardClaim("nonStandardClaim", "nonStandardClaimValue")
.withExp(exp)
.withIat(iat)
.sign(algorithm);
Verification verification = RiscJWT.require(algorithm);
JWT verifier = verification.createVerifierForRisc(jti, asList("issuer"), asList("audience"), 1, 1, 1).build();
DecodedJWT jwt = verifier.decode(token);
Map<String, Claim> claims = jwt.getClaims();
verifyClaims(claims, exp);
}
示例11: testScopedJwtCreatorBase32Encoding
@Test
public void testScopedJwtCreatorBase32Encoding() throws Exception {
Algorithm algorithm = Algorithm.HMAC256("secret");
String token = ScopedJwtCreator.build()
.withScope("scope")
.withIssuer("issuer")
.withSubject("subject")
.withAudience("audience")
.withExp(exp)
.withIat(iat)
.signBase32Encoding(algorithm);
Verification verification = ScopedJWT.require(algorithm);
JWT verifier = verification.createVerifierForScoped("scope", asList("issuer"), asList("audience"), 1, 1).build();
DecodedJWT jwt = verifier.decode32Bytes(token);
Map<String, Claim> claims = jwt.getClaims();
verifyClaims(claims, exp);
}
示例12: testExtendedJwtCreatorBase16Encoding
@Test
public void testExtendedJwtCreatorBase16Encoding() throws Exception {
Algorithm algorithm = Algorithm.HMAC256("secret");
String token = ExtendedJwtCreator.build()
.withNbf(nbf) //this must be called first since ExtendedJwtCreator.build() returns an instance of ExtendedJwtCreator
.withPicture(PICTURE)
.withEmail(EMAIL)
.withIssuer("issuer")
.withSubject("subject")
.withAudience("audience")
.withExp(exp)
.withIat(iat)
.withName(NAME)
.signBase16Encoding(algorithm);
GoogleVerification verification = ExtendedJWT.require(algorithm);
JWT verifier = verification.createVerifierForExtended(PICTURE, EMAIL, asList("issuer"), asList("audience"),
NAME, 1, 1, 1).build();
DecodedJWT jwt = verifier.decode16Bytes(token);
Map<String, Claim> claims = jwt.getClaims();
verifyClaims(claims, exp);
}
示例13: testAccessJwtCreatorBase32Encoding
@Test
public void testAccessJwtCreatorBase32Encoding() throws Exception {
Algorithm algorithm = Algorithm.HMAC256("secret");
String token = AccessJwtCreator.build()
.withIssuer("issuer")
.withSubject("subject")
.withAudience("audience")
.withExp(exp)
.withIat(iat)
.signBase32Encoding(algorithm);
Verification verification = AccessJWT.require(algorithm);
JWT verifier = verification.createVerifierForAccess(asList("issuer"), asList("audience"), 1, 1).build();
DecodedJWT jwt = verifier.decode32Bytes(token);
Map<String, Claim> claims = jwt.getClaims();
verifyClaims(claims, exp);
}
示例14: testFbJwtCreatorArrayClaim
@Test
public void testFbJwtCreatorArrayClaim() throws Exception {
Algorithm algorithm = Algorithm.HMAC256("secret");
String token = FbJwtCreator.build()
.withExp(exp)
.withIat(iat)
.withUserId(USER_ID)
.withAppId(APP_ID)
.setIsNoneAlgorithmAllowed(true)
.withArrayClaim("arrayKey", "arrayValue1", "arrayValue2")
.sign(algorithm);
Verification verification = FbJWT.require(algorithm);
JWT verifier = verification.createVerifierForFb(USER_ID, APP_ID).build();
DecodedJWT jwt = verifier.decode(token);
Map<String, Claim> claims = jwt.getClaims();
verifyClaims(claims);
}
示例15: testRiscJwtCreatorInvalidAudience
@Test
public void testRiscJwtCreatorInvalidAudience() throws Exception {
thrown.expect(InvalidClaimException.class);
thrown.expectMessage("The Claim 'aud' value doesn't contain the required audience.");
Algorithm algorithm = Algorithm.HMAC256("secret");
String token = RiscJwtCreator.build()
.withJWTId(jti)
.withNbf(nbf)
.withIssuer("issuer")
.withSubject("subject")
.withAudience("invalid")
.withExp(exp)
.withIat(iat)
.sign(algorithm);
Verification verification = RiscJWT.require(algorithm);
JWT verifier = verification.createVerifierForRisc(jti, asList("issuer"), asList("audience"), 1, 1, 1).build();
DecodedJWT jwt = verifier.decode(token);
}