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

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

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

Verification.withIssuer介绍

暂无

代码示例

代码示例来源: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: 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 shouldRemoveClaimWhenPassingNull() throws Exception {
  Algorithm algorithm = mock(Algorithm.class);
  JWTVerifier verifier = JWTVerifier.init(algorithm)
      .withIssuer("iss")
      .withIssuer(null)
      .build();
  assertThat(verifier.claims, is(notNullValue()));
  assertThat(verifier.claims, not(hasKey("iss")));
}

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

@Test
public void shouldValidateIssuer() throws Exception {
  String token = "eyJhbGciOiJIUzI1NiIsImN0eSI6IkpXVCJ9.eyJpc3MiOiJhdXRoMCJ9.mZ0m_N1J4PgeqWmi903JuUoDRZDBPB7HwkS4nVyWH1M";
  DecodedJWT jwt = JWTVerifier.init(Algorithm.HMAC256("secret"))
      .withIssuer("auth0")
      .build()
      .verify(token);
  assertThat(jwt, is(notNullValue()));
}

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

@Test
public void shouldPassHMAC512Verification() throws Exception {
  String token = "eyJhbGciOiJIUzUxMiIsImN0eSI6IkpXVCJ9.eyJpc3MiOiJhdXRoMCJ9.VUo2Z9SWDV-XcOc_Hr6Lff3vl7L9e5Vb8ThXpmGDFjHxe3Dr1ZBmUChYF-xVA7cAdX1P_D4ZCUcsv3IefpVaJw";
  Algorithm algorithm = Algorithm.HMAC512("secret");
  JWTVerifier verifier = JWTVerifier.init(algorithm).withIssuer("auth0").build();
  concurrentVerify(verifier, token);
}

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

@Test
public void shouldPassHMAC256Verification() throws Exception {
  Algorithm algorithm = Algorithm.HMAC256("secret");
  JWTVerifier verifier = JWTVerifier.init(algorithm).withIssuer("auth0").build();
  String token = "eyJhbGciOiJIUzI1NiIsImN0eSI6IkpXVCJ9.eyJpc3MiOiJhdXRoMCJ9.mZ0m_N1J4PgeqWmi903JuUoDRZDBPB7HwkS4nVyWH1M";
  concurrentVerify(verifier, token);
}

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

@Test
public void shouldPassHMAC384Verification() throws Exception {
  String token = "eyJhbGciOiJIUzM4NCIsImN0eSI6IkpXVCJ9.eyJpc3MiOiJhdXRoMCJ9.uztpK_wUMYJhrRv8SV-1LU4aPnwl-EM1q-wJnqgyb5DHoDteP6lN_gE1xnZJH5vw";
  Algorithm algorithm = Algorithm.HMAC384("secret");
  JWTVerifier verifier = JWTVerifier.init(algorithm).withIssuer("auth0").build();
  concurrentVerify(verifier, token);
}

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

@Test
  public void shouldPassECDSA512VerificationWithJOSESignature() throws Exception {
    String token = "eyJhbGciOiJFUzUxMiJ9.eyJpc3MiOiJhdXRoMCJ9.AeCJPDIsSHhwRSGZCY6rspi8zekOw0K9qYMNridP1Fu9uhrA1QrG-EUxXlE06yvmh2R7Rz0aE7kxBwrnq8L8aOBCAYAsqhzPeUvyp8fXjjgs0Eto5I0mndE2QHlgcMSFASyjHbU8wD2Rq7ZNzGQ5b2MZfpv030WGUajT-aZYWFUJHVg2";
    ECKey key = (ECKey) readPublicKeyFromFile(PUBLIC_KEY_FILE_512, "EC");
    Algorithm algorithm = Algorithm.ECDSA512(key);
    JWTVerifier verifier = JWTVerifier.init(algorithm).withIssuer("auth0").build();

    concurrentVerify(verifier, token);
  }
}

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

@Test
public void shouldPassRSA512Verification() throws Exception {
  String token = "eyJhbGciOiJSUzUxMiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJhdXRoMCJ9.mvL5LoMyIrWYjk5umEXZTmbyIrkbbcVPUkvdGZbu0qFBxGOf0nXP5PZBvPcOu084lvpwVox5n3VaD4iqzW-PsJyvKFgi5TnwmsbKchAp7JexQEsQOnTSGcfRqeUUiBZqRQdYsho71oAB3T4FnalDdFEpM-fztcZY9XqKyayqZLreTeBjqJm4jfOWH7KfGBHgZExQhe96NLq1UA9eUyQwdOA1Z0SgXe4Ja5PxZ6Fm37KnVDtDlNnY4JAAGFo6y74aGNnp_BKgpaVJCGFu1f1S5xCQ1HSvs8ZSdVWs5NgawW3wRd0kRt_GJ_Y3mIwiF4qUyHWGtsSHu_qjVdCTtbFyow";
  Algorithm algorithm = Algorithm.RSA512((RSAKey) readPublicKeyFromFile(PUBLIC_KEY_FILE, "RSA"));
  JWTVerifier verifier = JWTVerifier.init(algorithm).withIssuer("auth0").build();
  concurrentVerify(verifier, token);
}

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

@Test
public void shouldPassECDSA256VerificationWithJOSESignature() throws Exception {
  String token = "eyJhbGciOiJFUzI1NiJ9.eyJpc3MiOiJhdXRoMCJ9.4iVk3-Y0v4RT4_9IaQlp-8dZ_4fsTzIylgrPTDLrEvTHBTyVS3tgPbr2_IZfLETtiKRqCg0aQ5sh9eIsTTwB1g";
  ECKey key = (ECKey) readPublicKeyFromFile(PUBLIC_KEY_FILE_256, "EC");
  Algorithm algorithm = Algorithm.ECDSA256(key);
  JWTVerifier verifier = JWTVerifier.init(algorithm).withIssuer("auth0").build();
  concurrentVerify(verifier, token);
}

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

@Test
public void shouldPassRSA384Verification() throws Exception {
  String token = "eyJhbGciOiJSUzM4NCIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJhdXRoMCJ9.TZlWjXObwGSQOiu2oMq8kiKz0_BR7bbBddNL6G8eZ_GoR82BXOZDqNrQr7lb_M-78XGBguWLWNIdYhzgxOUL9EoCJlrqVm9s9vo6G8T1sj1op-4TbjXZ61TwIvrJee9BvPLdKUJ9_fp1Js5kl6yXkst40Th8Auc5as4n49MLkipjpEhKDKaENKHpSubs1ripSz8SCQZSofeTM_EWVwSw7cpiM8Fy8jOPvWG8Xz4-e3ODFowvHVsDcONX_4FTMNbeRqDuHq2ZhCJnEfzcSJdrve_5VD5fM1LperBVslTrOxIgClOJ3RmM7-WnaizJrWP3D6Z9OLxPxLhM6-jx6tcxEw";
  Algorithm algorithm = Algorithm.RSA384((RSAKey) readPublicKeyFromFile(PUBLIC_KEY_FILE, "RSA"));
  JWTVerifier verifier = JWTVerifier.init(algorithm).withIssuer("auth0").build();
  concurrentVerify(verifier, token);
}

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

@Test
public void shouldPassRSA256Verification() throws Exception {
  String token = "eyJhbGciOiJSUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJhdXRoMCJ9.dxXF3MdsyW-AuvwJpaQtrZ33fAde9xWxpLIg9cO2tMLH2GSRNuLAe61KsJusZhqZB9Iy7DvflcmRz-9OZndm6cj_ThGeJH2LLc90K83UEvvRPo8l85RrQb8PcanxCgIs2RcZOLygERizB3pr5icGkzR7R2y6zgNCjKJ5_NJ6EiZsGN6_nc2PRK_DbyY-Wn0QDxIxKoA5YgQJ9qafe7IN980pXvQv2Z62c3XR8dYuaXBqhthBj-AbaFHEpZapN-V-TmuLNzR2MCB6Xr7BYMuCaqWf_XU8og4XNe8f_8w9Wv5vvgqMM1KhqVpG5VdMJv4o_L4NoCROHhtUQSLRh2M9cA";
  Algorithm algorithm = Algorithm.RSA256((RSAKey) readPublicKeyFromFile(PUBLIC_KEY_FILE, "RSA"));
  JWTVerifier verifier = JWTVerifier.init(algorithm).withIssuer("auth0").build();
  concurrentVerify(verifier, token);
}

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

@Test
public void shouldPassECDSA384VerificationWithJOSESignature() throws Exception {
  String token = "eyJhbGciOiJFUzM4NCJ9.eyJpc3MiOiJhdXRoMCJ9.50UU5VKNdF1wfykY8jQBKpvuHZoe6IZBJm5NvoB8bR-hnRg6ti-CHbmvoRtlLfnHfwITa_8cJMy6TenMC2g63GQHytc8rYoXqbwtS4R0Ko_AXbLFUmfxnGnMC6v4MS_z";
  ECKey key = (ECKey) readPublicKeyFromFile(PUBLIC_KEY_FILE_384, "EC");
  Algorithm algorithm = Algorithm.ECDSA384(key);
  JWTVerifier verifier = JWTVerifier.init(algorithm).withIssuer("auth0").build();
  concurrentVerify(verifier, token);
}

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

@Test
public void shouldThrowOnInvalidIssuer() throws Exception {
  exception.expect(InvalidClaimException.class);
  exception.expectMessage("The Claim 'iss' value doesn't match the required one.");
  String token = "eyJhbGciOiJIUzI1NiIsImN0eSI6IkpXVCJ9.eyJpc3MiOiJhdXRoMCJ9.mZ0m_N1J4PgeqWmi903JuUoDRZDBPB7HwkS4nVyWH1M";
  JWTVerifier.init(Algorithm.HMAC256("secret"))
      .withIssuer("invalid")
      .build()
      .verify(token);
}

代码示例来源:origin: kamax-matrix/mxhsd

public DeviceManager(GlobalStateHolder global, String jwtSecret) {
  if (StringUtils.isBlank(jwtSecret)) {
    throw new IllegalArgumentException("JWT secret must be set to a non-white/empty value");
  }
  this.global = Objects.requireNonNull(global);
  try {
    jwtAlgo = Algorithm.HMAC256(jwtSecret);
    jwtVerifier = JWT.require(jwtAlgo)
        .withIssuer(global.getDomain())
        .build();
  } catch (UnsupportedEncodingException e) {
    throw new RuntimeException("Failed to setup JWT algorithm", e);
  }
  devByToken = new HashMap<>();
  devById = new HashMap<>();
}

代码示例来源:origin: com.charlyghislain.authenticator/authenticator-ejb

@Produces
@Dependent
public JWTVerifier produceJwtVerifier() {
  Algorithm algorithm = Algorithm.RSA256(defaultRsaKeyProvider);
  return JWT.require(algorithm)
      .withIssuer(tokenIssuer)
      .acceptLeeway(tokenValidationLeewaySeconds)
      .build();
}

代码示例来源:origin: fbacchella/LogHub

private JWTHandler(Builder builder) throws IllegalArgumentException {
  this.validity = builder.validity;
  this.issuer = builder.issuer;
  switch(builder.alg) {
  case "HMAC256":
    alg = Algorithm.HMAC256(builder.secret);
    break;
  default:
    throw new IllegalArgumentException("Unhandled signing algorithm: " + builder.alg);
  }
  this.verifier = JWT.require(alg)
          .withIssuer(builder.issuer)
          .build();
}

代码示例来源:origin: 794147572/cloud

public DecodedJWT verifyJWT(String token) {
  DecodedJWT jwt = null;
  try {
    JWTVerifier verifier = JWT.require(Algorithm.HMAC256(SECRET)).withIssuer(ISSUER).build();
    jwt = verifier.verify(token);
  } catch (UnsupportedEncodingException e) {
    logger.error("verify jwt error");
  }
  return jwt;
}

代码示例来源:origin: com.linecorp.armeria/armeria-saml

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: 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;
  }
}

相关文章