Exemplo n.º 1
0
        public bool Authorize(GoogleAccount account)
        {
            DictionaryDataStore dataStore = new DictionaryDataStore();

            if (account != null)
            {
                account.LoadDataStore(dataStore: ref dataStore);
            }

            try {
                UserCredential credential = GoogleWebAuthorizationBroker.AuthorizeAsync(
                    clientSecrets: GoogleSecrets.ToClientSecrets(Secrets),
                    scopes: GoogleScopes.ToStrings(Scopes),
                    user: "******",
                    taskCancellationToken: CancellationToken.None,
                    dataStore: dataStore
                    ).Result;
                Accounts.Add(GoogleAccount.SaveAccount(broker: this, credential: credential, dataStore: dataStore));
                return(true);
            } catch (TokenResponseException ex) {
                if (ex.Message.Contains("invalid_grant"))
                {
                    return(account.Reauthenticate());
                }
                else
                {
                    Log.Error(ex);
                }
                return(false);
            }
        }
Exemplo n.º 2
0
 public UserCredential Authorize(string googleUser)
 {
     return(GoogleWebAuthorizationBroker.AuthorizeAsync(
                GoogleSecrets.ToClientSecrets(Secrets),
                GoogleScopes.ToStrings(Scopes),
                googleUser, System.Threading.CancellationToken.None,
                new FileDataStore(AppName)
                ).Result);
 }