Пример #1
0
 private void GetTokenForMYOB(Credentials crendetials)
 {
     try
     {
         _configurationCloud            = new ApiConfiguration(crendetials.ConsumerKey, crendetials.ConsumerSecret, "http://desktop");
         _oAuthKeyService               = new MYOBOAuthKeyService();
         _oAuthKeyService.OAuthResponse = null;
         if (_oAuthKeyService.OAuthResponse == null)
         {
             var    oauthService = new OAuthService(_configurationCloud);
             string _accessCode  = OAuthLogin.GetAuthorizationCode(_configurationCloud);
             _oAuthKeyService.OAuthResponse =
                 oauthService.GetTokens(_accessCode);
             var frmLogin = new CompanyFileLogin();
             frmLogin.ShowDialog(this);
             if (frmLogin.Username.Length > 0)
             {
                 AccountingIntegrationConfigManager.Instance.SaveCompanyFileCredentials(frmLogin.Username, frmLogin.Password);
             }
         }
     }
     catch (Exception ex)
     {
         MessageBox.Show(ex.Message);
     }
 }
Пример #2
0
        public IActionResult AuthorizationToAccess(string email, string password)
        {
            var oauthLogin = new OAuthLogin();

            oauthLogin.Email    = email;
            oauthLogin.Password = password;

            return(PartialView(oauthLogin));
        }
Пример #3
0
        public IActionResult LoginGooglePassword(string email)
        {
            var oauthLogin = new OAuthLogin();

            oauthLogin.Email    = email;
            oauthLogin.Password = string.Empty;

            return(PartialView(oauthLogin));
        }
Пример #4
0
        public static void SaveCredentials(OAuthLogin oauthLogin, string baseUrl)
        {
            _client = new RestClient(baseUrl);
            var apiRequest = new RestRequest(Method.POST);

            apiRequest.Resource      = "/CrendentialsApi/SaveCredentials";
            apiRequest.RequestFormat = DataFormat.Json;
            apiRequest.AddBody(oauthLogin);
            var response = _client.Execute(apiRequest);
        }
Пример #5
0
 public void SaveLoginCredentials(OAuthLogin oauthLogin)
 {
     try
     {
         _context.OAuthLogin.Add(oauthLogin);
         _context.SaveChanges();
     }
     catch (Exception x)
     {
         throw new Exception(x.Message);
     }
 }
Пример #6
0
        public IActionResult SaveGoogleAccount(OAuthLogin oauthLogin)
        {
            var record = LoginAPI.CheckUserExists(oauthLogin.Email, _clientBaseAddress.BaseURLApi);

            if (record == null)
            {
                var response = OAuthAPI.GenerateToken(_clientBaseAddress.BaseURLApi);
                oauthLogin.Token = response.access_token;
                LoginAPI.SaveCredentials(oauthLogin, _clientBaseAddress.BaseURLApi);
            }

            return(RedirectToAction("Index", "AdAccounts"));
        }
Пример #7
0
        private void TryGetTokens()
        {
            _oAuthKeyService = new OAuthKeyService();
            if (_oAuthKeyService.OAuthResponse != null)
            {
                return;
            }
            var oauthService = new OAuthService(_configurationCloud);
            var code         = OAuthLogin.GetAuthorizationCode(_configurationCloud);
            var tokens       = oauthService.GetTokens(code);

            _oAuthKeyService.OAuthResponse = tokens;
        }
Пример #8
0
 public void TryLogin()
 {
     this.contentCard.Children.Clear();
     txtStatus.Foreground = Brushes.Red;
     txtStatus.Text       = "Status: Logged-Out";
     loginForm            = new OAuthLogin(new OAuthRequest()
     {
         OAuthService = new Uri(PushConstants.WebServices.OAuthLogin),
         ClientID     = PushConstants.Configs.ClientID,
         RedirectURL  = PushConstants.Configs.RedirectURL
     });
     loginForm.OnLoginEnded += Login_OnLoginEnded;
     this.contentCard.Children.Add(loginForm);
 }
Пример #9
0
        public async Task <IActionResult> GetCredential(string email)
        {
            var result = new OAuthLogin();

            try
            {
                result = _repository.GetCredentialByEmail(email);
            }
            catch (Exception x)
            {
                return(BadRequest(x.Message));
            }
            return(Ok(result));
        }
Пример #10
0
        private t.Task <OAuthTokens> GetOAuthTokens()
        {
            var tcs = new t.TaskCompletionSource <OAuthTokens>();

            t.Task.Run(
                async() =>
            {
                var oauthService = new OAuthService(_configurationCloud);
                var code         = OAuthLogin.GetAuthorizationCode(_configurationCloud);
                var response     = await oauthService.GetTokensAsync(code);
                tcs.SetResult(response);
            });
            return(tcs.Task);
        }
Пример #11
0
        public static OAuthLogin CheckUserExists(string email, string baseUrl)
        {
            var result = new OAuthLogin();

            try
            {
                _client = new RestClient(baseUrl);
                var apiRequest = new RestRequest(Method.GET);
                apiRequest.Resource = "/CrendentialsApi/GetCredential";
                apiRequest.AddParameter("email", email);
                var response = _client.Execute(apiRequest);
                result = JsonConvert.DeserializeObject <OAuthLogin>(response.Content);

                return(result);
            }
            catch (Exception x)
            {
                throw new Exception(x.Message);
            }
        }
Пример #12
0
        private async Task LoginUser()
        {
            IsVisibleButton    = false;
            IsVisibleIndicator = true;
            IsRunningIndicator = true;

            try
            {
                //Authenticate against ADFS and NW Gateway
                OAuthLogin oauthlogin = new OAuthLogin();
                LoginModel.UserName = LoginModel.UserName + "@jkintranet.com".ToLower();
                string access_token = await oauthlogin.LoginUserAsync(LoginModel);

                if (!string.IsNullOrEmpty(access_token) && access_token.StartsWith("SUCCESS", StringComparison.CurrentCulture))
                {
                    await OnSignedIn();

                    Application.Current.MainPage = new MasterDetailView();
                    LoginModel = new UserModel();
                }
                else
                {
                    await Application.Current.MainPage.DisplayAlert("Authorization Failed!", $"{access_token}", "OK");

                    LoginModel = new UserModel();
                }

                IsVisibleButton    = true;
                IsVisibleIndicator = false;
                IsRunningIndicator = false;
            }
            catch (Exception)
            {
                IsVisibleButton    = true;
                IsVisibleIndicator = false;
                IsRunningIndicator = false;

                LoginModel = new UserModel();
            }
        }
Пример #13
0
        /// <summary>
        /// Event that is called when the form loads
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        /// <remarks></remarks>
        private void CompanyFilesLoad(object sender, EventArgs e)
        {
            try
            {
                ShowSpinner();

                //If developer key  enable (see above) and set useCVloud to true the following section manages OAuth token and accessing cloud service
                if (UseCloud)
                {
                    _configurationCloud = new ApiConfiguration(DeveloperKey, DeveloperSecret, "http://desktop");
                    _oAuthKeyService    = new OAuthKeyService();

                    //Get tokens if not stored
                    if (_oAuthKeyService.OAuthResponse == null)
                    {
                        var oauthService = new OAuthService(_configurationCloud);
                        _oAuthKeyService.OAuthResponse =
                            oauthService.GetTokens(OAuthLogin.GetAuthorizationCode(_configurationCloud));
                    }

                    // Load all files from cloud and local simultaneously
                    var cfsCloud = new CompanyFileService(_configurationCloud, null, _oAuthKeyService);
                    cfsCloud.GetRange(OnComplete, OnError);
                }

                _configurationLocal = new ApiConfiguration(LocalApiUrl);
                var cfsLocal = new CompanyFileService(_configurationLocal);
                cfsLocal.GetRange(OnComplete, OnError);

                //' The following two lines can be called to run synchronously rather than async
                //_companyFiles = cfs.GetRange()
                //dgvCompanyFiles.DataSource = _companyFiles
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }
Пример #14
0
 public async Task <IActionResult> SaveCredentials([FromBody] OAuthLogin oauthLogin)
 {
     _repository.SaveLoginCredentials(oauthLogin);
     return(Ok());
 }