public UberAuthenticationViewModel(IAggregateService aggregateService, IUberService uberService) : base(ApplicationPage.UberAuthentication, aggregateService) { this.uberService = uberService; this.credentials = new UberOAuthCredentials("-PNH94q8gmuRmb5ZvnEVYO0P-ysj_8-_", "1h-6l1ZVRciE0suS9E5LRjbXvoXg-Q6d3lZfaFxX", UberOAuthGrantType.authorization_code); }
public UberAuthentication() { InitializeComponent(); this.credentials = new UberOAuthCredentials("-PNH94q8gmuRmb5ZvnEVYO0P-ysj_8-_", "1h-6l1ZVRciE0suS9E5LRjbXvoXg-Q6d3lZfaFxX", UberOAuthGrantType.authorization_code); this.LoginControl.Navigate(this.credentials.GetLoginUri()); }
public async Task<UberAuthenticationDetails> Authenticate(CancellationToken ct, UberOAuthCredentials credentials) { UberOAuthResponse response = await uberApi.Authenticate(ct, credentials); if (response == null) return null; return new UberAuthenticationDetails(response.access_token, response.token_type, response.expires_in, response.refresh_token, response.scope); }
internal async Task<UberOAuthResponse> Authenticate(CancellationToken ct, UberOAuthCredentials credentials) { using (HttpClient httpClient = new HttpClient()) { httpClient.Timeout = new TimeSpan(0, 1, 0); // 1 minute timeout HttpResponseMessage response = new HttpResponseMessage(); try { response = await httpClient.PostAsync(credentials.AuthenticationUrl, credentials.GetPostContent(), ct); if (response.IsSuccessStatusCode) { try { var data = response.Content.ReadAsStringAsync().Result; return JsonConvert.DeserializeObject<UberOAuthResponse>(data); } catch (Exception e) { Debug.WriteLine(e.Message); return null; } } else { string errorResponseString = response.Content.ReadAsStringAsync().Result; Debug.WriteLine(errorResponseString); return null; } } catch (TaskCanceledException) { Debug.WriteLine("TaskCanceledException"); return null; } catch (Exception e) { Debug.WriteLine(e.Message); return null; } } }