Java Code Examples for com.google.firebase.auth.FacebookAuthProvider#getCredential()
The following examples show how to use
com.google.firebase.auth.FacebookAuthProvider#getCredential() .
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: LoginActivity.java From android-paypal-example with Apache License 2.0 | 6 votes |
private void handleFacebookAccessToken(AccessToken token) { Log.d(TAG, "handleFacebookAccessToken:" + token); AuthCredential credential = FacebookAuthProvider.getCredential(token.getToken()); mAuth.signInWithCredential(credential) .addOnCompleteListener(this, new OnCompleteListener<AuthResult>() { @Override public void onComplete(@NonNull Task<AuthResult> task) { if (task.isSuccessful()) { // Sign in success, update UI with the signed-in user's information Log.d(TAG, "signInWithCredential:success"); updateUI(mAuth.getCurrentUser()); } else { // If sign in fails, display a message to the user. Log.w(TAG, "signInWithCredential:failure", task.getException()); Toast.makeText(LoginActivity.this, "Authentication failed.", Toast.LENGTH_SHORT).show(); } } }); }
Example 2
Source File: FirestackAuth.java From react-native-firestack with MIT License | 6 votes |
@ReactMethod public void facebookLogin(String Token, final Callback callback) { mAuth = FirebaseAuth.getInstance(); AuthCredential credential = FacebookAuthProvider.getCredential(Token); mAuth.signInWithCredential(credential) .addOnCompleteListener(new OnCompleteListener<AuthResult>() { @Override public void onComplete(@NonNull Task<AuthResult> task) { if (task.isSuccessful()) { FirestackAuthModule.this.user = task.getResult().getUser(); userCallback(FirestackAuthModule.this.user, callback); }else{ // userErrorCallback(task, callback); } } }).addOnFailureListener(new OnFailureListener() { @Override public void onFailure(@NonNull Exception ex) { userExceptionCallback(ex, callback); } }); }
Example 3
Source File: FireSignin.java From Learning-Resources with MIT License | 6 votes |
private void firebaseAuthWithFacebook(AccessToken accessToken) { mPrgrsbrMain.setVisibility(View.VISIBLE); LogManager.printLog(LOGTYPE_INFO, "signInWithFacebookToken: " + accessToken); AuthCredential credential = FacebookAuthProvider.getCredential(accessToken.getToken()); mFireAuth.signInWithCredential(credential) .addOnCompleteListener(this, new OnCompleteListener<AuthResult>() { @Override public void onComplete(@NonNull Task<AuthResult> task) { LogManager.printLog(LOGTYPE_DEBUG, "signInWithCredential:onComplete:" + task.isSuccessful()); if (!task.isSuccessful()) { mPrgrsbrMain.setVisibility(View.GONE); Log.w(LOG_TAG, "signInWithCredential", task.getException()); Snackbar.make(mCrdntrlyot, "Authentication failed.\n" + task.getException().getMessage(), Snackbar.LENGTH_LONG).show(); } else successLoginGetData(task); } }); }
Example 4
Source File: MainActivity.java From Beginner-Level-Android-Studio-Apps with GNU General Public License v3.0 | 5 votes |
private void handleFacebookAccessToken(AccessToken token) { Log.d(TAG, "handleFacebookAccessToken:" + token); AuthCredential credential = FacebookAuthProvider.getCredential(token.getToken()); //sign with credential which create from firebase auth mAuth.signInWithCredential(credential) .addOnCompleteListener(this, new OnCompleteListener<AuthResult>() { @Override public void onComplete(@NonNull Task<AuthResult> task) { if (task.isSuccessful()) { // Sign in success, update UI with the signed-in user's information Log.d(TAG, "signInWithCredential:success"); FirebaseUser user = mAuth.getCurrentUser(); btnFacebook.setEnabled(true); updateUI(user); } else { // If sign in fails, display a message to the user. Log.w(TAG, "signInWithCredential:failure", task.getException()); Toast.makeText(MainActivity.this, "Authentication failed.", Toast.LENGTH_SHORT).show(); btnFacebook.setEnabled(true); updateUI(null); } // ... } }); }
Example 5
Source File: LinkingSocialProviderResponseHandlerTest.java From FirebaseUI-Android with Apache License 2.0 | 5 votes |
@Test public void testSignIn_genericIdpLinkingFlow_expectImmediateLink() { mHandler.getOperation().observeForever(mResponseObserver); // Set Facebook credential AuthCredential facebookAuthCredential = FacebookAuthProvider.getCredential(TestConstants.TOKEN); mHandler.setRequestedSignInCredentialForEmail(facebookAuthCredential, TestConstants.EMAIL); // Fake social response from Microsoft IdpResponse idpResponse = new IdpResponse.Builder( new User.Builder(MICROSOFT_PROVIDER, TestConstants.EMAIL) .setName(DISPLAY_NAME) .build()) .build(); when(mMockAuth.getCurrentUser()).thenReturn(mMockUser); when(mMockUser.linkWithCredential(any(AuthCredential.class))) .thenReturn(AutoCompleteTask.forSuccess(FakeAuthResult.INSTANCE)); mHandler.startSignIn(idpResponse); InOrder inOrder = inOrder(mResponseObserver); inOrder.verify(mResponseObserver) .onChanged(argThat(ResourceMatchers.<IdpResponse>isLoading())); ArgumentCaptor<Resource<IdpResponse>> resolveCaptor = ArgumentCaptor.forClass(Resource.class); inOrder.verify(mResponseObserver).onChanged(resolveCaptor.capture()); assertThat(resolveCaptor.getValue().getValue()).isNotNull(); }
Example 6
Source File: ProviderUtils.java From FirebaseUI-Android with Apache License 2.0 | 5 votes |
@Nullable public static AuthCredential getAuthCredential(IdpResponse response) { if (response.hasCredentialForLinking()) { return response.getCredentialForLinking(); } switch (response.getProviderType()) { case GoogleAuthProvider.PROVIDER_ID: return GoogleAuthProvider.getCredential(response.getIdpToken(), null); case FacebookAuthProvider.PROVIDER_ID: return FacebookAuthProvider.getCredential(response.getIdpToken()); default: return null; } }
Example 7
Source File: FirestackAuth.java From react-native-firestack with MIT License | 5 votes |
@ReactMethod public void reauthenticateWithCredentialForProvider(final String provider, final String authToken, final String authSecret, final Callback callback) { AuthCredential credential; if (provider.equals("facebook")) { credential = FacebookAuthProvider.getCredential(authToken); } else if (provider.equals("google")) { credential = GoogleAuthProvider.getCredential(authToken, null); } else if (provider.equals("twitter")) { credential = TwitterAuthProvider.getCredential(authToken, authSecret); } else { // TODO: FirestackUtils.todoNote(TAG, "reauthenticateWithCredentialForProvider", callback); // AuthCredential credential; // Log.d(TAG, "reauthenticateWithCredentialForProvider called with: " + provider); return; } FirebaseUser user = FirebaseAuth.getInstance().getCurrentUser(); if (user != null) { user.reauthenticate(credential) .addOnCompleteListener(new OnCompleteListener<Void>() { @Override public void onComplete(@NonNull Task<Void> task) { if (task.isSuccessful()) { Log.d(TAG, "User re-authenticated with " + provider); FirebaseUser u = FirebaseAuth.getInstance().getCurrentUser(); userCallback(u, callback); } else { // userErrorCallback(task, callback); } } }); } else { WritableMap err = Arguments.createMap(); err.putInt("errorCode", NO_CURRENT_USER); err.putString("errorMessage", "No current user"); callback.invoke(err); } }
Example 8
Source File: RegisterActivity.java From kute with Apache License 2.0 | 5 votes |
private void handleFacebookAccessToken(AccessToken token) { Log.d(TAG, "handleFacebookAccessToken:" + token); // [START_EXCLUDE silent] Toast.makeText(getApplicationContext(),"Facebook show dialog",Toast.LENGTH_LONG).show(); //showProgressDialog(); // [END_EXCLUDE] AuthCredential credential = FacebookAuthProvider.getCredential(token.getToken()); mAuth.signInWithCredential(credential) .addOnCompleteListener(this, new OnCompleteListener<AuthResult>() { @Override public void onComplete(@NonNull Task<AuthResult> task) { try{ Log.d(TAG, "signInWithCredential:onComplete:" + task.isSuccessful()); // If sign in fails, display a message to the user. If sign in succeeds // the auth state listener will be notified and logic to handle the // signed in user can be handled in the listener. if (!task.isSuccessful()) { //make user partial login to logout signOut(); Log.w(TAG, "signInWithCredential", task.getException()); Toast.makeText(RegisterActivity.this, "Authentication failed.", Toast.LENGTH_SHORT).show(); } // [START_EXCLUDE] Toast.makeText(getApplicationContext(),"Facebook hide dialog",Toast.LENGTH_LONG).show(); //hideProgressDialog(); // [END_EXCLUDE] } catch (Exception e){ e.printStackTrace(); } } }); }
Example 9
Source File: FacebookLoginActivity.java From endpoints-samples with Apache License 2.0 | 5 votes |
private void handleFacebookAccessToken(AccessToken token) { Log.d(TAG, "handleFacebookAccessToken:" + token); // [START_EXCLUDE silent] showProgressDialog(); // [END_EXCLUDE] AuthCredential credential = FacebookAuthProvider.getCredential(token.getToken()); mAuth.signInWithCredential(credential) .addOnCompleteListener(this, new OnCompleteListener<AuthResult>() { @Override public void onComplete(@NonNull Task<AuthResult> task) { Log.d(TAG, "signInWithCredential:onComplete:" + task.isSuccessful()); // If sign in fails, display a message to the user. If sign in succeeds // the auth state listener will be notified and logic to handle the // signed in user can be handled in the listener. if (!task.isSuccessful()) { Log.w(TAG, "signInWithCredential", task.getException()); Toast.makeText(FacebookLoginActivity.this, "Authentication failed.", Toast.LENGTH_SHORT).show(); } // [START_EXCLUDE] hideProgressDialog(); // [END_EXCLUDE] } }); }
Example 10
Source File: FacebookLoginActivity.java From quickstart-android with Apache License 2.0 | 5 votes |
private void handleFacebookAccessToken(AccessToken token) { Log.d(TAG, "handleFacebookAccessToken:" + token); // [START_EXCLUDE silent] showProgressBar(); // [END_EXCLUDE] AuthCredential credential = FacebookAuthProvider.getCredential(token.getToken()); mAuth.signInWithCredential(credential) .addOnCompleteListener(this, new OnCompleteListener<AuthResult>() { @Override public void onComplete(@NonNull Task<AuthResult> task) { if (task.isSuccessful()) { // Sign in success, update UI with the signed-in user's information Log.d(TAG, "signInWithCredential:success"); FirebaseUser user = mAuth.getCurrentUser(); updateUI(user); } else { // If sign in fails, display a message to the user. Log.w(TAG, "signInWithCredential:failure", task.getException()); Toast.makeText(FacebookLoginActivity.this, "Authentication failed.", Toast.LENGTH_SHORT).show(); updateUI(null); } // [START_EXCLUDE] hideProgressBar(); // [END_EXCLUDE] } }); }
Example 11
Source File: LoginActivity.java From Simple-Blog-App with MIT License | 5 votes |
private void signInWithFacebook(AccessToken token) { Log.d(TAG, "signInWithFacebook:" + token.getToken()); AuthCredential credential = FacebookAuthProvider.getCredential(token.getToken()); final String tokenString = token.getToken(); mAuth.signInWithCredential(credential) .addOnCompleteListener(this, new OnCompleteListener<AuthResult>() { @Override public void onComplete(@NonNull Task<AuthResult> task) { Log.d(TAG, "signInWithCredential:onComplete:" + task.isSuccessful()); // // startActivity(new Intent(SignUp09.this, Dashboard.class)); // If sign in fails, display a message to the user. If sign in succeeds // the auth state listener will be notified and logic to handle the // signed in user can be handled in the listener. if (!task.isSuccessful()) { Log.w(TAG, "signInWithCredential", task.getException()); Toast.makeText(LoginActivity.this, "Sorry for inconvenience,Please try again..", Toast.LENGTH_SHORT).show(); } else { //signInFacebook(tokenString); Toast.makeText(LoginActivity.this, "Welcome..!", Toast.LENGTH_SHORT).show(); checkUserExist(); } } }); }
Example 12
Source File: SignInBaseActivity.java From Expert-Android-Programming with MIT License | 5 votes |
private void handleFacebookAccessToken(final AccessToken token) { MyLg.d("KOI", "handleFacebookAccessToken:" + token); AuthCredential credential = FacebookAuthProvider.getCredential(token.getToken()); mAuth.signInWithCredential(credential) .addOnCompleteListener((Activity) context, new OnCompleteListener<AuthResult>() { @Override public void onComplete(@NonNull Task<AuthResult> task) { MyLg.d(TAG, "signInWithCredential:onComplete:" + task.isSuccessful()); } }); }
Example 13
Source File: FacebookSign.java From FeedFire with MIT License | 5 votes |
private void handleFacebookAccessToken(AccessToken token) { FirebaseAuth auth = FirebaseAuth.getInstance(); AuthCredential credential = FacebookAuthProvider.getCredential(token.getToken()); auth.signInWithCredential(credential) .addOnCompleteListener(mActivity, new OnCompleteListener<AuthResult>() { @Override public void onComplete(@NonNull Task<AuthResult> task) { if (!task.isSuccessful()) { mFaceCallback.cancelLoginFace(); }else{ mFaceCallback.getInfoFace(); } } }); }
Example 14
Source File: MainActivity.java From snippets-android with Apache License 2.0 | 4 votes |
public void getFbCredentials() { AccessToken token = AccessToken.getCurrentAccessToken(); // [START auth_fb_cred] AuthCredential credential = FacebookAuthProvider.getCredential(token.getToken()); // [END auth_fb_cred] }
Example 15
Source File: LinkingSocialProviderResponseHandlerTest.java From FirebaseUI-Android with Apache License 2.0 | 4 votes |
@Test public void testSignIn_withDifferentIdp_expectSuccess() { mHandler.getOperation().observeForever(mResponseObserver); // We're going to fake a sign in with facebook, where the email belongs // to an existing account with a Google provider. // Fake social response from Google IdpResponse response = new IdpResponse.Builder(new User.Builder( GoogleAuthProvider.PROVIDER_ID, TestConstants.EMAIL).build()) .setToken(TestConstants.TOKEN) .build(); // Set facebook credential AuthCredential facebookAuthCredential = FacebookAuthProvider.getCredential(TestConstants.TOKEN); mHandler.setRequestedSignInCredentialForEmail(facebookAuthCredential, TestConstants.EMAIL); // mock sign in with Google credential to always work when(mMockAuth.signInWithCredential(any(GoogleAuthCredential.class))) .thenReturn(AutoCompleteTask.forSuccess(FakeAuthResult.INSTANCE)); // Mock linking with Facebook to always work when(FakeAuthResult.INSTANCE.getUser().linkWithCredential(facebookAuthCredential)) .thenReturn(new AutoContinueTask<>(FakeAuthResult.INSTANCE, FakeAuthResult.INSTANCE, true, null)); mHandler.startSignIn(response); verify(mMockAuth).signInWithCredential(any(GoogleAuthCredential.class)); verify(FakeAuthResult.INSTANCE.getUser()).linkWithCredential(facebookAuthCredential); InOrder inOrder = inOrder(mResponseObserver); inOrder.verify(mResponseObserver) .onChanged(argThat(ResourceMatchers.<IdpResponse>isLoading())); inOrder.verify(mResponseObserver) .onChanged(argThat(ResourceMatchers.<IdpResponse>isSuccess())); }
Example 16
Source File: LinkingSocialProviderResponseHandlerTest.java From FirebaseUI-Android with Apache License 2.0 | 4 votes |
@Test public void testSignIn_anonymousUpgradeEnabledWithDifferentIdp_expectMergeFailure() { mHandler.getOperation().observeForever(mResponseObserver); setupAnonymousUpgrade(); // We're going to fake a sign in with facebook, where the email belongs // to an existing account with a Google provider. // We need to link Facebook to this account, and then a merge failure should occur // so that the developer can handle it. // Before we can link, they need to sign in with Google to prove they own the account. // Fake social response from Google IdpResponse response = new IdpResponse.Builder(new User.Builder( GoogleAuthProvider.PROVIDER_ID, TestConstants.EMAIL).build()) .setToken(TestConstants.TOKEN) .build(); // Set facebook credential AuthCredential facebookAuthCredential = FacebookAuthProvider.getCredential(TestConstants.TOKEN); mHandler.setRequestedSignInCredentialForEmail(facebookAuthCredential, TestConstants.EMAIL); when(mScratchMockAuth.signInWithCredential(any(GoogleAuthCredential.class))) .thenReturn(AutoCompleteTask.forSuccess(FakeAuthResult.INSTANCE)); // Mock linking with Facebook to always work when(FakeAuthResult.INSTANCE.getUser().linkWithCredential(facebookAuthCredential)) .thenReturn(new AutoContinueTask<>(FakeAuthResult.INSTANCE, FakeAuthResult.INSTANCE, true, null)); mHandler.startSignIn(response); verify(mScratchMockAuth).signInWithCredential(any(GoogleAuthCredential.class)); verify(FakeAuthResult.INSTANCE.getUser()).linkWithCredential(facebookAuthCredential); InOrder inOrder = inOrder(mResponseObserver); inOrder.verify(mResponseObserver) .onChanged(argThat(ResourceMatchers.<IdpResponse>isLoading())); ArgumentCaptor<Resource<IdpResponse>> resolveCaptor = ArgumentCaptor.forClass(Resource.class); inOrder.verify(mResponseObserver).onChanged(resolveCaptor.capture()); // Merge failure should occur after successful linking FirebaseAuthAnonymousUpgradeException e = (FirebaseAuthAnonymousUpgradeException) resolveCaptor.getValue().getException(); AuthCredential credential = ProviderUtils.getAuthCredential(response); GoogleAuthCredential responseCredential = (GoogleAuthCredential) e.getResponse().getCredentialForLinking(); assertThat(responseCredential.getProvider()).isEqualTo(credential.getProvider()); assertThat(responseCredential.getSignInMethod()).isEqualTo(credential.getSignInMethod()); }
Example 17
Source File: FacebookProviderHandler.java From capacitor-firebase-auth with MIT License | 4 votes |
private void handleFacebookAccessToken(AccessToken token) { AuthCredential credential = FacebookAuthProvider.getCredential(token.getToken()); this.plugin.handleAuthCredentials(credential); }
Example 18
Source File: WelcomeBackPasswordHandlerTest.java From FirebaseUI-Android with Apache License 2.0 | 4 votes |
@Test public void testSignIn_linksIdpCredential() { mHandler.getOperation().observeForever(mResponseObserver); // Fake social response from Facebook User user = new User.Builder(FacebookAuthProvider.PROVIDER_ID, TestConstants.EMAIL) .build(); IdpResponse response = new IdpResponse.Builder(user) .setToken(TestConstants.TOKEN) .setSecret(TestConstants.SECRET) .build(); AuthCredential credential = FacebookAuthProvider.getCredential(TestConstants.TOKEN); // Mock sign in to always succeed when(mMockAuth.signInWithEmailAndPassword(TestConstants.EMAIL, TestConstants.PASSWORD)) .thenReturn(AutoCompleteTask.forSuccess(FakeAuthResult.INSTANCE)); // Mock linking to always succeed when(FakeAuthResult.INSTANCE.getUser().linkWithCredential(credential)) .thenReturn(new AutoContinueTask<>(FakeAuthResult.INSTANCE, FakeAuthResult.INSTANCE, true, null)); // Mock smartlock save to always succeed when(mMockCredentials.save(any(Credential.class))) .thenReturn(AutoCompleteTask.<Void>forSuccess(null)); // Kick off the sign in flow mHandler.startSignIn(TestConstants.EMAIL, TestConstants.PASSWORD, response, credential); // Verify that we get a loading event verify(mResponseObserver).onChanged(argThat(ResourceMatchers.<IdpResponse>isLoading())); // Verify that sign in is called with the right arguments verify(mMockAuth).signInWithEmailAndPassword( TestConstants.EMAIL, TestConstants.PASSWORD); // Verify that account linking is attempted verify(FakeAuthResult.INSTANCE.getUser()).linkWithCredential(credential); // Verify that we get a success event verify(mResponseObserver).onChanged(argThat(ResourceMatchers.<IdpResponse>isSuccess())); }
Example 19
Source File: WelcomeBackPasswordHandlerTest.java From FirebaseUI-Android with Apache License 2.0 | 4 votes |
@Test public void testSignIn_anonymousUserUpgradeEnabledWithSocialFlow_expectSafeLinksIdpCredentialAndMergeFailure() { setupAnonymousUpgrade(); mHandler.getOperation().observeForever(mResponseObserver); // Fake social response from Facebook User user = new User.Builder(FacebookAuthProvider.PROVIDER_ID, TestConstants.EMAIL) .build(); IdpResponse response = new IdpResponse.Builder(user) .setToken(TestConstants.TOKEN) .setSecret(TestConstants.SECRET) .build(); AuthCredential credential = FacebookAuthProvider.getCredential(TestConstants.TOKEN); // Need to control FirebaseAuth's return values AuthOperationManager authOperationManager = AuthOperationManager.getInstance(); authOperationManager.mScratchAuth = mScratchMockAuth; when(mScratchMockAuth.signInWithCredential(any(AuthCredential.class))) .thenReturn(AutoCompleteTask.forSuccess(FakeAuthResult.INSTANCE)); // Mock linking with Facebook to always work when(FakeAuthResult.INSTANCE.getUser().linkWithCredential(credential)) .thenReturn(new AutoContinueTask<>(FakeAuthResult.INSTANCE, FakeAuthResult.INSTANCE, true, null)); // Kick off the sign in flow mHandler.startSignIn(TestConstants.EMAIL, TestConstants.PASSWORD, response, credential); // Verify that signInWithCredential was called ArgumentCaptor<EmailAuthCredential> credentialCaptor = ArgumentCaptor.forClass(EmailAuthCredential.class); verify(mScratchMockAuth).signInWithCredential(credentialCaptor.capture()); EmailAuthCredential capturedCredential = credentialCaptor.getValue(); // TODO: EmailAuthCredential no longer exposes .getEmail() or .getPassword() // assertThat(capturedCredential.getEmail()).isEqualTo(TestConstants.EMAIL); // assertThat(capturedCredential.getPassword()).isEqualTo(TestConstants.PASSWORD); // Verify that account linking is attempted verify(FakeAuthResult.INSTANCE.getUser()).linkWithCredential(credential); verifyMergeFailure(); }