コード例 #1
0
        private async Task <T> GetAsync <T>(string url, TokenDto token) where T : new()
        {
            var request = new RestRequest(url);

            request.AddHeader("Authorization", "Bearer " + token.AccessToken);
            request.AddHeader("Referer", "https://my.tado.com/");
            return(await _client.GetTaskAsync <T>(request));
        }
コード例 #2
0
        private async Task <TokenDto> RefreshTokenAsync(TokenDto token)
        {
            if ((token.Expires - DateTime.UtcNow).TotalMinutes > 1.5)
            {
                return(token);
            }

            var refreshRequest = new RestRequest("oauth/token");

            refreshRequest.AddQueryParameter("client_id", "tado-webapp");
            refreshRequest.AddQueryParameter("grant_type", "refresh_token");
            refreshRequest.AddQueryParameter("refresh_token", token.RefreshToken);
            refreshRequest.AddQueryParameter("scope", "home.user");
            refreshRequest.AddHeader("Origin", "https://my.tado.com");
            refreshRequest.AddHeader("Referer", "https://my.tado.com/");

            token = await _client.PostTaskAsync <TokenDto>(refreshRequest);

            token.Expires = DateTime.UtcNow.AddSeconds(token.ExpiresIn);
            return(token);
        }