public static async Task <bool> GetTokens(GfycatPreset preset) { var auth = new GfycatAuthRequest { GrantType = "client_credentials", ClientId = Secret.GfycatId, ClientSecret = Secret.GfycatSecret }; return(await GetTokens(preset, auth)); }
public static async Task <bool> RefreshToken(GfycatPreset preset) { var auth = new GfycatAuthRequest { GrantType = "refresh", ClientId = Secret.GfycatId, ClientSecret = Secret.GfycatSecret, RefreshToken = preset.RefreshToken }; return(await GetTokens(preset, auth)); }
public static async Task <bool> GetTokens(GfycatPreset preset, string username, string password) { var auth = new GfycatAuthRequest { GrantType = "password", ClientId = Secret.GfycatId, ClientSecret = Secret.GfycatSecret, Username = username, Password = password }; return(await GetTokens(preset, auth)); }
private static async Task <bool> GetTokens(GfycatPreset preset, GfycatAuthRequest auth) { var response = await WebHelper.Post("https://api.gfycat.com/v1/oauth/token", Serializer.Serialize(auth)); if (string.IsNullOrEmpty(response)) { return(false); } var token = Serializer.Deserialize <OAuth2Token>(response); if (string.IsNullOrEmpty(token?.AccessToken)) { return(false); } preset.AccessToken = token.AccessToken; preset.RefreshToken = token.RefreshToken; preset.AccessTokenExpiryDate = DateTime.UtcNow + TimeSpan.FromSeconds(token.ExpiresIn - 10); preset.RefreshTokenExpiryDate = DateTime.UtcNow + TimeSpan.FromSeconds(token.RefreshTokenExpiresIn - 10); return(true); }