Ejemplo n.º 1
0
        public async Task <GoogleSession> LoginAsync()
        {
            if (string.IsNullOrEmpty(_clientId))
            {
                throw new NullReferenceException("You must register app at first!");
            }
            Session = await PromptOAuthDialog(_clientId, WebAuthenticationOptions.None);

            return(Session);
        }
Ejemplo n.º 2
0
        public async Task <GoogleSession> GetToken(string code)
        {
            var parameters = new Dictionary <string, string>
            {
                { "code", code },
                { "client_id", _clientId },
                { "client_secret", _clientSecret },
                { "redirect_uri", GooglePlusResources.RedirectUri },
                { "grant_type", "authorization_code" }
            };

            Session = await DoPostRequest <GoogleSession>(GooglePlusResources.GeneralOAuthUri + "/token", parameters);

            return(Session);
        }
 public bool IsLogged()
 {
     Proxy.RegisterApp(ClientId, ClientSecret);
     try
     {
         _session      = StorageService.GetValue <GoogleSession>(ACCOUNT_STORAGE_KEY);
         Proxy.Session = _session;
         return(true);
     }
     catch (KeyNotFoundException)
     {
         Log.Write("Google session isn't in cache");
     }
     return(false);
 }
Ejemplo n.º 4
0
        public async Task <GoogleSession> RefreshTokenAsync(GoogleSession session)
        {
            _refreshToken = session.RefreshToken;
            var parameters = new Dictionary <string, string>
            {
                { "client_id", _clientId },
                { "client_secret", _clientSecret },
                { "refresh_token", session.RefreshToken },
                { "grant_type", "refresh_token" }
            };

            Session = await DoPostRequest <GoogleSession>(GooglePlusResources.GeneralOAuthUri + "/token", parameters);

            Session.RefreshToken = _refreshToken;
            return(Session);
        }
 private async Task CheckSession()
 {
     if (DateTime.Now < _session.TokenExpireDateTime)
     {
         return;
     }
     try
     {
         _session = await Proxy.RefreshTokenAsync(_session);
     }
     catch (Exception ex)
     {
         Log.Write(string.Format("Refresh token Error: {0}", ex.Message));
         throw;
     }
 }
        public async Task <bool> LoginAsync()
        {
            if (IsLogged())
            {
                return(true);
            }
            try
            {
                _session = await Proxy.LoginAsync();

                StorageService.SetValue(ACCOUNT_STORAGE_KEY, _session);
            }
            catch (Exception ex)
            {
                Log.Write(string.Format("LoginAsync Error: {0}", ex.Message));
                throw;
            }
            return(true);
        }