本文整理汇总了Java中com.google.firebase.auth.FirebaseToken类的典型用法代码示例。如果您正苦于以下问题:Java FirebaseToken类的具体用法?Java FirebaseToken怎么用?Java FirebaseToken使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
FirebaseToken类属于com.google.firebase.auth包,在下文中一共展示了FirebaseToken类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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
示例16: retrieveUser
import com.google.firebase.auth.FirebaseToken; //导入依赖的package包/类
@Override
protected UserDetails retrieveUser(String username, UsernamePasswordAuthenticationToken authentication) throws AuthenticationException {
final FirebaseAuthenticationToken authenticationToken = (FirebaseAuthenticationToken) authentication;
final CompletableFuture<FirebaseToken> future = new CompletableFuture<>();
firebaseAuth.verifyIdToken(authenticationToken.getToken()).addOnSuccessListener(future::complete);
try {
final FirebaseToken token = future.get();
return new FirebaseUserDetails(token.getEmail(), token.getUid());
} catch (InterruptedException | ExecutionException e) {
throw new SessionAuthenticationException(e.getMessage());
}
}
开发者ID:awaters1,项目名称:spring-security-firebase,代码行数:13,代码来源:FirebaseAuthenticationProvider.java
示例17: validateToken
import com.google.firebase.auth.FirebaseToken; //导入依赖的package包/类
private Boolean validateToken(String token) {
Task task = FirebaseAuth.getInstance().verifyIdToken(token);
// TODO refactor
// wait for task to finish
while (!task.isComplete()) {
}
FirebaseToken decodedToken = (FirebaseToken) task.getResult();
return decodedToken.getUid() != null && !decodedToken.getUid().isEmpty();
}
开发者ID:trvlrch,项目名称:trvlr-backend,代码行数:12,代码来源:FirebaseService.java
示例18: saveAccount
import com.google.firebase.auth.FirebaseToken; //导入依赖的package包/类
public static final void saveAccount(FirebaseToken firebaseToken, String token) {
AccountJDO account = AccountManager.addAccount(
firebaseToken.getUid(),
AccountJDO.FIREBASECLIENT,
firebaseToken.getEmail(),
firebaseToken.getName(),
firebaseToken.getIssuer(),
firebaseToken.getName(),
firebaseToken.getPicture(), false);
UserLoggedInManager.submitOauthUser(account.getUniqueId(), token);
}
开发者ID:WELTEN,项目名称:dojo-ibl,代码行数:14,代码来源:OauthFirebaseWorker.java
示例19: authenticateFirebaseUser
import com.google.firebase.auth.FirebaseToken; //导入依赖的package包/类
public void authenticateFirebaseUser(String userToken) {
Task<FirebaseToken> tokenTask = FirebaseAuth.getInstance().verifyIdToken(userToken);
try {
Tasks.await(tokenTask);
} catch (Exception e) {
LOG.log(Level.SEVERE, "An error occurred while authenticating the user token", e);
return;
}
this.user = tokenTask.getResult();
}
开发者ID:google,项目名称:iosched,代码行数:11,代码来源:FirebaseWrapper.java
示例20: parse
import com.google.firebase.auth.FirebaseToken; //导入依赖的package包/类
/** Parses a serialized {@link FirebaseToken} without verification. */
public static FirebaseToken parse(String serialized) {
return FirebaseTestTrampoline.parseToken(JacksonFactory.getDefaultInstance(), serialized);
}
开发者ID:curioswitch,项目名称:curiostack,代码行数:5,代码来源:FirebaseTestUtil.java
注:本文中的com.google.firebase.auth.FirebaseToken类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论