Пример #1
0
        public void LogOut()
        {
            var acct = SecureStorageStore.FindAccountsForServiceAsync(Configuration.GoogleServiceName)?.Result?.FirstOrDefault();

            SecureStorageStore.SaveAsync(null, Configuration.GoogleServiceName).Wait();
            _loggedIn = null;
            OnLoggedOut?.Invoke(this, new EventArgs());
        }
Пример #2
0
 public void LogIn(Account user)
 {
     _loggedIn = GetModelFromAccount(user);
     SecureStorageStore.SaveAsync(user, Configuration.GoogleServiceName).Wait();
     OnLoggedIn?.Invoke(this, new LoggedInEventArgs()
     {
         Account = _loggedIn
     });
 }
Пример #3
0
        public AccountModel GetLoggedInAccount()
        {
            if (_loggedIn != null)
            {
                return(_loggedIn);
            }

            var token = SecureStorageStore.FindAccountsForServiceAsync(Configuration.GoogleServiceName)?.Result?.FirstOrDefault();
            var model = GetModelFromAccount(token);

            _loggedIn = model;
            return(model);
        }
Пример #4
0
        private void RefreshAccessToken(Account currentAccount)
        {
            var http    = new HttpClient();
            var content = new
            {
                client_id     = Configuration.ClientId,
                refresh_token = currentAccount.Properties["refresh_token"],
                grant_type    = "refresh_token"
            };
            var response = http.PostAsync($"https://www.googleapis.com/oauth2/v4/token", new StringContent(JsonConvert.SerializeObject(content))).Result;
            var dict     = JsonConvert.DeserializeObject <Dictionary <string, string> >(response.Content.ReadAsStringAsync().Result);

            currentAccount.Properties["access_token"] = dict["access_token"];
            SecureStorageStore.SaveAsync(currentAccount, Configuration.GoogleServiceName).Wait();
        }