Пример #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);
            }
        }
Пример #2
0
        public GoogleWebAuthBroker(GoogleScopes.ScopeGroup scopes, GoogleSecrets secrets)
        {
            Scopes  = scopes;
            Secrets = secrets;

            Core.Net.Networking.DisableCertificateValidation();
            AppName = Path.GetFileNameWithoutExtension(System.Reflection.Assembly.GetEntryAssembly().Location);
        }
Пример #3
0
 public UserCredential Authorize(string googleUser)
 {
     return(GoogleWebAuthorizationBroker.AuthorizeAsync(
                GoogleSecrets.ToClientSecrets(Secrets),
                GoogleScopes.ToStrings(Scopes),
                googleUser, System.Threading.CancellationToken.None,
                new FileDataStore(AppName)
                ).Result);
 }