当前位置: 首页>>代码示例>>Java>>正文


Java FirebaseToken类代码示例

本文整理汇总了Java中com.google.firebase.auth.FirebaseToken的典型用法代码示例。如果您正苦于以下问题:Java FirebaseToken类的具体用法?Java FirebaseToken怎么用?Java FirebaseToken使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


FirebaseToken类属于com.google.firebase.auth包,在下文中一共展示了FirebaseToken类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: setCustomUserClaims

import com.google.firebase.auth.FirebaseToken; //导入依赖的package包/类
public static void setCustomUserClaims(
    String uid) throws InterruptedException, ExecutionException {
  // [START set_custom_user_claims]
  // Set admin privilege on the user corresponding to uid.
  Map<String, Object> claims = new HashMap<>();
  claims.put("admin", true);
  FirebaseAuth.getInstance().setCustomUserClaimsAsync(uid, claims).get();
  // The new custom claims will propagate to the user's ID token the
  // next time a new one is issued.
  // [END set_custom_user_claims]

  String idToken = "id_token";
  // [START verify_custom_claims]
  // Verify the ID token first.
  FirebaseToken decoded = FirebaseAuth.getInstance().verifyIdTokenAsync(idToken).get();
  if (Boolean.TRUE.equals(decoded.getClaims().get("admin"))) {
    // Allow access to requested admin resource.
  }
  // [END verify_custom_claims]

  // [START read_custom_user_claims]
  // Lookup the user associated with the specified uid.
  UserRecord user = FirebaseAuth.getInstance().getUserAsync(uid).get();
  System.out.println(user.getCustomClaims().get("admin"));
  // [END read_custom_user_claims]
}
 
开发者ID:firebase,项目名称:quickstart-java,代码行数:27,代码来源:AuthSnippets.java

示例2: verifyToken

import com.google.firebase.auth.FirebaseToken; //导入依赖的package包/类
@Test
public void verifyToken() throws Exception {
  FirebaseToken token =
      TestOnlyImplFirebaseAuthTrampolines.parseToken(
          FACTORY, createToken(createHeader(), createPayload()));

  IdToken.Payload payload = (IdToken.Payload) token.getClaims();
  assertTrue(payload.getAudienceAsList().contains(PROJECT_ID));
  assertEquals(ISSUER, payload.getIssuer());

  verifier.verifyTokenAndSignature(TestOnlyImplFirebaseAuthTrampolines.getToken(token));
}
 
开发者ID:firebase,项目名称:firebase-admin-java,代码行数:13,代码来源:FirebaseTokenVerifierTest.java

示例3: verifyTokenFailure_MissingKeyId

import com.google.firebase.auth.FirebaseToken; //导入依赖的package包/类
@Test
public void verifyTokenFailure_MissingKeyId() throws Exception {
  Header header = createHeader();
  header.setKeyId(null);
  FirebaseToken token =
      TestOnlyImplFirebaseAuthTrampolines.parseToken(
          FACTORY, createToken(header, createPayload()));
  thrown.expectMessage("Firebase ID token has no \"kid\" claim.");
  verifier.verifyTokenAndSignature(TestOnlyImplFirebaseAuthTrampolines.getToken(token));
}
 
开发者ID:firebase,项目名称:firebase-admin-java,代码行数:11,代码来源:FirebaseTokenVerifierTest.java

示例4: verifyTokenFailure_MissingKeyId_CustomToken

import com.google.firebase.auth.FirebaseToken; //导入依赖的package包/类
@Test
public void verifyTokenFailure_MissingKeyId_CustomToken() throws Exception {
  Header header = createHeader();
  header.setKeyId(null);
  Payload payload = createPayload();
  payload.setAudience(
      "https://identitytoolkit.googleapis.com/google.identity.identitytoolkit"
          + ".v1.IdentityToolkit");
  FirebaseToken token =
      TestOnlyImplFirebaseAuthTrampolines.parseToken(FACTORY, createToken(header, payload));
  thrown.expectMessage("verifyIdToken() expects an ID token, but was given a custom token.");
  verifier.verifyTokenAndSignature(TestOnlyImplFirebaseAuthTrampolines.getToken(token));
}
 
开发者ID:firebase,项目名称:firebase-admin-java,代码行数:14,代码来源:FirebaseTokenVerifierTest.java

示例5: verifyTokenFailure_IncorrectAlgorithm

import com.google.firebase.auth.FirebaseToken; //导入依赖的package包/类
@Test
public void verifyTokenFailure_IncorrectAlgorithm() throws Exception {
  Header header = createHeader();
  header.setAlgorithm("HS256");
  FirebaseToken token =
      TestOnlyImplFirebaseAuthTrampolines.parseToken(
          FACTORY, createToken(header, createPayload()));
  thrown.expectMessage("Firebase ID token has incorrect algorithm.");
  verifier.verifyTokenAndSignature(TestOnlyImplFirebaseAuthTrampolines.getToken(token));
}
 
开发者ID:firebase,项目名称:firebase-admin-java,代码行数:11,代码来源:FirebaseTokenVerifierTest.java

示例6: verifyTokenFailure_IncorrectAudience

import com.google.firebase.auth.FirebaseToken; //导入依赖的package包/类
@Test
public void verifyTokenFailure_IncorrectAudience() throws Exception {
  Payload payload = createPayload();
  payload.setAudience(
      "https://identitytoolkit.googleapis.com/google.identity.identitytoolkit.v1."
          + "IdentityToolkit");
  FirebaseToken token =
      TestOnlyImplFirebaseAuthTrampolines.parseToken(
          FACTORY, createToken(createHeader(), payload));
  thrown.expectMessage("Firebase ID token has incorrect \"aud\" (audience) claim.");
  verifier.verifyTokenAndSignature(TestOnlyImplFirebaseAuthTrampolines.getToken(token));
}
 
开发者ID:firebase,项目名称:firebase-admin-java,代码行数:13,代码来源:FirebaseTokenVerifierTest.java

示例7: verifyTokenFailure_IncorrectIssuer

import com.google.firebase.auth.FirebaseToken; //导入依赖的package包/类
@Test
public void verifyTokenFailure_IncorrectIssuer() throws Exception {
  Payload payload = createPayload();
  payload.setIssuer("https://foobar.google.com/" + PROJECT_ID);
  FirebaseToken token =
      TestOnlyImplFirebaseAuthTrampolines.parseToken(
          FACTORY, createToken(createHeader(), payload));
  thrown.expectMessage("Firebase ID token has incorrect \"iss\" (issuer) claim.");
  verifier.verifyTokenAndSignature(TestOnlyImplFirebaseAuthTrampolines.getToken(token));
}
 
开发者ID:firebase,项目名称:firebase-admin-java,代码行数:11,代码来源:FirebaseTokenVerifierTest.java

示例8: verifyTokenFailure_MissingSubject

import com.google.firebase.auth.FirebaseToken; //导入依赖的package包/类
@Test
public void verifyTokenFailure_MissingSubject() throws Exception {
  Payload payload = createPayload();
  payload.setSubject(null);
  FirebaseToken token =
      TestOnlyImplFirebaseAuthTrampolines.parseToken(
          FACTORY, createToken(createHeader(), payload));
  thrown.expectMessage("Firebase ID token has no \"sub\" (subject) claim.");
  verifier.verifyTokenAndSignature(TestOnlyImplFirebaseAuthTrampolines.getToken(token));
}
 
开发者ID:firebase,项目名称:firebase-admin-java,代码行数:11,代码来源:FirebaseTokenVerifierTest.java

示例9: verifyTokenFailure_EmptySubject

import com.google.firebase.auth.FirebaseToken; //导入依赖的package包/类
@Test
public void verifyTokenFailure_EmptySubject() throws Exception {
  Payload payload = createPayload();
  payload.setSubject("");
  FirebaseToken token =
      TestOnlyImplFirebaseAuthTrampolines.parseToken(
          FACTORY, createToken(createHeader(), payload));
  thrown.expectMessage("Firebase ID token has an empty string \"sub\" (subject) claim.");
  verifier.verifyTokenAndSignature(TestOnlyImplFirebaseAuthTrampolines.getToken(token));
}
 
开发者ID:firebase,项目名称:firebase-admin-java,代码行数:11,代码来源:FirebaseTokenVerifierTest.java

示例10: verifyTokenFailure_LongSubject

import com.google.firebase.auth.FirebaseToken; //导入依赖的package包/类
@Test
public void verifyTokenFailure_LongSubject() throws Exception {
  Payload payload = createPayload();
  payload.setSubject(
      "abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuv"
          + "wxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz");
  FirebaseToken token =
      TestOnlyImplFirebaseAuthTrampolines.parseToken(
          FACTORY, createToken(createHeader(), payload));
  thrown.expectMessage(
      "Firebase ID token has \"sub\" (subject) claim longer than 128 characters.");
  verifier.verifyTokenAndSignature(TestOnlyImplFirebaseAuthTrampolines.getToken(token));
}
 
开发者ID:firebase,项目名称:firebase-admin-java,代码行数:14,代码来源:FirebaseTokenVerifierTest.java

示例11: verifyTokenFailure_NotYetIssued

import com.google.firebase.auth.FirebaseToken; //导入依赖的package包/类
@Test
public void verifyTokenFailure_NotYetIssued() throws Exception {
  Payload payload = createPayload();
  payload.setIssuedAtTimeSeconds(System.currentTimeMillis() / 1000);
  payload.setExpirationTimeSeconds(System.currentTimeMillis() / 1000 + 3600);
  FirebaseToken token =
      TestOnlyImplFirebaseAuthTrampolines.parseToken(
          FACTORY, createToken(createHeader(), payload));
  thrown.expectMessage("Firebase ID token has expired or is not yet valid.");
  verifier.verifyTokenAndSignature(TestOnlyImplFirebaseAuthTrampolines.getToken(token));
}
 
开发者ID:firebase,项目名称:firebase-admin-java,代码行数:12,代码来源:FirebaseTokenVerifierTest.java

示例12: verifyTokenFailure_Expired

import com.google.firebase.auth.FirebaseToken; //导入依赖的package包/类
@Test
public void verifyTokenFailure_Expired() throws Exception {
  Payload payload = createPayload();
  payload.setIssuedAtTimeSeconds(0L);
  payload.setExpirationTimeSeconds(3600L);
  FirebaseToken token =
      TestOnlyImplFirebaseAuthTrampolines.parseToken(
          FACTORY, createToken(createHeader(), payload));
  thrown.expectMessage("Firebase ID token has expired or is not yet valid.");
  verifier.verifyTokenAndSignature(TestOnlyImplFirebaseAuthTrampolines.getToken(token));
}
 
开发者ID:firebase,项目名称:firebase-admin-java,代码行数:12,代码来源:FirebaseTokenVerifierTest.java

示例13: verifyTokenFailure_WrongCert

import com.google.firebase.auth.FirebaseToken; //导入依赖的package包/类
@Test
public void verifyTokenFailure_WrongCert() throws Exception {
  initCrypto(ServiceAccount.OWNER.getPrivateKey(), ServiceAccount.NONE.getCert());
  FirebaseToken token =
      TestOnlyImplFirebaseAuthTrampolines.parseToken(
          FACTORY, createToken(createHeader(), createPayload()));
  thrown.expectMessage("Firebase ID token isn't signed by a valid public key.");
  verifier.verifyTokenAndSignature(TestOnlyImplFirebaseAuthTrampolines.getToken(token));
}
 
开发者ID:firebase,项目名称:firebase-admin-java,代码行数:10,代码来源:FirebaseTokenVerifierTest.java

示例14: verifyTokenCertificateError

import com.google.firebase.auth.FirebaseToken; //导入依赖的package包/类
@Test
public void verifyTokenCertificateError() throws Exception {
  FirebaseToken token =
      TestOnlyImplFirebaseAuthTrampolines.parseToken(
          FACTORY, createToken(createHeader(), createPayload()));

  MockHttpTransport mockTransport = new MockHttpTransport() {
    @Override
    public LowLevelHttpRequest buildRequest(String method, String url) throws IOException {
      throw new IOException("Expected error");
    }
  };
  FirebaseTokenVerifier verifier = new FirebaseTokenVerifier.Builder()
      .setClock(CLOCK)
      .setPublicKeysManager(
          new GooglePublicKeysManager.Builder(mockTransport, FACTORY)
              .setClock(CLOCK)
              .setPublicCertsEncodedUrl(FirebaseTokenVerifier.CLIENT_CERT_URL)
              .build())
      .setProjectId(PROJECT_ID)
      .build();
  try {
    verifier.verifyTokenAndSignature(TestOnlyImplFirebaseAuthTrampolines.getToken(token));
    Assert.fail("No exception thrown");
  } catch (FirebaseAuthException expected) {
    assertTrue(expected.getCause() instanceof IOException);
    assertEquals("Expected error", expected.getCause().getMessage());
  }
}
 
开发者ID:firebase,项目名称:firebase-admin-java,代码行数:30,代码来源:FirebaseTokenVerifierTest.java

示例15: legacyCustomToken

import com.google.firebase.auth.FirebaseToken; //导入依赖的package包/类
@Test
public void legacyCustomToken() throws Exception {
  initCrypto(ServiceAccount.OWNER.getPrivateKey(), ServiceAccount.NONE.getCert());
  FirebaseToken token =
      TestOnlyImplFirebaseAuthTrampolines.parseToken(FACTORY, LEGACY_CUSTOM_TOKEN);
  thrown.expectMessage(
      "verifyIdToken() expects an ID token, but was given a legacy custom token.");
  verifier.verifyTokenAndSignature(TestOnlyImplFirebaseAuthTrampolines.getToken(token));
}
 
开发者ID:firebase,项目名称:firebase-admin-java,代码行数:10,代码来源:FirebaseTokenVerifierTest.java


注:本文中的com.google.firebase.auth.FirebaseToken类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。