public TraktAuthenticator(string clientId, string clientSecret, Uri redirectUri, OAuthToken token = null) { ClientId = clientId; ClientSecret = clientSecret; RedirectUri = redirectUri; this.token = token; }
public Task SaveAsync(OAuthToken token) { return Task.Run(delegate { var json = JsonConvert.SerializeObject(token); fileStore.WriteFile(TokenPath, json); }); }
public async Task GetAccessTokenAsync(IRestClient client, string authCode) { var request = new RestRequest("oauth/token", HttpMethod.Post). AddJsonBody(new { code = authCode, redirect_uri = RedirectUri.AbsoluteUri, grant_type = "authorization_code", client_id = ClientId, client_secret = ClientSecret }); var response = await client.Execute<OAuthToken>(request); token = response.Data; }
public Task<bool> SilentLoginAsync() { return Task.Run<bool>(delegate { if (!fileStore.Exists(TokenPath)) return false; string fileText; if (!fileStore.TryReadTextFile(TokenPath, out fileText)) return false; token = JsonConvert.DeserializeObject<OAuthToken>(fileText); return true; }); }
public TraktService(string clientId, string clientSecret, Uri redirectUri, OAuthToken token = null) { client = new RestClient("https://api.trakt.tv"); client.Authenticator = new TraktAuthenticator(clientId, clientSecret, redirectUri, token); }