Beispiel #1
0
        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));
        }
Beispiel #2
0
        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));
        }
Beispiel #3
0
        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));
        }
Beispiel #4
0
        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);
        }