本文整理汇总了Java中com.auth0.jwt.interfaces.DecodedJWT类的典型用法代码示例。如果您正苦于以下问题:Java DecodedJWT类的具体用法?Java DecodedJWT怎么用?Java DecodedJWT使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
DecodedJWT类属于com.auth0.jwt.interfaces包,在下文中一共展示了DecodedJWT类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: shouldDoRSA512SigningWithBothKeys
import com.auth0.jwt.interfaces.DecodedJWT; //导入依赖的package包/类
@Test
public void shouldDoRSA512SigningWithBothKeys() throws Exception {
Algorithm algorithm = Algorithm.RSA512((RSAPublicKey) readPublicKeyFromFile(PUBLIC_KEY_FILE, "RSA"), (RSAPrivateKey) readPrivateKeyFromFile(PRIVATE_KEY_FILE, "RSA"));
String jwtContent = String.format("%s.%s", RS512Header, auth0IssPayload);
byte[] contentBytes = jwtContent.getBytes(StandardCharsets.UTF_8);
byte[] signatureBytes = algorithm.sign(contentBytes);
String jwtSignature = Base64.encodeBase64URLSafeString(signatureBytes);
String token = String.format("%s.%s", jwtContent, jwtSignature);
String expectedSignature = "THIPVYzNZ1Yo_dm0k1UELqV0txs3SzyMopCyHcLXOOdgYXF4MlGvBqu0CFvgSga72Sp5LpuC1Oesj40v_QDsp2GTGDeWnvvcv_eo-b0LPSpmT2h1Ibrmu-z70u2rKf28pkN-AJiMFqi8sit2kMIp1bwIVOovPvMTQKGFmova4Xwb3G526y_PeLlflW1h69hQTIVcI67ACEkAC-byjDnnYIklA-B4GWcggEoFwQRTdRjAUpifA6HOlvnBbZZlUd6KXwEydxVS-eh1odwPjB2_sfbyy5HnLsvNdaniiZQwX7QbwLNT4F72LctYdHHM1QCrID6bgfgYp9Ij9CRX__XDEA";
assertThat(signatureBytes, is(notNullValue()));
assertThat(jwtSignature, is(expectedSignature));
JWT jwt = JWT.require(algorithm).withIssuer("auth0").build();
DecodedJWT decoded = jwt.decode(token);
algorithm.verify(decoded, EncodeType.Base64);
}
示例2: testImplicitJwtCreatorNonStandardClaimIntegerValue
import com.auth0.jwt.interfaces.DecodedJWT; //导入依赖的package包/类
@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);
}
示例3: testExtendedJwtCreatorInvalidAudience
import com.auth0.jwt.interfaces.DecodedJWT; //导入依赖的package包/类
@Test
public void testExtendedJwtCreatorInvalidAudience() 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 = 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("invalid")
.withExp(exp)
.withIat(iat)
.withName(NAME)
.sign(algorithm);
GoogleVerification verification = ExtendedJWT.require(algorithm);
JWT verifier = verification.createVerifierForExtended(PICTURE, EMAIL, asList("issuer"), asList("audience"),
NAME, 1, 1, 1).build();
DecodedJWT jwt = verifier.decode(token);
Map<String, Claim> claims = jwt.getClaims();
verifyClaims(claims, exp);
}
示例4: testAccessJwtCreatorNoneAlgorithmNotAllowed
import com.auth0.jwt.interfaces.DecodedJWT; //导入依赖的package包/类
@Test
public void testAccessJwtCreatorNoneAlgorithmNotAllowed() throws Exception {
thrown.expect(IllegalAccessException.class);
thrown.expectMessage("None algorithm isn't allowed");
Algorithm algorithm = Algorithm.none();
String token = AccessJwtCreator.build()
.withIssuer("issuer")
.withSubject("subject")
.withAudience("audience")
.withExp(exp)
.withIat(iat)
.setIsNoneAlgorithmAllowed(false)
.sign(algorithm);
Verification verification = AccessJWT.require(algorithm);
JWT verifier = verification.createVerifierForAccess(asList("issuer"), asList("audience"), 1, 1).build();
DecodedJWT jwt = verifier.decode(token);
}
示例5: testGoogleJwtCreatorBase32Encoding
import com.auth0.jwt.interfaces.DecodedJWT; //导入依赖的package包/类
@Test
public void testGoogleJwtCreatorBase32Encoding() throws Exception {
Algorithm algorithm = Algorithm.HMAC256("secret");
String token = GoogleJwtCreator.build()
.withPicture(PICTURE)
.withEmail(EMAIL)
.withIssuer("issuer")
.withSubject("subject")
.withAudience("audience")
.withExp(exp)
.withIat(iat)
.withName(NAME)
.signBase32Encoding(algorithm);
GoogleVerification verification = GoogleJWT.require(algorithm);
JWT verifier = verification.createVerifierForGoogle(PICTURE, EMAIL, asList("issuer"), asList("audience"),
NAME, 1, 1).build();
DecodedJWT jwt = verifier.decode32Bytes(token);
Map<String, Claim> claims = jwt.getClaims();
verifyClaims(claims, exp);
}
示例6: testAccessJwtCreatorBase16Encoding
import com.auth0.jwt.interfaces.DecodedJWT; //导入依赖的package包/类
@Test
public void testAccessJwtCreatorBase16Encoding() throws Exception {
Algorithm algorithm = Algorithm.HMAC256("secret");
String token = AccessJwtCreator.build()
.withIssuer("issuer")
.withSubject("subject")
.withAudience("audience")
.withExp(exp)
.withIat(iat)
.signBase16Encoding(algorithm);
Verification verification = AccessJWT.require(algorithm);
JWT verifier = verification.createVerifierForAccess(asList("issuer"), asList("audience"), 1, 1).build();
DecodedJWT jwt = verifier.decode16Bytes(token);
Map<String, Claim> claims = jwt.getClaims();
verifyClaims(claims, exp);
}
示例7: testExtendedJwtCreatorNoneAlgorithmAllowed
import com.auth0.jwt.interfaces.DecodedJWT; //导入依赖的package包/类
@Test
public void testExtendedJwtCreatorNoneAlgorithmAllowed() throws Exception {
Algorithm algorithm = Algorithm.none();
String token = ExtendedJwtCreator.build()
.withNbf(nbf)
.withPicture(PICTURE)
.withEmail(EMAIL)
.withIssuer("issuer")
.withSubject("subject")
.withAudience("audience")
.withExp(exp)
.withIat(iat)
.withName(NAME)
.setIsNoneAlgorithmAllowed(true)
.sign(algorithm);
GoogleVerification verification = ExtendedJWT.require(algorithm);
JWT verifier = verification.createVerifierForExtended(PICTURE, EMAIL, asList("issuer"), asList("audience"),
NAME, 1, 1, 1).build();
DecodedJWT jwt = verifier.decode(token);
Map<String, Claim> claims = jwt.getClaims();
verifyClaims(claims, exp);
}
示例8: testImplicitJwtCreatorNonStandardClaimBooleanValue
import com.auth0.jwt.interfaces.DecodedJWT; //导入依赖的package包/类
@Test
public void testImplicitJwtCreatorNonStandardClaimBooleanValue() throws Exception {
Algorithm algorithm = Algorithm.HMAC256("secret");
String token = ImplicitJwtCreator.build()
.withIssuer("issuer")
.withSubject("subject")
.withAudience("audience")
.withIat(TimeUtil.generateRandomIatDateInPast())
.withNonStandardClaim("nonStandardClaim", true)
.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);
}
示例9: shouldDoRSA256SigningWithProvidedPrivateKey
import com.auth0.jwt.interfaces.DecodedJWT; //导入依赖的package包/类
@Test
public void shouldDoRSA256SigningWithProvidedPrivateKey() throws Exception {
RSAKeyProvider provider = mock(RSAKeyProvider.class);
PrivateKey privateKey = readPrivateKeyFromFile(PRIVATE_KEY_FILE, "RSA");
PublicKey publicKey = readPublicKeyFromFile(PUBLIC_KEY_FILE, "RSA");
when(provider.getPrivateKey()).thenReturn((RSAPrivateKey) privateKey);
when(provider.getPublicKeyById(null)).thenReturn((RSAPublicKey) publicKey);
Algorithm algorithm = Algorithm.RSA256(provider);
String jwtContent = String.format("%s.%s", RS256Header, auth0IssPayload);
byte[] contentBytes = jwtContent.getBytes(StandardCharsets.UTF_8);
byte[] signatureBytes = algorithm.sign(contentBytes);
String jwtSignature = Base64.encodeBase64URLSafeString(signatureBytes);
String token = String.format("%s.%s", jwtContent, jwtSignature);
assertThat(signatureBytes, is(notNullValue()));
JWT jwt = JWT.require(algorithm).withIssuer("auth0").build();
DecodedJWT decoded = jwt.decode(token);
algorithm.verify(decoded, EncodeType.Base64);
}
示例10: testGoogleJwtCreatorNoneAlgorithmAllowed
import com.auth0.jwt.interfaces.DecodedJWT; //导入依赖的package包/类
@Test
public void testGoogleJwtCreatorNoneAlgorithmAllowed() throws Exception {
Algorithm algorithm = Algorithm.none();
String token = GoogleJwtCreator.build()
.withPicture(PICTURE)
.withEmail(EMAIL)
.withIssuer("issuer")
.withSubject("subject")
.withAudience("audience")
.withExp(exp)
.withIat(iat)
.withName(NAME)
.setIsNoneAlgorithmAllowed(true)
.sign(algorithm);
GoogleVerification verification = GoogleJWT.require(algorithm);
JWT verifier = verification.createVerifierForGoogle(PICTURE, EMAIL, asList("issuer"), asList("audience"),
NAME, 1, 1).build();
DecodedJWT jwt = verifier.decode(token);
Map<String, Claim> claims = jwt.getClaims();
verifyClaims(claims, exp);
}
示例11: testAccessJwtCreatorArrayClaim
import com.auth0.jwt.interfaces.DecodedJWT; //导入依赖的package包/类
@Test
public void testAccessJwtCreatorArrayClaim() throws Exception {
Algorithm algorithm = Algorithm.HMAC256("secret");
String token = AccessJwtCreator.build()
.withIssuer("issuer")
.withSubject("subject")
.withAudience("audience")
.withArrayClaim("arrayKey", "arrayValue1", "arrayValue2")
.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);
}
示例12: testExtendedJwtCreatorNonStandardClaimIntegerValue
import com.auth0.jwt.interfaces.DecodedJWT; //导入依赖的package包/类
@Test
public void testExtendedJwtCreatorNonStandardClaimIntegerValue() throws Exception {
Algorithm algorithm = Algorithm.HMAC256("secret");
String token = ExtendedJwtCreator.build()
.withNbf(nbf)
.withPicture(PICTURE)
.withEmail(EMAIL)
.withIssuer("issuer")
.withSubject("subject")
.withAudience("audience")
.withExp(exp)
.withIat(iat)
.withName(NAME)
.withNonStandardClaim("nonStandardClaim", 999)
.sign(algorithm);
GoogleVerification verification = ExtendedJWT.require(algorithm);
JWT verifier = verification.createVerifierForExtended(PICTURE, EMAIL, asList("issuer"), asList("audience"),
NAME, 1, 1, 1).build();
DecodedJWT jwt = verifier.decode(token);
}
示例13: testGoogleJwtCreatorInvalidAudience
import com.auth0.jwt.interfaces.DecodedJWT; //导入依赖的package包/类
@Test
public void testGoogleJwtCreatorInvalidAudience() 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 = GoogleJwtCreator.build()
.withPicture(PICTURE)
.withEmail(EMAIL)
.withIssuer("issuer")
.withSubject("subject")
.withAudience("invalid")
.withExp(exp)
.withIat(iat)
.withName(NAME)
.sign(algorithm);
GoogleVerification verification = GoogleJWT.require(algorithm);
JWT verifier = verification.createVerifierForGoogle(PICTURE, EMAIL, asList("issuer"), asList("audience"),
NAME, 1, 1).build();
DecodedJWT jwt = verifier.decode(token);
}
示例14: testFbJwtCreatorNoneAlgorithmNotSpecifiedButStillNotAllowed
import com.auth0.jwt.interfaces.DecodedJWT; //导入依赖的package包/类
@Test
public void testFbJwtCreatorNoneAlgorithmNotSpecifiedButStillNotAllowed() throws Exception {
thrown.expect(IllegalAccessException.class);
thrown.expectMessage("None algorithm isn't allowed");
Algorithm algorithm = Algorithm.none();
String token = FbJwtCreator.build()
.withExp(exp)
.withIat(iat)
.withUserId(USER_ID)
.withAppId(APP_ID)
.sign(algorithm);
Verification verification = FbJWT.require(algorithm);
JWT verifier = verification.createVerifierForFb(USER_ID, APP_ID).build();
DecodedJWT jwt = verifier.decode(token);
}
示例15: testFbJwtCreatorNoneAlgorithmAllowed
import com.auth0.jwt.interfaces.DecodedJWT; //导入依赖的package包/类
@Test
public void testFbJwtCreatorNoneAlgorithmAllowed() throws Exception {
Algorithm algorithm = Algorithm.none();
String token = FbJwtCreator.build()
.withExp(exp)
.withIat(iat)
.withUserId(USER_ID)
.withAppId(APP_ID)
.setIsNoneAlgorithmAllowed(true)
.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);
}