private async void cmdOk_Clicked(object sender, EventArgs e)
 {
     try
     {
         gridProgress.IsVisible = true;
         await Task.Run(async() =>
         {
             await SessionSingleton.LoginResourceOwner(txtEmail.Text, txtPassword.Text);
             IsCancelled = false;
             Device.BeginInvokeOnMainThread(() =>
             {
                 ClosePage();
             });
         });
     }
     catch (Exception ex)
     {
         SessionSingleton.EndSession();
         await App.Current.MainPage.DisplayAlert("Error", ex.Message, "OK");
     }
     finally
     {
         gridProgress.IsVisible = false;
     }
 }
Exemple #2
0
        public static async Task LoginResourceOwner(string username, string userpassword)
        {
            DiscoveryClient discoClient = new DiscoveryClient(ApiServerURL);

            discoClient.Policy.RequireHttps = false;
            DiscoveryResponse disco = await discoClient.GetAsync();

            if (disco.IsError)
            {
                throw new Exception(disco.Error);
            }

            TokenClient   client = new TokenClient(disco.TokenEndpoint, ClientName, ClientSecret);
            TokenResponse result = await client.RequestResourceOwnerPasswordAsync(username, userpassword, string.Join(" ", ClientScopes));

            if (result.IsError)
            {
                throw new Exception("Could not log in, username or password is incorrect, or you have not yet confirmed your email.");
            }

            StringBuilder sb = new StringBuilder(128);

            sb.AppendLine($"refresh token: {result.RefreshToken}");
            sb.AppendLine($"access token: {result.AccessToken}");
            System.Diagnostics.Debug.WriteLine(sb.ToString());

            SessionSingleton.SetTokens(result.AccessToken, result.RefreshToken);
        }
Exemple #3
0
        private static async Task LoadAccountEx()
        {
            Proxies.DCEMVDemoServerClient client = SessionSingleton.GenDCEMVServerApiClient();
            using (SessionSingleton.HttpClient)
            {
                Proxies.Account accountJson = await client.AccountGetAsync();

                Account account = Account.FromJsonString(accountJson.ToJson());
                SessionSingleton.Account = account;
            }
        }
Exemple #4
0
        public static async Task RequestRefreshToken()
        {
            DiscoveryClient   discoClient = new DiscoveryClient(ApiServerURL);
            DiscoveryResponse disco       = await discoClient.GetAsync();

            if (disco.IsError)
            {
                throw new Exception(disco.Error);
            }

            TokenClient   client = new TokenClient(disco.TokenEndpoint, ClientName, ClientSecret);
            TokenResponse result = await client.RequestRefreshTokenAsync(SessionSingleton.RefreshToken);

            if (result.IsError)
            {
                throw new Exception("Could not refresh token, try logoff and login again.");
            }
            SessionSingleton.SetTokens(result.AccessToken, result.RefreshToken);
        }