com.auth0.jwt.JWT类的使用及代码示例

x33g5p2x  于2022-01-21 转载在 其他  
字(8.1k)|赞(0)|评价(0)|浏览(591)

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

JWT介绍

暂无

代码示例

代码示例来源: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: knowm/XChange

public QuoineSignatureDigest(
  String tokenID, String userSecret, SynchronizedValueFactory<Long> nonceFactory) {
 this.tokenID = tokenID;
 this.userSecret = userSecret.getBytes();
 this.nonceFactory = nonceFactory;
 this.builder = JWT.create();
}

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

@Test
public void shouldGetHeader() throws Exception {
  DecodedJWT jwt = JWT.decode("eyJhbGciOiJIUzI1NiJ9.e30.XmNK3GpH3Ys_7wsYBfq4C3M6goz71I7dTgUkuIa5lyQ");
  assertThat(jwt, is(notNullValue()));
  assertThat(jwt.getHeader(), is("eyJhbGciOiJIUzI1NiJ9"));
}

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

@Test
public void shouldVerifyDecodedToken() throws Exception {
  String token = "eyJhbGciOiJSUzUxMiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJhdXRoMCJ9.mvL5LoMyIrWYjk5umEXZTmbyIrkbbcVPUkvdGZbu0qFBxGOf0nXP5PZBvPcOu084lvpwVox5n3VaD4iqzW-PsJyvKFgi5TnwmsbKchAp7JexQEsQOnTSGcfRqeUUiBZqRQdYsho71oAB3T4FnalDdFEpM-fztcZY9XqKyayqZLreTeBjqJm4jfOWH7KfGBHgZExQhe96NLq1UA9eUyQwdOA1Z0SgXe4Ja5PxZ6Fm37KnVDtDlNnY4JAAGFo6y74aGNnp_BKgpaVJCGFu1f1S5xCQ1HSvs8ZSdVWs5NgawW3wRd0kRt_GJ_Y3mIwiF4qUyHWGtsSHu_qjVdCTtbFyow";
  DecodedJWT decodedJWT = JWT.decode(token);
  RSAKey key = (RSAKey) PemUtils.readPublicKeyFromFile(PUBLIC_KEY_FILE_RSA, "RSA");
  DecodedJWT jwt = JWT.require(Algorithm.RSA512(key))
    .build()
    .verify(decodedJWT);
  assertThat(jwt, is(notNullValue()));
}

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

@Test
public void shouldGetPayload() throws Exception {
  DecodedJWT jwt = JWT.decode("eyJhbGciOiJIUzI1NiJ9.e30.XmNK3GpH3Ys_7wsYBfq4C3M6goz71I7dTgUkuIa5lyQ");
  assertThat(jwt, is(notNullValue()));
  assertThat(jwt.getPayload(), is("e30"));
}

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

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

@Test
public void shouldGetIssuer() throws Exception {
  DecodedJWT jwt = JWT.decode("eyJhbGciOiJIUzI1NiJ9.eyJpc3MiOiJKb2huIERvZSJ9.SgXosfRR_IwCgHq5lF3tlM-JHtpucWCRSaVuoHTbWbQ");
  assertThat(jwt, is(notNullValue()));
  assertThat(jwt.getIssuer(), is("John Doe"));
}

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

@Test
public void shouldAcceptHMAC512Algorithm() throws Exception {
  String token = "eyJhbGciOiJIUzUxMiIsImN0eSI6IkpXVCJ9.eyJpc3MiOiJhdXRoMCJ9.VUo2Z9SWDV-XcOc_Hr6Lff3vl7L9e5Vb8ThXpmGDFjHxe3Dr1ZBmUChYF-xVA7cAdX1P_D4ZCUcsv3IefpVaJw";
  DecodedJWT jwt = JWT.require(Algorithm.HMAC512("secret"))
      .build()
      .verify(token);
  assertThat(jwt, is(notNullValue()));
}

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

@Test
public void shouldGetSubject() throws Exception {
  DecodedJWT jwt = JWT.decode("eyJhbGciOiJIUzI1NiJ9.eyJzdWIiOiJUb2szbnMifQ.RudAxkslimoOY3BLl2Ghny3BrUKu9I1ZrXzCZGDJtNs");
  assertThat(jwt, is(notNullValue()));
  assertThat(jwt.getSubject(), is("Tok3ns"));
}

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

@Test
public void shouldGetAlgorithm() throws Exception {
  String token = "eyJhbGciOiJIUzI1NiJ9.e30.XmNK3GpH3Ys_7wsYBfq4C3M6goz71I7dTgUkuIa5lyQ";
  DecodedJWT jwt = JWT.require(Algorithm.HMAC256("secret"))
      .build()
      .verify(token);
  assertThat(jwt, is(notNullValue()));
  assertThat(jwt.getAlgorithm(), is("HS256"));
}

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

@Test
public void shouldGetAlgorithm() throws Exception {
  DecodedJWT jwt = JWT.decode("eyJhbGciOiJIUzI1NiJ9.e30.XmNK3GpH3Ys_7wsYBfq4C3M6goz71I7dTgUkuIa5lyQ");
  assertThat(jwt, is(notNullValue()));
  assertThat(jwt.getAlgorithm(), is("HS256"));
}

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

@Test
public void shouldGetKeyId() throws Exception {
  String token = "eyJhbGciOiJIUzI1NiIsImtpZCI6ImtleSJ9.e30.von1Vt9tq9cn5ZYdX1f4cf2EE7fUvb5BCBlKOTm9YWs";
  DecodedJWT jwt = JWT.require(Algorithm.HMAC256("secret"))
      .build()
      .verify(token);
  assertThat(jwt, is(notNullValue()));
  assertThat(jwt.getKeyId(), is("key"));
}

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

@Test
public void shouldGetValidClaim() throws Exception {
  DecodedJWT jwt = JWT.decode("eyJhbGciOiJIUzI1NiJ9.eyJvYmplY3QiOnsibmFtZSI6ImpvaG4ifX0.lrU1gZlOdlmTTeZwq0VI-pZx2iV46UWYd5-lCjy6-c4");
  assertThat(jwt, is(notNullValue()));
  assertThat(jwt.getClaim("object"), is(notNullValue()));
  assertThat(jwt.getClaim("object"), is(instanceOf(Claim.class)));
}

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

@Test
public void shouldGetSubject() throws Exception {
  String token = "eyJhbGciOiJIUzI1NiJ9.eyJzdWIiOiJUb2szbnMifQ.RudAxkslimoOY3BLl2Ghny3BrUKu9I1ZrXzCZGDJtNs";
  DecodedJWT jwt = JWT.require(Algorithm.HMAC256("secret"))
      .build()
      .verify(token);
  assertThat(jwt, is(notNullValue()));
  assertThat(jwt.getSubject(), is("Tok3ns"));
}

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

@Test
public void shouldGetStringToken() throws Exception {
  DecodedJWT jwt = JWT.decode("eyJhbGciOiJIUzI1NiJ9.e30.XmNK3GpH3Ys_7wsYBfq4C3M6goz71I7dTgUkuIa5lyQ");
  assertThat(jwt, is(notNullValue()));
  assertThat(jwt.getToken(), is(notNullValue()));
  assertThat(jwt.getToken(), is("eyJhbGciOiJIUzI1NiJ9.e30.XmNK3GpH3Ys_7wsYBfq4C3M6goz71I7dTgUkuIa5lyQ"));
}

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

@Test
public void shouldGetSignature() throws Exception {
  String token = "eyJhbGciOiJIUzI1NiJ9.e30.XmNK3GpH3Ys_7wsYBfq4C3M6goz71I7dTgUkuIa5lyQ";
  DecodedJWT jwt = JWT.require(Algorithm.HMAC256("secret"))
      .build()
      .verify(token);
  assertThat(jwt, is(notNullValue()));
  assertThat(jwt.getSignature(), is("XmNK3GpH3Ys_7wsYBfq4C3M6goz71I7dTgUkuIa5lyQ"));
}

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

@Test
public void shouldGetExpirationTime() throws Exception {
  DecodedJWT jwt = JWT.decode("eyJhbGciOiJIUzI1NiJ9.eyJleHAiOjE0NzY3MjcwODZ9.L9dcPHEDQew2u9MkDCORFkfDGcSOsgoPqNY-LUMLEHg");
  assertThat(jwt, is(notNullValue()));
  assertThat(jwt.getExpiresAt(), is(instanceOf(Date.class)));
  long ms = 1476727086L * 1000;
  Date expectedDate = new Date(ms);
  assertThat(jwt.getExpiresAt(), is(notNullValue()));
  assertThat(jwt.getExpiresAt(), is(equalTo(expectedDate)));
}

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

@Test
public void shouldAcceptRSA256Algorithm() throws Exception {
  String token = "eyJhbGciOiJSUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJhdXRoMCJ9.dxXF3MdsyW-AuvwJpaQtrZ33fAde9xWxpLIg9cO2tMLH2GSRNuLAe61KsJusZhqZB9Iy7DvflcmRz-9OZndm6cj_ThGeJH2LLc90K83UEvvRPo8l85RrQb8PcanxCgIs2RcZOLygERizB3pr5icGkzR7R2y6zgNCjKJ5_NJ6EiZsGN6_nc2PRK_DbyY-Wn0QDxIxKoA5YgQJ9qafe7IN980pXvQv2Z62c3XR8dYuaXBqhthBj-AbaFHEpZapN-V-TmuLNzR2MCB6Xr7BYMuCaqWf_XU8og4XNe8f_8w9Wv5vvgqMM1KhqVpG5VdMJv4o_L4NoCROHhtUQSLRh2M9cA";
  RSAKey key = (RSAKey) PemUtils.readPublicKeyFromFile(PUBLIC_KEY_FILE_RSA, "RSA");
  DecodedJWT jwt = JWT.require(Algorithm.RSA256(key))
      .build()
      .verify(token);
  assertThat(jwt, is(notNullValue()));
}

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

@Test
public void shouldDecodeAStringToken() throws Exception {
  String token = "eyJhbGciOiJIUzI1NiIsImN0eSI6IkpXVCJ9.eyJpc3MiOiJhdXRoMCJ9.mZ0m_N1J4PgeqWmi903JuUoDRZDBPB7HwkS4nVyWH1M";
  DecodedJWT jwt = JWT.decode(token);
  assertThat(jwt, is(notNullValue()));
}

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

@Test
public void shouldAcceptRSA384Algorithm() throws Exception {
  String token = "eyJhbGciOiJSUzM4NCIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJhdXRoMCJ9.TZlWjXObwGSQOiu2oMq8kiKz0_BR7bbBddNL6G8eZ_GoR82BXOZDqNrQr7lb_M-78XGBguWLWNIdYhzgxOUL9EoCJlrqVm9s9vo6G8T1sj1op-4TbjXZ61TwIvrJee9BvPLdKUJ9_fp1Js5kl6yXkst40Th8Auc5as4n49MLkipjpEhKDKaENKHpSubs1ripSz8SCQZSofeTM_EWVwSw7cpiM8Fy8jOPvWG8Xz4-e3ODFowvHVsDcONX_4FTMNbeRqDuHq2ZhCJnEfzcSJdrve_5VD5fM1LperBVslTrOxIgClOJ3RmM7-WnaizJrWP3D6Z9OLxPxLhM6-jx6tcxEw";
  RSAKey key = (RSAKey) PemUtils.readPublicKeyFromFile(PUBLIC_KEY_FILE_RSA, "RSA");
  DecodedJWT jwt = JWT.require(Algorithm.RSA384(key))
      .build()
      .verify(token);
  assertThat(jwt, is(notNullValue()));
}

相关文章