Search in sources :

Example 1 with Credential

use of com.google.android.gms.auth.api.credentials.Credential in project FirebaseUI-Android by firebase.

the class SignInDelegate method onActivityResult.

@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
    super.onActivityResult(requestCode, resultCode, data);
    switch(requestCode) {
        case RC_CREDENTIALS_READ:
            if (resultCode == ResultCodes.OK) {
                // credential selected from SmartLock, log in with that credential
                Credential credential = data.getParcelableExtra(Credential.EXTRA_KEY);
                handleCredential(credential);
            } else {
                // Smart lock selector cancelled, go to the AuthMethodPicker screen
                startAuthMethodChoice();
            }
            break;
        case RC_IDP_SIGNIN:
        case RC_AUTH_METHOD_PICKER:
        case RC_EMAIL_FLOW:
            finish(resultCode, data);
            break;
        default:
            IdpSignInContainer signInContainer = IdpSignInContainer.getInstance(getActivity());
            if (signInContainer != null) {
                signInContainer.onActivityResult(requestCode, resultCode, data);
            }
    }
}
Also used : Credential(com.google.android.gms.auth.api.credentials.Credential)

Example 2 with Credential

use of com.google.android.gms.auth.api.credentials.Credential in project FirebaseUI-Android by firebase.

the class SmartLockBase method credentialsFromFirebaseUser.

/**
     * Make a list of {@link Credential} from a FirebaseUser. Useful for deleting Credentials,
     * not for saving since we don't have access to the password.
     */
public static List<Credential> credentialsFromFirebaseUser(@NonNull FirebaseUser user) {
    if (TextUtils.isEmpty(user.getEmail())) {
        Log.w(TAG, "Can't get credentials from user with no email: " + user);
        return Collections.emptyList();
    }
    List<Credential> credentials = new ArrayList<>();
    for (UserInfo userInfo : user.getProviderData()) {
        // Get provider ID from Firebase Auth
        String providerId = userInfo.getProviderId();
        // Convert to Credentials API account type
        String accountType = providerIdToAccountType(providerId);
        // Build and add credential
        Credential.Builder builder = new Credential.Builder(user.getEmail()).setAccountType(accountType);
        // to make deletion succeed.
        if (accountType == null) {
            builder.setPassword("some_password");
        }
        credentials.add(builder.build());
    }
    return credentials;
}
Also used : Credential(com.google.android.gms.auth.api.credentials.Credential) ArrayList(java.util.ArrayList) UserInfo(com.google.firebase.auth.UserInfo)

Example 3 with Credential

use of com.google.android.gms.auth.api.credentials.Credential in project WordPress-Android by wordpress-mobile.

the class SmartLockHelper method saveCredentialsInSmartLock.

public void saveCredentialsInSmartLock(@NonNull final String username, @NonNull final String password, @NonNull final String displayName, @NonNull final Uri profilePicture) {
    Activity activity = getActivityAndCheckAvailability();
    if (activity == null || mCredentialsClient == null || !mCredentialsClient.isConnected()) {
        return;
    }
    Credential credential = new Credential.Builder(username).setPassword(password).setName(displayName).setProfilePictureUri(profilePicture).build();
    Auth.CredentialsApi.save(mCredentialsClient, credential).setResultCallback(new ResultCallback<Status>() {

        @Override
        public void onResult(@NonNull Status status) {
            if (!status.isSuccess() && status.hasResolution()) {
                try {
                    Activity activity = getActivityAndCheckAvailability();
                    if (activity == null) {
                        return;
                    }
                    // This prompt the user to resolve the save request
                    status.startResolutionForResult(activity, SignInActivity.SMART_LOCK_SAVE);
                } catch (IntentSender.SendIntentException e) {
                // Could not resolve the request
                }
            }
        }
    });
}
Also used : Status(com.google.android.gms.common.api.Status) Credential(com.google.android.gms.auth.api.credentials.Credential) FragmentActivity(android.support.v4.app.FragmentActivity) Activity(android.app.Activity)

Example 4 with Credential

use of com.google.android.gms.auth.api.credentials.Credential in project WordPress-Android by wordpress-mobile.

the class SmartLockHelper method deleteCredentialsInSmartLock.

public void deleteCredentialsInSmartLock(@NonNull final String username, @NonNull final String password) {
    Activity activity = getActivityAndCheckAvailability();
    if (activity == null || mCredentialsClient == null || !mCredentialsClient.isConnected()) {
        return;
    }
    Credential credential = new Credential.Builder(username).setPassword(password).build();
    Auth.CredentialsApi.delete(mCredentialsClient, credential).setResultCallback(new ResultCallback<Status>() {

        @Override
        public void onResult(@NonNull Status status) {
            AppLog.i(T.NUX, status.isSuccess() ? "SmartLock: credentials deleted for username: " + username : "SmartLock: Credentials not deleted for username: " + username);
        }
    });
}
Also used : Status(com.google.android.gms.common.api.Status) Credential(com.google.android.gms.auth.api.credentials.Credential) FragmentActivity(android.support.v4.app.FragmentActivity) Activity(android.app.Activity)

Example 5 with Credential

use of com.google.android.gms.auth.api.credentials.Credential in project WordPress-Android by wordpress-mobile.

the class SmartLockHelper method smartLockAutoFill.

public void smartLockAutoFill(@NonNull final Callback callback) {
    Activity activity = getActivityAndCheckAvailability();
    if (activity == null || mCredentialsClient == null || !mCredentialsClient.isConnected()) {
        return;
    }
    CredentialRequest credentialRequest = new CredentialRequest.Builder().setPasswordLoginSupported(true).build();
    Auth.CredentialsApi.request(mCredentialsClient, credentialRequest).setResultCallback(new ResultCallback<CredentialRequestResult>() {

        @Override
        public void onResult(@NonNull CredentialRequestResult result) {
            Status status = result.getStatus();
            if (status.isSuccess()) {
                Credential credential = result.getCredential();
                callback.onCredentialRetrieved(credential);
            } else {
                if (status.getStatusCode() == CommonStatusCodes.RESOLUTION_REQUIRED) {
                    try {
                        Activity activity = getActivityAndCheckAvailability();
                        if (activity == null) {
                            return;
                        }
                        // Prompt the user to choose a saved credential
                        status.startResolutionForResult(activity, SignInActivity.SMART_LOCK_READ);
                    } catch (IntentSender.SendIntentException e) {
                        AppLog.d(T.NUX, "SmartLock: Failed to send resolution for credential request");
                    }
                } else {
                    // The user must create an account or log in manually.
                    AppLog.d(T.NUX, "SmartLock: Unsuccessful credential request.");
                }
            }
        }
    });
}
Also used : Status(com.google.android.gms.common.api.Status) CredentialRequest(com.google.android.gms.auth.api.credentials.CredentialRequest) Credential(com.google.android.gms.auth.api.credentials.Credential) FragmentActivity(android.support.v4.app.FragmentActivity) Activity(android.app.Activity) CredentialRequestResult(com.google.android.gms.auth.api.credentials.CredentialRequestResult)

Aggregations

Credential (com.google.android.gms.auth.api.credentials.Credential)7 Activity (android.app.Activity)3 FragmentActivity (android.support.v4.app.FragmentActivity)3 Status (com.google.android.gms.common.api.Status)3 ArrayList (java.util.ArrayList)2 CredentialRequest (com.google.android.gms.auth.api.credentials.CredentialRequest)1 CredentialRequestResult (com.google.android.gms.auth.api.credentials.CredentialRequestResult)1 Task (com.google.android.gms.tasks.Task)1 FirebaseUser (com.google.firebase.auth.FirebaseUser)1 UserInfo (com.google.firebase.auth.UserInfo)1 Callback (org.wordpress.android.ui.accounts.SmartLockHelper.Callback)1