public async Task LoginAsync(OAuthRequest oauthRequest) { var response = await traktService.LoginAsync(oauthRequest); var userSettings = await traktService.GetSettingsAsync(); var user = new User { Username = userSettings.User.Username, AccessToken = response.Access_Token, Refresh_Token = response.Refresh_Token }; await storageService.CreateOrUpdateUserAsync(user); }
public async Task <OAuthResponse> LoginAsync(OAuthRequest oauthRequest) { var request = new RestRequest("oauth/token", HttpMethod.Post). AddJsonBody(new { oauthRequest.code, oauthRequest.redirect_uri, oauthRequest.grant_type, client_id = Client, client_secret = Secret }); var response = await RestClient.Execute <OAuthResponse>(request); SetAuthenticator(response.Data); return(response.Data); }
public async Task<OAuthResponse> LoginAsync(OAuthRequest oauthRequest) { var request = new RestRequest("oauth/token", HttpMethod.Post). AddJsonBody(new { oauthRequest.code, oauthRequest.redirect_uri, oauthRequest.grant_type, client_id = Client, client_secret = Secret }); var response = await RestClient.Execute<OAuthResponse>(request); SetAuthenticator(response.Data); return response.Data; }
private async void Login() { var callbackUri = WebAuthenticationBroker.GetCurrentApplicationCallbackUri(); var uri = new Uri(string.Format("https://api.trakt.tv/oauth/authorize?response_type=code&client_id={0}&redirect_uri={1}", App.TRAKT_CLIENT_ID, callbackUri.AbsoluteUri)); var response = await WebAuthenticationBroker.AuthenticateAsync(WebAuthenticationOptions.None, uri, callbackUri); if (response.ResponseStatus != WebAuthenticationStatus.Success) return; var code = response.ResponseData.Substring(response.ResponseData.LastIndexOf("code=") + "code=".Length); Exception exception = null; var oauthRequest = new OAuthRequest { code = code, redirect_uri = callbackUri.AbsoluteUri, grant_type = "authorization_code" }; try { await loginService.LoginAsync(oauthRequest); string username = string.Empty; navigationService.Navigate(App.Experience.Main.ToString(), username); } catch (Exception e) { exception = e; } if (exception != null) { await new MessageDialog(exception.Message, "Error").ShowAsync(); return; } }