Welcome to mirror list, hosted at ThFree Co, Russian Federation.

GoogleTokenHandler.java « auth « maps « mapswithme « com « src « android - github.com/mapsme/omim.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: c7b391c06bab96c74f2578fb9f0ca5ab94531ab1 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
package com.mapswithme.maps.auth;

import android.content.Intent;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.text.TextUtils;

import com.google.android.gms.auth.api.signin.GoogleSignIn;
import com.google.android.gms.auth.api.signin.GoogleSignInAccount;
import com.google.android.gms.common.api.ApiException;
import com.google.android.gms.tasks.Task;
import com.mapswithme.maps.Framework;
import com.mapswithme.util.log.Logger;
import com.mapswithme.util.log.LoggerFactory;

class GoogleTokenHandler implements TokenHandler
{
  @Nullable
  private String mToken;

  @Override
  public boolean checkToken(int requestCode, @NonNull Intent data)
  {
    if (requestCode != Constants.REQ_CODE_GOOGLE_SIGN_IN)
      return false;

    Task<GoogleSignInAccount> task = GoogleSignIn.getSignedInAccountFromIntent(data);
    try
    {
      GoogleSignInAccount account = task.getResult(ApiException.class);
      if (account != null)
        mToken = account.getIdToken();
      return !TextUtils.isEmpty(mToken);
    }
    catch (ApiException e)
    {
      // The ApiException status code indicates the detailed failure reason.
      // Please refer to the GoogleSignInStatusCodes class reference for more information.
      Logger logger = LoggerFactory.INSTANCE.getLogger(LoggerFactory.Type.MISC);
      logger.w(GoogleTokenHandler.class.getSimpleName(),
               "signInResult:failed code=" + e.getStatusCode());
    }
    return false;
  }

  @Nullable
  @Override
  public String getToken()
  {
    return mToken;
  }

  @Override
  public int getType()
  {
    return Framework.SOCIAL_TOKEN_GOOGLE;
  }
}