Search in sources :

Example 31 with GoogleSignInAccount

use of com.google.android.gms.auth.api.signin.GoogleSignInAccount in project Precisely by Pankaj-Baranwal.

the class SignUp method handleSignInResult.

private void handleSignInResult(Task<GoogleSignInAccount> completedTask) {
    try {
        GoogleSignInAccount account = completedTask.getResult(ApiException.class);
        Constants.user_name = account.getDisplayName();
        submitData(account.getId());
    } catch (ApiException e) {
        Toast.makeText(this, "Google behaving weirdly!", Toast.LENGTH_SHORT).show();
    }
}
Also used : GoogleSignInAccount(com.google.android.gms.auth.api.signin.GoogleSignInAccount) ApiException(com.google.android.gms.common.api.ApiException)

Example 32 with GoogleSignInAccount

use of com.google.android.gms.auth.api.signin.GoogleSignInAccount in project CDT by IUS-CS.

the class HostActivity method onResume.

@Override
protected void onResume() {
    super.onResume();
    // check if user is already signed in
    // launches the signInActivity if user is not signed in
    GoogleSignInAccount account = GoogleSignIn.getLastSignedInAccount(this);
    if (account == null) {
        startActivity(new Intent(HostActivity.this, SignInActivity.class));
    }
}
Also used : GoogleSignInAccount(com.google.android.gms.auth.api.signin.GoogleSignInAccount) Intent(android.content.Intent)

Example 33 with GoogleSignInAccount

use of com.google.android.gms.auth.api.signin.GoogleSignInAccount in project AnyMemo by helloworld1.

the class GoogleAccountActivity method onActivityResult.

@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
    super.onActivityResult(requestCode, resultCode, data);
    // GoogleSignInApi.getSignInIntent(...);
    if (requestCode == RC_SIGN_IN) {
        GoogleSignInResult result = Auth.GoogleSignInApi.getSignInResultFromIntent(data);
        if (result == null) {
            activityComponents().errorUtil().showFatalError(getString(R.string.google_sign_in_empty_error_text), null);
            return;
        }
        if (!result.isSuccess()) {
            activityComponents().errorUtil().showFatalError(getString(R.string.google_sign_in_not_successful_error_text), null);
            return;
        }
        GoogleSignInAccount acct = result.getSignInAccount();
        if (acct == null) {
            activityComponents().errorUtil().showFatalError(getString(R.string.google_sign_in_account_empty_result), null);
            return;
        }
        // Get account information
        final String email = acct.getEmail();
        appComponents().executorService().submit(new Runnable() {

            @Override
            public void run() {
                try {
                    String token = GoogleAuthUtil.getToken(GoogleAccountActivity.this, email, AMEnv.GDRIVE_SCOPE);
                    onAuthenticated(token);
                } catch (IOException e) {
                    activityComponents().errorUtil().showFatalError("IO Error", e);
                } catch (UserRecoverableAuthException e) {
                    startActivityForResult(e.getIntent(), RC_AUTH_TOKEN);
                } catch (GoogleAuthException e) {
                    activityComponents().errorUtil().showFatalError("GoogleAuthException", e);
                }
            }
        });
    } else if (requestCode == RC_AUTH_TOKEN) {
        Bundle extra = data.getExtras();
        if (extra == null) {
            activityComponents().errorUtil().showFatalError("RC_AUTH_TOKEN does not have extra", null);
            return;
        }
        String token = extra.getString("authtoken");
        if (Strings.isNullOrEmpty(token)) {
            activityComponents().errorUtil().showFatalError("RC_AUTH_TOKEN does not have token", null);
            return;
        }
        onAuthenticated(token);
    }
}
Also used : GoogleSignInAccount(com.google.android.gms.auth.api.signin.GoogleSignInAccount) Bundle(android.os.Bundle) GoogleAuthException(com.google.android.gms.auth.GoogleAuthException) IOException(java.io.IOException) UserRecoverableAuthException(com.google.android.gms.auth.UserRecoverableAuthException) GoogleSignInResult(com.google.android.gms.auth.api.signin.GoogleSignInResult)

Example 34 with GoogleSignInAccount

use of com.google.android.gms.auth.api.signin.GoogleSignInAccount in project xabber-android by redsolution.

the class BaseLoginActivity method handleSignInResult.

private void handleSignInResult(GoogleSignInResult result) {
    if (result.isSuccess()) {
        GoogleSignInAccount acct = result.getSignInAccount();
        if (acct != null) {
            final String googleAuthCode = acct.getServerAuthCode();
            Application.getInstance().runInBackground(new Runnable() {

                @Override
                public void run() {
                    try {
                        GoogleTokenResponse tokenResponse = new GoogleAuthorizationCodeTokenRequest(new NetHttpTransport(), JacksonFactory.getDefaultInstance(), GOOGLE_TOKEN_SERVER, getString(R.string.SOCIAL_AUTH_GOOGLE_KEY), getString(R.string.SOCIAL_AUTH_GOOGLE_SECRET), googleAuthCode, "").execute();
                        final String token = tokenResponse.getAccessToken();
                        Application.getInstance().runOnUiThread(new Runnable() {

                            @Override
                            public void run() {
                                String credentials = gson.toJson(new AuthManager.AccessToken(token));
                                onSocialAuthSuccess(AuthManager.PROVIDER_GOOGLE, credentials);
                            }
                        });
                    } catch (IOException e) {
                        e.printStackTrace();
                    }
                }
            });
        }
    } else
        Toast.makeText(this, R.string.auth_google_error, Toast.LENGTH_LONG).show();
}
Also used : GoogleSignInAccount(com.google.android.gms.auth.api.signin.GoogleSignInAccount) AuthManager(com.xabber.android.data.xaccount.AuthManager) GoogleAuthorizationCodeTokenRequest(com.google.api.client.googleapis.auth.oauth2.GoogleAuthorizationCodeTokenRequest) NetHttpTransport(com.google.api.client.http.javanet.NetHttpTransport) GoogleTokenResponse(com.google.api.client.googleapis.auth.oauth2.GoogleTokenResponse) IOException(java.io.IOException)

Example 35 with GoogleSignInAccount

use of com.google.android.gms.auth.api.signin.GoogleSignInAccount in project boilerplate by koush.

the class AccountAuthHelper method getGoogleSigninForeground.

public static Promise<UserToken> getGoogleSigninForeground(final WindowChromeCompatActivity activity, String clientId) {
    GoogleSignInOptions gso = new GoogleSignInOptions.Builder(GoogleSignInOptions.DEFAULT_SIGN_IN).requestEmail().requestIdToken(clientId).requestId().build();
    GoogleSignInClient client = GoogleSignIn.getClient(activity, gso);
    Intent intent = client.getSignInIntent();
    return activity.startActivityForResult(intent).next(from -> {
        Task<GoogleSignInAccount> task = GoogleSignIn.getSignedInAccountFromIntent(from);
        return Promise.resolve(new UserToken(task.getResult(ApiException.class).getId(), task.getResult(ApiException.class).getEmail(), task.getResult(ApiException.class).getIdToken()));
    });
}
Also used : GoogleSignInAccount(com.google.android.gms.auth.api.signin.GoogleSignInAccount) GoogleSignInOptions(com.google.android.gms.auth.api.signin.GoogleSignInOptions) Intent(android.content.Intent) GoogleSignInClient(com.google.android.gms.auth.api.signin.GoogleSignInClient) ApiException(com.google.android.gms.common.api.ApiException)

Aggregations

GoogleSignInAccount (com.google.android.gms.auth.api.signin.GoogleSignInAccount)48 ApiException (com.google.android.gms.common.api.ApiException)15 GoogleSignInResult (com.google.android.gms.auth.api.signin.GoogleSignInResult)12 Intent (android.content.Intent)7 IOException (java.io.IOException)5 User (com.androidstudy.andelamedmanager.data.model.User)2 GoogleSignInOptions (com.google.android.gms.auth.api.signin.GoogleSignInOptions)2 Scope (com.google.android.gms.common.api.Scope)2 Request (okhttp3.Request)2 JSONException (org.json.JSONException)2 Context (android.content.Context)1 Uri (android.net.Uri)1 Bundle (android.os.Bundle)1 NonNull (androidx.annotation.NonNull)1 ServerStatusCode (cl.smartcities.isci.transportinspector.serverConnection.ServerStatusCode)1 Response (com.android.volley.Response)1 VolleyError (com.android.volley.VolleyError)1 IntentResultListener (com.codename1.impl.android.IntentResultListener)1 AccessToken (com.codename1.io.AccessToken)1 ConnectionRequest (com.codename1.io.ConnectionRequest)1