|
18 | 18 |
|
19 | 19 | import static com.google.common.base.Preconditions.checkArgument; |
20 | 20 | import static com.google.common.base.Preconditions.checkNotNull; |
| 21 | +import static com.google.firebase.auth.internal.Utils.isEmulatorMode; |
21 | 22 |
|
22 | 23 | import com.google.api.client.json.JsonFactory; |
23 | 24 | import com.google.api.client.util.Clock; |
@@ -309,7 +310,7 @@ protected FirebaseToken execute() throws FirebaseAuthException { |
309 | 310 | @VisibleForTesting |
310 | 311 | FirebaseTokenVerifier getIdTokenVerifier(boolean checkRevoked) { |
311 | 312 | FirebaseTokenVerifier verifier = idTokenVerifier.get(); |
312 | | - if (checkRevoked) { |
| 313 | + if (checkRevoked || isEmulatorMode()) { |
313 | 314 | FirebaseUserManager userManager = getUserManager(); |
314 | 315 | verifier = RevocationCheckDecorator.decorateIdTokenVerifier(verifier, userManager); |
315 | 316 | } |
@@ -389,7 +390,7 @@ public FirebaseToken execute() throws FirebaseAuthException { |
389 | 390 | @VisibleForTesting |
390 | 391 | FirebaseTokenVerifier getSessionCookieVerifier(boolean checkRevoked) { |
391 | 392 | FirebaseTokenVerifier verifier = cookieVerifier.get(); |
392 | | - if (checkRevoked) { |
| 393 | + if (checkRevoked || isEmulatorMode()) { |
393 | 394 | FirebaseUserManager userManager = getUserManager(); |
394 | 395 | verifier = RevocationCheckDecorator.decorateSessionCookieVerifier(verifier, userManager); |
395 | 396 | } |
@@ -553,6 +554,64 @@ protected UserRecord execute() throws FirebaseAuthException { |
553 | 554 | }; |
554 | 555 | } |
555 | 556 |
|
| 557 | + /** |
| 558 | + * Gets the user data for the user corresponding to a given provider id. |
| 559 | + * |
| 560 | + * @param providerId Identifier for the given federated provider, for example, |
| 561 | + * "google.com" for the Google provider. |
| 562 | + * @param uid The user identifier with the given provider. |
| 563 | + * @return A {@link UserRecord} instance. |
| 564 | + * @throws IllegalArgumentException If the uid is null or empty, or if |
| 565 | + * the providerId is null, empty, or does not belong to a federated provider. |
| 566 | + * @throws FirebaseAuthException If an error occurs while retrieving user data. |
| 567 | + */ |
| 568 | + public UserRecord getUserByProviderUid( |
| 569 | + @NonNull String providerId, @NonNull String uid) throws FirebaseAuthException { |
| 570 | + return getUserByProviderUidOp(providerId, uid).call(); |
| 571 | + } |
| 572 | + |
| 573 | + /** |
| 574 | + * Gets the user data for the user corresponding to a given provider id. |
| 575 | + * |
| 576 | + * @param providerId Identifer for the given federated provider, for example, |
| 577 | + * "google.com" for the Google provider. |
| 578 | + * @param uid The user identifier with the given provider. |
| 579 | + * @return An {@code ApiFuture} which will complete successfully with a {@link UserRecord} |
| 580 | + * instance. If an error occurs while retrieving user data or if the provider ID and uid |
| 581 | + * do not correspond to a user, the future throws a {@link FirebaseAuthException}. |
| 582 | + * @throws IllegalArgumentException If the uid is null or empty, or if |
| 583 | + * the provider ID is null, empty, or does not belong to a federated provider. |
| 584 | + */ |
| 585 | + public ApiFuture<UserRecord> getUserByProviderUidAsync( |
| 586 | + @NonNull String providerId, @NonNull String uid) { |
| 587 | + return getUserByProviderUidOp(providerId, uid).callAsync(firebaseApp); |
| 588 | + } |
| 589 | + |
| 590 | + private CallableOperation<UserRecord, FirebaseAuthException> getUserByProviderUidOp( |
| 591 | + final String providerId, final String uid) { |
| 592 | + checkArgument(!Strings.isNullOrEmpty(providerId), "providerId must not be null or empty"); |
| 593 | + checkArgument(!Strings.isNullOrEmpty(uid), "uid must not be null or empty"); |
| 594 | + |
| 595 | + // Although we don't really advertise it, we want to also handle |
| 596 | + // non-federated idps with this call. So if we detect one of them, we'll |
| 597 | + // reroute this request appropriately. |
| 598 | + if (providerId == "phone") { |
| 599 | + return this.getUserByPhoneNumberOp(uid); |
| 600 | + } else if (providerId == "email") { |
| 601 | + return this.getUserByEmailOp(uid); |
| 602 | + } |
| 603 | + |
| 604 | + checkArgument(!providerId.equals("password") |
| 605 | + && !providerId.equals("anonymous"), "providerId must belong to a federated provider"); |
| 606 | + final FirebaseUserManager userManager = getUserManager(); |
| 607 | + return new CallableOperation<UserRecord, FirebaseAuthException>() { |
| 608 | + @Override |
| 609 | + protected UserRecord execute() throws FirebaseAuthException { |
| 610 | + return userManager.getUserByProviderUid(providerId, uid); |
| 611 | + } |
| 612 | + }; |
| 613 | + } |
| 614 | + |
556 | 615 | /** |
557 | 616 | * Gets a page of users starting from the specified {@code pageToken}. Page size is limited to |
558 | 617 | * 1000 users. |
|
0 commit comments