本文整理了Java中com.auth0.jwt.interfaces.Verification
类的一些代码示例,展示了Verification
类的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Verification
类的具体详情如下:
包路径:com.auth0.jwt.interfaces.Verification
类名称:Verification
暂无
代码示例来源:origin: google/data-transfer-project
/** Create an instance of the token verifier. */
private static JWTVerifier createVerifier(String secret, String issuer) {
return JWT.require(createAlgorithm(secret)).withIssuer(issuer).build();
}
代码示例来源:origin: auth0/java-jwt
@Test
public void shouldValidateCustomClaimOfTypeDate() throws Exception {
String token = "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJuYW1lIjoxNDc4ODkxNTIxfQ.mhioumeok8fghQEhTKF3QtQAksSvZ_9wIhJmgZLhJ6c";
Date date = new Date(1478891521000L);
DecodedJWT jwt = JWTVerifier.init(Algorithm.HMAC256("secret"))
.withClaim("name", date)
.build()
.verify(token);
assertThat(jwt, is(notNullValue()));
}
代码示例来源:origin: line/armeria
JwtBasedSamlRequestIdManager(String issuer, Algorithm algorithm,
int validSeconds, int leewaySeconds) {
this.issuer = requireNonNull(issuer, "issuer");
this.algorithm = requireNonNull(algorithm, "algorithm");
this.validSeconds = validSeconds;
this.leewaySeconds = leewaySeconds;
checkArgument(validSeconds > 0,
"invalid valid duration: " + validSeconds + " (expected: > 0)");
checkArgument(leewaySeconds >= 0,
"invalid leeway duration:" + leewaySeconds + " (expected: >= 0)");
un1 = getUniquifierPrefix();
verifier = JWT.require(algorithm)
.withIssuer(issuer)
.acceptLeeway(leewaySeconds)
.build();
}
代码示例来源:origin: auth0/java-jwt
@Test
public void shouldAcceptHMAC256Algorithm() throws Exception {
String token = "eyJhbGciOiJIUzI1NiIsImN0eSI6IkpXVCJ9.eyJpc3MiOiJhdXRoMCJ9.mZ0m_N1J4PgeqWmi903JuUoDRZDBPB7HwkS4nVyWH1M";
DecodedJWT jwt = JWT.require(Algorithm.HMAC256("secret"))
.build()
.verify(token);
assertThat(jwt, is(notNullValue()));
}
代码示例来源:origin: auth0/java-jwt
@Test
public void shouldAcceptPartialAudience() throws Exception {
//Token 'aud' = ["Mark", "David", "John"]
String tokenArr = "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJhdWQiOlsiTWFyayIsIkRhdmlkIiwiSm9obiJdfQ.DX5xXiCaYvr54x_iL0LZsJhK7O6HhAdHeDYkgDeb0Rw";
DecodedJWT jwtArr = JWTVerifier.init(Algorithm.HMAC256("secret"))
.withAudience("John")
.build()
.verify(tokenArr);
assertThat(jwtArr, is(notNullValue()));
}
代码示例来源:origin: com.centurylink.mdw/mdw-common
private void verify() throws IOException {
Props props = new Props(this);
String mdwAppId = appId;
if (mdwAppId == null)
mdwAppId = props.get(Props.APP_ID);
if (mdwAppId == null)
throw new IOException("--app-id param or mdw.app.id prop required");
if (userToken == null)
throw new IOException("--user-token required for verification");
String mdwAppToken = appToken;
if (mdwAppToken == null)
mdwAppToken = System.getenv("MDW_APP_TOKEN");
if (mdwAppToken == null)
throw new IOException("--app-token param or MDW_APP_TOKEN environment variable required");
JWTVerifier verifier = JWT.require(Algorithm.HMAC256(mdwAppToken))
.withIssuer("mdwAuth")
.withAudience(mdwAppId)
.build();
DecodedJWT jwt = verifier.verify(userToken);
String subject = jwt.getSubject();
System.out.println("Token verified for app " + mdwAppId + " and user " + subject);
}
代码示例来源:origin: auth0/java-jwt
@SuppressWarnings("RedundantCast")
@Test
public void shouldAddCustomLeewayToDateClaims() throws Exception {
Algorithm algorithm = mock(Algorithm.class);
JWTVerifier verifier = JWTVerifier.init(algorithm)
.acceptLeeway(1234L)
.build();
assertThat(verifier.claims, is(notNullValue()));
assertThat(verifier.claims, hasEntry("iat", (Object) 1234L));
assertThat(verifier.claims, hasEntry("exp", (Object) 1234L));
assertThat(verifier.claims, hasEntry("nbf", (Object) 1234L));
}
代码示例来源:origin: line/line-login-starter
public boolean verifyIdToken(String id_token, String nonce) {
try {
JWT.require(
Algorithm.HMAC256(channelSecret))
.withIssuer("https://access.line.me")
.withAudience(channelId)
.withClaim("nonce", nonce)
.build()
.verify(id_token);
return true;
} catch (UnsupportedEncodingException e) {
//UTF-8 encoding not supported
return false;
} catch (JWTVerificationException e) {
//Invalid signature/claims
return false;
}
}
代码示例来源:origin: auth0/java-jwt
@SuppressWarnings("RedundantCast")
@Test
public void shouldOverrideDefaultNotBeforeLeeway() throws Exception {
Algorithm algorithm = mock(Algorithm.class);
JWTVerifier verifier = JWTVerifier.init(algorithm)
.acceptLeeway(1234L)
.acceptNotBefore(9999L)
.build();
assertThat(verifier.claims, is(notNullValue()));
assertThat(verifier.claims, hasEntry("iat", (Object) 1234L));
assertThat(verifier.claims, hasEntry("exp", (Object) 1234L));
assertThat(verifier.claims, hasEntry("nbf", (Object) 9999L));
}
代码示例来源:origin: auth0/java-jwt
@SuppressWarnings("RedundantCast")
@Test
public void shouldOverrideDefaultExpiresAtLeeway() throws Exception {
Algorithm algorithm = mock(Algorithm.class);
JWTVerifier verifier = JWTVerifier.init(algorithm)
.acceptLeeway(1234L)
.acceptExpiresAt(9999L)
.build();
assertThat(verifier.claims, is(notNullValue()));
assertThat(verifier.claims, hasEntry("iat", (Object) 1234L));
assertThat(verifier.claims, hasEntry("exp", (Object) 9999L));
assertThat(verifier.claims, hasEntry("nbf", (Object) 1234L));
}
代码示例来源:origin: auth0/java-jwt
@SuppressWarnings("RedundantCast")
@Test
public void shouldOverrideDefaultIssuedAtLeeway() throws Exception {
Algorithm algorithm = mock(Algorithm.class);
JWTVerifier verifier = JWTVerifier.init(algorithm)
.acceptLeeway(1234L)
.acceptIssuedAt(9999L)
.build();
assertThat(verifier.claims, is(notNullValue()));
assertThat(verifier.claims, hasEntry("iat", (Object) 9999L));
assertThat(verifier.claims, hasEntry("exp", (Object) 1234L));
assertThat(verifier.claims, hasEntry("nbf", (Object) 1234L));
}
代码示例来源:origin: auth0/java-jwt
@Test
public void shouldValidateSubject() throws Exception {
String token = "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiIxMjM0NTY3ODkwIn0.Rq8IxqeX7eA6GgYxlcHdPFVRNFFZc5rEI3MQTZZbK3I";
DecodedJWT jwt = JWTVerifier.init(Algorithm.HMAC256("secret"))
.withSubject("1234567890")
.build()
.verify(token);
assertThat(jwt, is(notNullValue()));
}
代码示例来源:origin: com.github.edgar615/spring-boot-util-jwt
try {
verification = JWT.require(Algorithm.HMAC256(jwtProperty.getSecret()));
JWTVerifier verifier = verification.build(); //Reusable verifier instance
if (jwtProperty.getIssuer() != null) {
verification.withIssuer(jwtProperty.getIssuer());
verification.withSubject(jwtProperty.getSubject());
verification.withIssuer(jwtProperty.getIssuer());
代码示例来源:origin: auth0/java-jwt
@Test
public void shouldValidateJWTId() throws Exception {
String token = "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJqdGkiOiJqd3RfaWRfMTIzIn0.0kegfXUvwOYioP8PDaLMY1IlV8HOAzSVz3EGL7-jWF4";
DecodedJWT jwt = JWTVerifier.init(Algorithm.HMAC256("secret"))
.withJWTId("jwt_id_123")
.build()
.verify(token);
assertThat(jwt, is(notNullValue()));
}
代码示例来源:origin: auth0/java-jwt
@Test
public void shouldValidateCustomArrayClaimOfTypeString() throws Exception {
String token = "eyJhbGciOiJIUzI1NiJ9.eyJuYW1lIjpbInRleHQiLCIxMjMiLCJ0cnVlIl19.lxM8EcmK1uSZRAPd0HUhXGZJdauRmZmLjoeqz4J9yAA";
DecodedJWT jwt = JWTVerifier.init(Algorithm.HMAC256("secret"))
.withArrayClaim("name", "text", "123", "true")
.build()
.verify(token);
assertThat(jwt, is(notNullValue()));
}
代码示例来源:origin: auth0/java-jwt
@Test
public void shouldOverrideAcceptIssuedAtWhenIgnoreIssuedAtFlagPassedAndSkipTheVerification() throws Exception {
Clock clock = mock(Clock.class);
when(clock.getToday()).thenReturn(new Date(DATE_TOKEN_MS_VALUE - 1000));
String token = "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpYXQiOjE0Nzc1OTJ9.0WJky9eLN7kuxLyZlmbcXRL3Wy8hLoNCEk5CCl2M4lo";
JWTVerifier.BaseVerification verification = (JWTVerifier.BaseVerification) JWTVerifier.init(Algorithm.HMAC256("secret"));
DecodedJWT jwt = verification.acceptIssuedAt(20).ignoreIssuedAt()
.build()
.verify(token);
assertThat(jwt, is(notNullValue()));
}
代码示例来源:origin: org.mycore/mycore-restapi
public static void validate(String token) throws JWTVerificationException {
JWT.require(MCRJWTUtil.getJWTAlgorithm())
.withAudience(AUDIENCE)
.acceptLeeway(0)
.build().verify(token);
}
}
代码示例来源:origin: auth0/java-jwt
@Test
public void shouldThrowOnNullCustomClaimName() throws Exception {
exception.expect(IllegalArgumentException.class);
exception.expectMessage("The Custom Claim's name can't be null.");
JWTVerifier.init(Algorithm.HMAC256("secret"))
.withClaim(null, "value");
}
代码示例来源:origin: auth0/java-jwt
@Test
public void shouldThrowOnNegativeCustomLeeway() throws Exception {
exception.expect(IllegalArgumentException.class);
exception.expectMessage("Leeway value can't be negative.");
Algorithm algorithm = mock(Algorithm.class);
JWTVerifier.init(algorithm)
.acceptLeeway(-1);
}
代码示例来源:origin: auth0/java-jwt
@Test
public void shouldAcceptHMAC384Algorithm() throws Exception {
String token = "eyJhbGciOiJIUzM4NCIsImN0eSI6IkpXVCJ9.eyJpc3MiOiJhdXRoMCJ9.uztpK_wUMYJhrRv8SV-1LU4aPnwl-EM1q-wJnqgyb5DHoDteP6lN_gE1xnZJH5vw";
DecodedJWT jwt = JWT.require(Algorithm.HMAC384("secret"))
.build()
.verify(token);
assertThat(jwt, is(notNullValue()));
}
内容来源于网络,如有侵权,请联系作者删除!