com.google.firebase.auth.FirebaseAuth Java Examples

The following examples show how to use com.google.firebase.auth.FirebaseAuth. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: SignupActivity.java    From wmn-safety with MIT License 6 votes vote down vote up
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_signup);

    mHelpers = new Helpers(this);
    mFirebaseAuth = FirebaseAuth.getInstance();
    mFirebaseDatabase = FirebaseDatabase.getInstance();

    mEmailText = findViewById(R.id.sign_up_email_tv);
    mNameText = findViewById(R.id.sign_up_name_tv);
    mPhoneText = findViewById(R.id.sign_up_phone_tv);
    mPasswordText = findViewById(R.id.sign_up_password_tv);

    findViewById(R.id.sign_up_button).setOnClickListener(this);
    findViewById(R.id.sign_up_login_tv).setOnClickListener(this);

}
 
Example #2
Source File: TripHistory.java    From UberClone with MIT License 6 votes vote down vote up
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_trip_history);
    initToolbar();
    initRecyclerView();

    mAuth = FirebaseAuth.getInstance();
    database = FirebaseDatabase.getInstance();
    riderHistory = database.getReference(Common.history_driver);
    listData = new ArrayList<>();
    adapter = new historyAdapter(this, listData, new ClickListener() {
        @Override
        public void onClick(View view, int index) {

        }
    });
    rvHistory.setAdapter(adapter);
    getHistory();
}
 
Example #3
Source File: SpeakerDetailFragment.java    From white-label-event-app with Apache License 2.0 6 votes vote down vote up
@Override
public void onCreate(@Nullable Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    LOGGER.fine("onCreate");

    final Bundle args = getArguments();
    speakerId = args.getString(ARG_SPEAKER_ID);
    if (Strings.isNullOrEmpty(speakerId)) {
        throw new IllegalArgumentException(ARG_SPEAKER_ID + " can't be null or empty");
    }

    favSessionButtonManager = new FavSessionButtonManager(
        FirebaseDatabase.getInstance(), FirebaseAuth.getInstance(), new MyAuthRequiredListener());

    bus = Singletons.deps.getBus();
}
 
Example #4
Source File: LogoutHelper.java    From social-app-android with Apache License 2.0 6 votes vote down vote up
public static void signOut(GoogleApiClient mGoogleApiClient, FragmentActivity fragmentActivity) {
    FirebaseUser user = FirebaseAuth.getInstance().getCurrentUser();
    if (user != null) {
        ProfileInteractor.getInstance(fragmentActivity.getApplicationContext())
                .removeRegistrationToken(FirebaseInstanceId.getInstance().getToken(), user.getUid());

        for (UserInfo profile : user.getProviderData()) {
            String providerId = profile.getProviderId();
            logoutByProvider(providerId, mGoogleApiClient, fragmentActivity);
        }
        logoutFirebase(fragmentActivity.getApplicationContext());
    }

    if (clearImageCacheAsyncTask == null) {
        clearImageCacheAsyncTask = new ClearImageCacheAsyncTask(fragmentActivity.getApplicationContext());
        clearImageCacheAsyncTask.execute();
    }
}
 
Example #5
Source File: FireResetPassword.java    From Learning-Resources with MIT License 6 votes vote down vote up
@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.lo_fire_auth_resetpassword);

    mCrdntrlyot = (CoordinatorLayout) findViewById(R.id.cordntrlyot_fireauth_resetpaswrd);
    mTxtinptlyotEmail = (TextInputLayout) findViewById(R.id.txtinputlyot_fireauth_resetpaswrd_email);
    mTxtinptEtEmail = (TextInputEditText) findViewById(R.id.txtinptet_fireauth_resetpaswrd_email);
    mAppcmptbtnSignup = (AppCompatButton) findViewById(R.id.appcmptbtn_fireauth_resetpaswrd);
    mPrgrsbrMain = (ProgressBar) findViewById(R.id.prgrsbr_fireauth_resetpaswrd);

    mFireAuth = FirebaseAuth.getInstance();

    mAppcmptbtnSignup.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {

            // Check all field Validation and call API
            checkVldtnCallApi();
        }
    });

}
 
Example #6
Source File: FirebaseAuthSnippets.java    From firebase-admin-java with Apache License 2.0 6 votes vote down vote up
public void generateSignInWithEmailLink() {
  final ActionCodeSettings actionCodeSettings = initActionCodeSettings();
  final String displayName = "Example User";
  // [START sign_in_with_email_link]
  String email = "[email protected]";
  try {
    String link = FirebaseAuth.getInstance().generateSignInWithEmailLink(
        email, actionCodeSettings);
    // Construct email verification template, embed the link and send
    // using custom SMTP server.
    sendCustomPasswordResetEmail(email, displayName, link);
  } catch (FirebaseAuthException e) {
    System.out.println("Error generating email link: " + e.getMessage());
  }
  // [END sign_in_with_email_link]
}
 
Example #7
Source File: FirebaseAuthSnippets.java    From firebase-admin-java with Apache License 2.0 6 votes vote down vote up
@POST
@Path("/profile")
public Response verifySessionCookie(@CookieParam("session") Cookie cookie) {
  String sessionCookie = cookie.getValue();
  try {
    // Verify the session cookie. In this case an additional check is added to detect
    // if the user's Firebase session was revoked, user deleted/disabled, etc.
    final boolean checkRevoked = true;
    FirebaseToken decodedToken = FirebaseAuth.getInstance().verifySessionCookie(
        sessionCookie, checkRevoked);
    return serveContentForUser(decodedToken);
  } catch (FirebaseAuthException e) {
    // Session cookie is unavailable, invalid or revoked. Force user to login.
    return Response.temporaryRedirect(URI.create("/login")).build();
  }
}
 
Example #8
Source File: MainActivity.java    From snippets-android with Apache License 2.0 6 votes vote down vote up
public void taskChaining() {
    // [START task_chaining]
    Task<AuthResult> signInTask = FirebaseAuth.getInstance().signInAnonymously();

    signInTask.continueWithTask(new Continuation<AuthResult, Task<String>>() {
        @Override
        public Task<String> then(@NonNull Task<AuthResult> task) throws Exception {
            // Take the result from the first task and start the second one
            AuthResult result = task.getResult();
            return doSomething(result);
        }
    }).addOnSuccessListener(new OnSuccessListener<String>() {
        @Override
        public void onSuccess(String s) {
            // Chain of tasks completed successfully, got result from last task.
            // ...
        }
    }).addOnFailureListener(new OnFailureListener() {
        @Override
        public void onFailure(@NonNull Exception e) {
            // One of the tasks in the chain failed with an exception.
            // ...
        }
    });
    // [END task_chaining]
}
 
Example #9
Source File: AnonymousUpgradeActivity.java    From FirebaseUI-Android with Apache License 2.0 6 votes vote down vote up
private void handleSignInResult(int requestCode, int resultCode, Intent data) {
    if (requestCode == RC_SIGN_IN) {
        IdpResponse response = IdpResponse.fromResultIntent(data);
        if (response == null) {
            // User pressed back button
            return;
        }
        if (resultCode == RESULT_OK) {
            setStatus("Signed in as " + getUserIdentifier(FirebaseAuth.getInstance()
                    .getCurrentUser()));
        } else if (response.getError().getErrorCode() == ErrorCodes
                .ANONYMOUS_UPGRADE_MERGE_CONFLICT) {
            setStatus("Merge conflict: user already exists.");
            mResolveMergeButton.setEnabled(true);
            mPendingCredential = response.getCredentialForLinking();
        } else {
            Toast.makeText(this, "Auth error, see logs", Toast.LENGTH_SHORT).show();
            Log.w(TAG, "Error: " + response.getError().getMessage(), response.getError());
        }

        updateUI();
    }
}
 
Example #10
Source File: AuthTest.java    From gdx-fireapp with Apache License 2.0 6 votes vote down vote up
@Test
public void signInAnonymously_fail() {
    // Given
    Auth auth = new Auth();
    BiConsumer biConsumer = Mockito.mock(BiConsumer.class);
    Mockito.when(task.isSuccessful()).thenReturn(false);
    Mockito.when(task.getException()).thenReturn(new Exception());
    Mockito.doReturn(task).when(firebaseAuth).signInAnonymously();

    // When
    auth.signInAnonymously()
            .fail(biConsumer);

    // Then
    PowerMockito.verifyStatic(FirebaseAuth.class, VerificationModeFactory.times(1));
    FirebaseAuth.getInstance();
    Mockito.verify(firebaseAuth, VerificationModeFactory.times(1)).signInAnonymously();
    Mockito.verify(task, VerificationModeFactory.times(1)).addOnCompleteListener(Mockito.any(OnCompleteListener.class));
    Mockito.verify(biConsumer, VerificationModeFactory.times(1)).accept(Mockito.nullable(String.class), Mockito.any(Exception.class));
}
 
Example #11
Source File: RegistrationActivity.java    From Password-Storage with MIT License 6 votes vote down vote up
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    Fabric.with(this, new Crashlytics());
    setContentView(R.layout.activity_registration);
    auth = FirebaseAuth.getInstance();
    appStatus=new AppStatus(getApplicationContext());
    register = (Button) findViewById(R.id.btn_register);
    existinguser = (Button) findViewById(R.id.existinguser);
    edt_Password = (EditText) findViewById(R.id.edt_Rpassword);
    edt_RePassword = (EditText) findViewById(R.id.edt_RRepassword);
    edt_Email = (EditText) findViewById(R.id.edt_email);
    progressBar=(ProgressBar)findViewById(R.id.progressBar);
    register.setOnClickListener(this);
    existinguser.setOnClickListener(this);
}
 
Example #12
Source File: RatingDialogFragment.java    From firestore-android-arch-components with Apache License 2.0 6 votes vote down vote up
@Nullable
@Override
public View onCreateView(LayoutInflater inflater,
                         @Nullable ViewGroup container,
                         @Nullable Bundle savedInstanceState) {
    binding = DataBindingUtil.inflate(inflater, R.layout.dialog_rating, container, false);
    binding.setHandler((cancel, rate, text) -> {
        if (! cancel) {
            final Rating rating = new Rating(FirebaseAuth.getInstance().getCurrentUser(), rate, text.toString());
            if (mRatingListener != null) {
                mRatingListener.onRating(rating);
            }
        }
        dismiss();
    });
    return binding.getRoot();
}
 
Example #13
Source File: StorageTest.java    From firebase-android-sdk with Apache License 2.0 6 votes vote down vote up
@Test
public void putShouldFailWithNotAuthorized() throws Exception {
  FirebaseAuth auth = FirebaseAuth.getInstance();
  FirebaseStorage storage = FirebaseStorage.getInstance();

  auth.signOut();
  StorageReference blob = storage.getReference("restaurants").child(TestId.create());
  byte[] data = "Google NYC".getBytes(StandardCharsets.UTF_8);

  try {
    Task<?> putTask = blob.putBytes(Arrays.copyOf(data, data.length));
    Throwable failure = Tasks2.waitForFailure(putTask);
    StorageException ex = (StorageException) failure;
    assertThat(ex.getErrorCode()).isEqualTo(StorageException.ERROR_NOT_AUTHORIZED);
  } finally {
    Tasks2.waitBestEffort(blob.delete());
  }
}
 
Example #14
Source File: profile.java    From Beginner-Level-Android-Studio-Apps with GNU General Public License v3.0 6 votes vote down vote up
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_profile);
    btnFBLogout = findViewById(R.id.btnlogout);
    tvid = findViewById(R.id.tvId);

    mAuth = FirebaseAuth.getInstance();

    FirebaseUser user = mAuth.getCurrentUser();
    //String id = user.
   // tvid.setText(id);

    btnFBLogout.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            mAuth.signOut();//firebase
            LoginManager.getInstance().logOut();//facebook
            updateUI();

        }
    });
}
 
Example #15
Source File: MainActivity.java    From snippets-android with Apache License 2.0 6 votes vote down vote up
public void updatePassword() {
    // [START update_password]
    FirebaseUser user = FirebaseAuth.getInstance().getCurrentUser();
    String newPassword = "SOME-SECURE-PASSWORD";

    user.updatePassword(newPassword)
            .addOnCompleteListener(new OnCompleteListener<Void>() {
                @Override
                public void onComplete(@NonNull Task<Void> task) {
                    if (task.isSuccessful()) {
                        Log.d(TAG, "User password updated.");
                    }
                }
            });
    // [END update_password]
}
 
Example #16
Source File: ChatFragment.java    From SnapchatClone with MIT License 6 votes vote down vote up
private void listenForData() {
    DatabaseReference receiveDB = FirebaseDatabase.getInstance().getReference().child("users")
            .child(FirebaseAuth.getInstance().getUid()).child("received");

    receiveDB.addValueEventListener(new ValueEventListener() {
        @Override
        public void onDataChange(@NonNull DataSnapshot dataSnapshot) {
            if (dataSnapshot.exists()) {
                for (DataSnapshot snap : dataSnapshot.getChildren()) {
                    getUserInfo(snap.getKey());
                }
            }
        }

        @Override
        public void onCancelled(@NonNull DatabaseError databaseError) {

        }
    });
}
 
Example #17
Source File: newUser.java    From NITKart with MIT License 6 votes vote down vote up
private void sendVerificationEmail() {
    FirebaseUser user = FirebaseAuth.getInstance().getCurrentUser();
    user.sendEmailVerification()
            .addOnCompleteListener(new OnCompleteListener<Void>() {
                @Override
                public void onComplete(@NonNull Task<Void> task) {
                    if (task.isSuccessful()) {
                        // Email sent
                        finish();
                    } else {
                        // overridePendingTransition(0, 0);
                        // finish();
                        // overridePendingTransition(0, 0);
                        // startActivity(getIntent());
                        sendVerificationEmail();
                    }
                }
            });
}
 
Example #18
Source File: MainActivity.java    From snippets-android with Apache License 2.0 6 votes vote down vote up
public void linkAndMerge(AuthCredential credential) {
    FirebaseAuth mAuth = FirebaseAuth.getInstance();

    // [START auth_link_and_merge]
    FirebaseUser prevUser = FirebaseAuth.getInstance().getCurrentUser();
    mAuth.signInWithCredential(credential)
            .addOnCompleteListener(new OnCompleteListener<AuthResult>() {
                @Override
                public void onComplete(@NonNull Task<AuthResult> task) {
                    FirebaseUser currentUser = task.getResult().getUser();
                    // Merge prevUser and currentUser accounts and data
                    // ...
                }
            });
    // [END auth_link_and_merge]
}
 
Example #19
Source File: newUser.java    From NITKart with MIT License 5 votes vote down vote up
@Override
public void finish() {
    FirebaseAuth.getInstance().signOut();
    progressBar.setVisibility(View.GONE);
    if (isRegistrationClicked) {
        Toast.makeText(getApplicationContext(), "Verify Email and Login", Toast.LENGTH_LONG).show();
    }
    startActivity(new Intent(getApplicationContext(), OpenScreen.class));
    super.finish();
}
 
Example #20
Source File: FlagEightLoginActivity.java    From InjuredAndroid with Apache License 2.0 5 votes vote down vote up
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_flag_eight_login);
    Toolbar toolbar = findViewById(R.id.toolbar);
    setSupportActionBar(toolbar);

    FirebaseAuth mAuth;
    mAuth = FirebaseAuth.getInstance();

    mAuth.signInAnonymously()
            .addOnCompleteListener(this, task -> {
                if (task.isSuccessful()) {
                    // Sign in success, update UI with the signed-in user's information
                    Log.d(TAG, "signInAnonymously:success");

                } else {
                    // If sign in fails, display a message to the user.
                    Log.w(TAG, "signInAnonymously:failure", task.getException());
                    Toast.makeText(FlagEightLoginActivity.this, "Authentication failed.",
                            Toast.LENGTH_SHORT).show();
                }
            });

    FloatingActionButton fab = findViewById(R.id.fab);
    fab.setOnClickListener(view -> {
        if (click == 0) {
            Snackbar.make(view, "AWS CLI.", Snackbar.LENGTH_LONG)
                    .setAction("Action",null).show();
            click = click + 1;
        } else if (click == 1) {
            Snackbar.make(view, "AWS profiles and credentials.", Snackbar.LENGTH_LONG)
                    .setAction("Action",null).show();
            click = 0;
        }
    });
}
 
Example #21
Source File: LogoutInteractor.java    From firebase-chat with MIT License 5 votes vote down vote up
@Override
public void performFirebaseLogout() {
    if (FirebaseAuth.getInstance().getCurrentUser() != null) {
        FirebaseAuth.getInstance().signOut();
        mOnLogoutListener.onSuccess("Successfully logged out!");
    } else {
        mOnLogoutListener.onFailure("No user logged in yet!");
    }
}
 
Example #22
Source File: FirestackAuth.java    From react-native-firestack with MIT License 5 votes vote down vote up
@ReactMethod
public void deleteUser(final Callback callback) {
  FirebaseUser user = FirebaseAuth.getInstance().getCurrentUser();

  if (user != null) {
    user.delete()
      .addOnCompleteListener(new OnCompleteListener<Void>() {
        @Override
        public void onComplete(@NonNull Task<Void> task) {
          if (task.isSuccessful()) {
            Log.d(TAG, "User account deleted");
            WritableMap resp = Arguments.createMap();
            resp.putString("status", "complete");
            resp.putString("msg", "User account deleted");
            callback.invoke(null, resp);
          } else {
            // userErrorCallback(task, callback);
          }
        }
      }).addOnFailureListener(new OnFailureListener() {
          @Override
          public void onFailure(@NonNull Exception ex) {
            userExceptionCallback(ex, callback);
          }
        });
  } else {
    WritableMap err = Arguments.createMap();
    err.putInt("errorCode", NO_CURRENT_USER);
    err.putString("errorMessage", "No current user");
    callback.invoke(err);
  }
}
 
Example #23
Source File: PostDetailsPresenter.java    From social-app-android with Apache License 2.0 5 votes vote down vote up
private void initLikeButtonState() {
    FirebaseUser firebaseUser = FirebaseAuth.getInstance().getCurrentUser();
    if (firebaseUser != null && post != null) {
        postManager.hasCurrentUserLike(context, post.getId(), firebaseUser.getUid(), exist -> {
            ifViewAttached(view -> {
                view.initLikeButtonState(exist);
            });
        });
    }
}
 
Example #24
Source File: ProfileManager.java    From social-app-android with Apache License 2.0 5 votes vote down vote up
public ProfileStatus checkProfile() {
    FirebaseUser user = FirebaseAuth.getInstance().getCurrentUser();

    if (user == null) {
        return ProfileStatus.NOT_AUTHORIZED;
    } else if (!PreferencesUtil.isProfileCreated(context)) {
        return ProfileStatus.NO_PROFILE;
    } else {
        return ProfileStatus.PROFILE_CREATED;
    }
}
 
Example #25
Source File: DatabaseTest.java    From firebase-android-sdk with Apache License 2.0 5 votes vote down vote up
@Test
public void setValueShouldTriggerListenerWithNewlySetData() throws Exception {
  FirebaseAuth auth = FirebaseAuth.getInstance();
  FirebaseDatabase database = FirebaseDatabase.getInstance();

  auth.signOut();
  Task<?> signInTask = auth.signInWithEmailAndPassword("[email protected]", "password");
  Tasks2.waitForSuccess(signInTask);

  DatabaseReference doc = database.getReference("restaurants").child(TestId.create());
  SnapshotListener listener = new SnapshotListener();
  doc.addListenerForSingleValueEvent(listener);

  HashMap<String, Object> data = new HashMap<>();
  data.put("location", "Google NYC");

  try {
    Task<?> setTask = doc.setValue(new HashMap<>(data));
    Task<DataSnapshot> snapshotTask = listener.toTask();
    Tasks2.waitForSuccess(setTask);
    Tasks2.waitForSuccess(snapshotTask);

    DataSnapshot result = snapshotTask.getResult();
    assertThat(result.getValue()).isEqualTo(data);
  } finally {
    Tasks2.waitBestEffort(doc.removeValue());
  }
}
 
Example #26
Source File: ChooseReceiverActivity.java    From SnapchatClone with MIT License 5 votes vote down vote up
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_choose_receiver);

    byte[] img = CameraFragment.imageByte;

    try {
        bitmap = BitmapFactory.decodeByteArray(img, 0, img.length);
    } catch (Exception e) {
        e.printStackTrace();
        finish();
    }

    Uid = FirebaseAuth.getInstance().getUid();

    mRecyclerView = findViewById(R.id.recyclerViewFindUsers);
    mRecyclerView.setNestedScrollingEnabled(false);
    mRecyclerView.setHasFixedSize(false);

    layoutManager = new LinearLayoutManager(getApplication());
    mRecyclerView.setLayoutManager(layoutManager);

    adapter = new RecieverAdapter(getDataset(), getApplication());

    mRecyclerView.setAdapter(adapter);

    FloatingActionButton mFab = findViewById(R.id.fab);
    mFab.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            saveToStories();
        }
    });
}
 
Example #27
Source File: ConversationListFragment.java    From chat21-android-sdk with GNU Affero General Public License v3.0 5 votes vote down vote up
@Override
    public void onSwipeMenuClosed(Conversation conversation, int position) {
//        Log.i(TAG, "onSwipeMenuClosed: conversation: " + conversation.toString() + " position: " + position);

        String conversationId = conversation.getConversationId();
        boolean isSupportConversation = conversationId.startsWith("support-group");

        // retrieve the firebase user token
        GetTokenResult task = FirebaseAuth.getInstance().getCurrentUser().getIdToken(false).getResult();
        String token = task.getToken();

        // create the header parameters
        Map<String, String> headerParams = new HashMap<>();
        headerParams.put("Accept", "application/json");
        headerParams.put("Content-Type", "application/json");
        headerParams.put("Authorization", "Bearer " + token);

        if (!isSupportConversation) {
            // is not support group
            deleteConversation(conversationId, headerParams);
        } else {
            // is support group
            closeSupportGroup(conversationId, headerParams);
        }

        // NOTE: dismiss is not necessary because the view disappears when the conversation is removed
//        // dismiss the swipe menu
//        conversationsListAdapter.dismissSwipeMenu(recyclerViewConversations, position);
//        conversationsListAdapter.notifyItemChanged(position);
    }
 
Example #28
Source File: EmailPasswordActivity.java    From endpoints-samples with Apache License 2.0 5 votes vote down vote up
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_emailpassword);

    // Views
    mStatusTextView = (TextView) findViewById(R.id.status);
    mDetailTextView = (TextView) findViewById(R.id.detail);
    mEmailField = (EditText) findViewById(R.id.field_email);
    mPasswordField = (EditText) findViewById(R.id.field_password);

    // Buttons
    findViewById(R.id.email_sign_in_button).setOnClickListener(this);
    findViewById(R.id.email_create_account_button).setOnClickListener(this);
    findViewById(R.id.sign_out_button).setOnClickListener(this);

    // [START initialize_auth]
    mAuth = FirebaseAuth.getInstance();
    // [END initialize_auth]

    // [START auth_state_listener]
    mAuthListener = new FirebaseAuth.AuthStateListener() {
        @Override
        public void onAuthStateChanged(@NonNull FirebaseAuth firebaseAuth) {
            FirebaseUser user = firebaseAuth.getCurrentUser();
            if (user != null) {
                // User is signed in
                Log.d(TAG, "onAuthStateChanged:signed_in:" + user.getUid());
            } else {
                // User is signed out
                Log.d(TAG, "onAuthStateChanged:signed_out");
            }
            // [START_EXCLUDE]
            updateUI(user);
            // [END_EXCLUDE]
        }
    };
    // [END auth_state_listener]
}
 
Example #29
Source File: FirebaseAuthSnippets.java    From firebase-admin-java with Apache License 2.0 5 votes vote down vote up
public static void setCustomUserClaimsScript() throws FirebaseAuthException {
  // [START set_custom_user_claims_script]
  UserRecord user = FirebaseAuth.getInstance()
      .getUserByEmail("[email protected]");
  // Confirm user is verified.
  if (user.isEmailVerified()) {
    Map<String, Object> claims = new HashMap<>();
    claims.put("admin", true);
    FirebaseAuth.getInstance().setCustomUserClaims(user.getUid(), claims);
  }
  // [END set_custom_user_claims_script]
}
 
Example #30
Source File: User.java    From gdx-fireapp with Apache License 2.0 5 votes vote down vote up
@Override
public Promise<GdxFirebaseUser> updatePassword(char[] newPassword) {
    if (FirebaseAuth.getInstance().getCurrentUser() == null) {
        throw new IllegalStateException();
    }
    return FuturePromise.when(new AuthPromiseConsumer<>(FirebaseAuth.getInstance().getCurrentUser()
            .updatePassword(new String(newPassword))));
}