Search in sources :

Example 6 with GoogleSignInAccount

use of com.google.android.gms.auth.api.signin.GoogleSignInAccount in project easy by MehdiBenmesa.

the class RestApiActivity method handleSignInResult.

private void handleSignInResult(GoogleSignInResult result) {
    Log.d(TAG, "handleSignInResult:" + result.isSuccess());
    if (result.isSuccess()) {
        // Get the account from the sign in result
        GoogleSignInAccount account = result.getSignInAccount();
        // Signed in successfully, show authenticated UI.
        mStatusTextView.setText(getString(R.string.signed_in_fmt, account.getDisplayName()));
        updateUI(true);
        // Store the account from the result
        mAccount = account.getAccount();
        // Asynchronously access the People API for the account
        getContacts();
    } else {
        // Clear the local account
        mAccount = null;
        // Signed out, show unauthenticated UI.
        updateUI(false);
    }
}
Also used : GoogleSignInAccount(com.google.android.gms.auth.api.signin.GoogleSignInAccount)

Example 7 with GoogleSignInAccount

use of com.google.android.gms.auth.api.signin.GoogleSignInAccount in project easy by MehdiBenmesa.

the class StartActivity method handleSignInResult.

// [END onActivityResult]
//1D:80:89:02:65:1A:38:03:60:08:D1:38:24:EA:CA:C0:F9:59:48:AC
// [START handleSignInResult]
private void handleSignInResult(GoogleSignInResult result) {
    Log.d(TAG, "handleSignInResult:" + result.isSuccess());
    if (result.isSuccess()) {
        // Signed in successfully, show authenticated UI.
        GoogleSignInAccount acct = result.getSignInAccount();
        updateUI(true);
        App.getInstance().setAccessToken(acct.getIdToken());
        App.getInstance().setEmail(acct.getEmail());
        if (acct.getEmail().substring(acct.getEmail().length() - 6, acct.getEmail().length()).equals("esi.dz")) {
            CustomRequest jsonReq = new CustomRequest(Request.Method.POST, APP_LOGIN, null, new Response.Listener<JSONObject>() {

                @Override
                public void onResponse(JSONObject response) {
                    try {
                        JSONObject user = response.getJSONObject("user");
                        Log.i(TAG, "Signed in as: " + user.getString("name"));
                        //JSONArray resp = responseBody.to;
                        if (user.getString("mail").equals(App.getInstance().getEmail())) {
                            startUserActivity(user);
                        }
                    } catch (JSONException e) {
                        e.printStackTrace();
                    }
                }
            }, new Response.ErrorListener() {

                @Override
                public void onErrorResponse(VolleyError error) {
                    hidepDialog();
                }
            }) {

                @Override
                protected Map<String, String> getParams() {
                    Map<String, String> params = new HashMap<String, String>();
                    params.put("email", App.getInstance().getEmail());
                    params.put("idToken", App.getInstance().getAccessToken());
                    return params;
                }
            };
            App.getInstance().addToRequestQueue(jsonReq);
        } else {
            String msg = "c'est pas un compte ESI ";
            Toast.makeText(this, msg, Toast.LENGTH_SHORT).show();
        }
    } else {
        // Signed out, show unauthenticated UI.
        updateUI(false);
    }
}
Also used : Response(com.android.volley.Response) VolleyError(com.android.volley.VolleyError) GoogleSignInAccount(com.google.android.gms.auth.api.signin.GoogleSignInAccount) JSONObject(org.json.JSONObject) HashMap(java.util.HashMap) JSONException(org.json.JSONException) CustomRequest(dz.easy.androidclient.Util.CustomRequest)

Example 8 with GoogleSignInAccount

use of com.google.android.gms.auth.api.signin.GoogleSignInAccount in project easy by MehdiBenmesa.

the class ServerAuthCodeActivity method onActivityResult.

@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
    super.onActivityResult(requestCode, resultCode, data);
    if (requestCode == RC_GET_AUTH_CODE) {
        GoogleSignInResult result = Auth.GoogleSignInApi.getSignInResultFromIntent(data);
        Log.d(TAG, "onActivityResult:GET_AUTH_CODE:success:" + result.getStatus().isSuccess());
        if (result.isSuccess()) {
            // [START get_auth_code]
            GoogleSignInAccount acct = result.getSignInAccount();
            String authCode = acct.getServerAuthCode();
            // Show signed-in UI.
            mAuthCodeTextView.setText(getString(R.string.auth_code_fmt, authCode));
            updateUI(true);
        // TODO(user): send code to server and exchange for access/refresh/ID tokens.
        // [END get_auth_code]
        } else {
            // Show signed-out UI.
            updateUI(false);
        }
    }
}
Also used : GoogleSignInAccount(com.google.android.gms.auth.api.signin.GoogleSignInAccount) GoogleSignInResult(com.google.android.gms.auth.api.signin.GoogleSignInResult)

Example 9 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() {
                                loginSocial(AuthManager.PROVIDER_GOOGLE, token);
                            }
                        });
                    } catch (IOException e) {
                        e.printStackTrace();
                    }
                }
            });
        }
    } else
        Toast.makeText(this, "google error", Toast.LENGTH_LONG).show();
}
Also used : GoogleSignInAccount(com.google.android.gms.auth.api.signin.GoogleSignInAccount) 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 10 with GoogleSignInAccount

use of com.google.android.gms.auth.api.signin.GoogleSignInAccount in project google-services by googlesamples.

the class SignInActivity method handleSignInResult.

// [END onActivityResult]
// [START handleSignInResult]
private void handleSignInResult(GoogleSignInResult result) {
    Log.d(TAG, "handleSignInResult:" + result.isSuccess());
    if (result.isSuccess()) {
        // Signed in successfully, show authenticated UI.
        GoogleSignInAccount acct = result.getSignInAccount();
        mStatusTextView.setText(getString(R.string.signed_in_fmt, acct.getDisplayName()));
        updateUI(true);
    } else {
        // Signed out, show unauthenticated UI.
        updateUI(false);
    }
}
Also used : GoogleSignInAccount(com.google.android.gms.auth.api.signin.GoogleSignInAccount)

Aggregations

GoogleSignInAccount (com.google.android.gms.auth.api.signin.GoogleSignInAccount)16 GoogleSignInResult (com.google.android.gms.auth.api.signin.GoogleSignInResult)5 IOException (java.io.IOException)2 JSONException (org.json.JSONException)2 Response (com.android.volley.Response)1 VolleyError (com.android.volley.VolleyError)1 ConnectionResult (com.google.android.gms.common.ConnectionResult)1 GoogleApiClient (com.google.android.gms.common.api.GoogleApiClient)1 GoogleAuthorizationCodeTokenRequest (com.google.api.client.googleapis.auth.oauth2.GoogleAuthorizationCodeTokenRequest)1 GoogleTokenResponse (com.google.api.client.googleapis.auth.oauth2.GoogleTokenResponse)1 NetHttpTransport (com.google.api.client.http.javanet.NetHttpTransport)1 CustomRequest (dz.easy.androidclient.Util.CustomRequest)1 HashMap (java.util.HashMap)1 Request (okhttp3.Request)1 JSONObject (org.json.JSONObject)1 User (org.michenux.drodrolib.security.User)1