com.auth0.jwt.interfaces.Verification.withAudience()方法的使用及代码示例

x33g5p2x  于2022-02-01 转载在 其他  
字(3.8k)|赞(0)|评价(0)|浏览(126)

本文整理了Java中com.auth0.jwt.interfaces.Verification.withAudience()方法的一些代码示例,展示了Verification.withAudience()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Verification.withAudience()方法的具体详情如下:
包路径:com.auth0.jwt.interfaces.Verification
类名称:Verification
方法名:withAudience

Verification.withAudience介绍

暂无

代码示例

代码示例来源: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: auth0/java-jwt

@Test
public void shouldValidateAudience() throws Exception {
  String token = "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJhdWQiOiJNYXJrIn0.xWB6czYI0XObbVhLAxe55TwChWZg7zO08RxONWU2iY4";
  DecodedJWT jwt = JWTVerifier.init(Algorithm.HMAC256("secret"))
      .withAudience("Mark")
      .build()
      .verify(token);
  assertThat(jwt, is(notNullValue()));
  String tokenArr = "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJhdWQiOlsiTWFyayIsIkRhdmlkIl19.6WfbIt8m61f9WlCYIQn5CThvw4UNyC66qrPaoinfssw";
  DecodedJWT jwtArr = JWTVerifier.init(Algorithm.HMAC256("secret"))
      .withAudience("Mark", "David")
      .build()
      .verify(tokenArr);
  assertThat(jwtArr, is(notNullValue()));
}

代码示例来源:origin: auth0/java-jwt

@Test
public void shouldThrowOnInvalidAudience() throws Exception {
  exception.expect(InvalidClaimException.class);
  exception.expectMessage("The Claim 'aud' value doesn't contain the required audience.");
  String token = "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiIxMjM0NTY3ODkwIn0.Rq8IxqeX7eA6GgYxlcHdPFVRNFFZc5rEI3MQTZZbK3I";
  JWTVerifier.init(Algorithm.HMAC256("secret"))
      .withAudience("nope")
      .build()
      .verify(token);
}

代码示例来源:origin: GoogleCloudPlatform/java-docs-samples

public DecodedGoogleJWTWrapper verifyWithAudience(String audience, String token) {
  JWTVerifier verifier = JWT.require(algorithm)
    .withAudience(audience)
    .build();
  return new DecodedGoogleJWTWrapper(verifier.verify(token));
 }
}

代码示例来源:origin: SoftInstigate/restheart

v.withAudience(audience);

代码示例来源: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: org.mycore/mycore-restapi

public static void validate(String token) throws JWTVerificationException {
    JWT.require(MCRJWTUtil.getJWTAlgorithm())
      .withAudience(AUDIENCE)
      .acceptLeeway(0)
      .build().verify(token);
  }
}

代码示例来源: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;
  }
}

相关文章