public Task StoreAsync(Credentials credentials)
        {
            NSUserDefaults.StandardUserDefaults.SetString(credentials.Account, "account");
            NSUserDefaults.StandardUserDefaults.SetString(credentials.Token, "token");

            return Task.FromResult(true);
        }
        public Task StoreAsync(Credentials credentials)
        {
            using (var preferences = PreferenceManager.GetDefaultSharedPreferences(Application.Context))
            using (var editor = preferences.Edit())
            {
                editor.PutString("account", credentials.Account);
                editor.PutString("token", credentials.Token);

                editor.Commit();
            }

            return Task.FromResult(true);
        }
Esempio n. 3
0
        public async void Login()
        {
            var entered = new Credentials(Account, Token);
            var authenticated = await authentication.AuthenticateCredentialsAsync(entered);

            if (!authenticated)
            {
                Message = "Account / Token is incorrect";
            }
            else
            {
                await credentials.StoreAsync(entered);

                navigation.ToProjects();
            }
        }
        public async Task<bool> AuthenticateCredentialsAsync(Credentials credentials)
        {
            var relativeUri = new Uri("/DefaultCollection/_apis/projects", UriKind.Relative);

            using (var client = new HttpClient())
            {
                client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
                client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Basic", $"username:{credentials.Token}".ToBase64());

                var baseUri = new Uri($"https://{credentials.Account}.visualstudio.com", UriKind.Absolute);

                var request = new HttpRequestMessage(HttpMethod.Get, new Uri(baseUri, relativeUri));

                using (var response = await client.SendAsync(request))
                {
                    return response.StatusCode == HttpStatusCode.OK;
                }
            }
        }
 public Task StoreAsync(Credentials credentials)
 {
     throw new NotSupportedException();
 }