Exemplo n.º 1
0
        public async Task ExecuteAsync(CancellationToken cancellationToken)
        {
            if (_userAccessTokenStore.UserAccessToken == null)
            {
                return;
            }

            RefreshableUserAccessTokenModel model = await _twitchApiClient.RefreshUserAccessToken(_userAccessTokenStore.UserAccessToken.RefreshToken);

            RefreshableUserAccessToken refreshableUserAccessToken = new RefreshableUserAccessToken()
            {
                AccessToken  = model.AccessToken,
                RefreshToken = model.RefreshToken
            };

            Interlocked.Exchange(ref _userAccessTokenStore.UserAccessToken, refreshableUserAccessToken);
        }
Exemplo n.º 2
0
        public async Task <RefreshableUserAccessTokenModel> RefreshUserAccessToken(string refreshToken)
        {
            HttpClient client = new HttpClient();

            string url = "https://id.twitch.tv/oauth2/token";

            url = QueryHelpers.AddQueryString(url, "client_id", _clientId);
            url = QueryHelpers.AddQueryString(url, "client_secret", _clientSecret);
            url = QueryHelpers.AddQueryString(url, "grant_type", "refresh_token");
            url = QueryHelpers.AddQueryString(url, "refresh_token", refreshToken);

            HttpResponseMessage response = await client.PostAsync(url, null);

            string jsonString = await response.Content.ReadAsStringAsync();

            RefreshableUserAccessTokenModel data = JsonConvert.DeserializeObject <RefreshableUserAccessTokenModel>(jsonString);

            return(data);
        }