Esempio n. 1
0
        internal async Task <string> GenerateServerBasedAccessTokenAsync()
        {
            if (_serverToken != null && DateTime.UtcNow < _expires)
            {
                return(_serverToken);
            }

            var result = await _http.GeneralRequestAsync($"{BaseOauthToken}?client_id={Settings.ClientId}&client_secret={Settings.Secret}&grant_type=client_credentials", "POST", null, ApiVersion.Helix, Settings.ClientId, null).ConfigureAwait(false);

            if (result.Key == 200)
            {
                var user = JsonConvert.DeserializeObject <JObject>(result.Value);

                _serverToken = user.Value <string>("access_token");
                _expires     = DateTime.UtcNow.AddSeconds(user.Value <int>("expires_in") - 5);
                return(_serverToken);
            }
            return(null);
        }
Esempio n. 2
0
        internal async Task <string> GenerateServerBasedAccessToken()
        {
            var result = await _http.GeneralRequestAsync($"{BaseAuth}/token?client_id={Settings.ClientId}&client_secret={Settings.Secret}&grant_type=client_credentials", "POST", null, ApiVersion.Helix, Settings.ClientId, null).ConfigureAwait(false);

            if (result.Key == 200)
            {
                var user   = JsonConvert.DeserializeObject <dynamic>(result.Value);
                var offset = (int)user.expires_in;
                _serverBasedAccessTokenExpiry = DateTime.Now + TimeSpan.FromSeconds(offset);
                _serverBasedAccessToken       = (string)user.access_token;
                return(_serverBasedAccessToken);
            }
            return(null);
        }