public AuthenticationResult GetAuthenticationResult(Uri responseUri, OAuthRequestCode request)
        {
            QueryValues          queryValues;
            AuthenticationResult result;

            if (request is OAuthRequestAuthorizationCode auth)
            {
                queryValues = QueryValues.Parse(StringUtils.RemovePrefix(responseUri.Query, "?"));
                this.EnsureStateEquals(queryValues, request);

                var accessTokenRequest = new OAuthTokenRequest();
                accessTokenRequest.ClientSecret = auth.ClientSecret;
                accessTokenRequest.Code         = queryValues.Single("code");
                accessTokenRequest.GrantType    = "authorization_code";
                accessTokenRequest.RedirectUri  = auth.RedirectUri;
                result = this.GetAuthenticationResult(accessTokenRequest);
            }
            else if (request is OAuthRequestTokenCode)
            {
                queryValues = QueryValues.Parse(HttpUtility.UrlDecode(StringUtils.RemovePrefix(responseUri.Fragment, "#")));
                this.EnsureStateEquals(queryValues, request);

                result = new AuthenticationResult(queryValues);
            }
            else
            {
                throw new ArgumentException("Invalid OAuthRequest Type", nameof(request));
            }

            return(result);
        }
        public WebRequestParameter CreateWebRequest(TwitchAPIRequest apiRequest)
        {
            var baseUri     = this.GetBaseUri(apiRequest.BaseUrl, apiRequest.Version, apiRequest.Path);
            var queryValues = new QueryValues();

            queryValues.AddRange(QueryValues.Parse(baseUri.Query));
            queryValues.AddRange(apiRequest.QueryValues);

            var request = new WebRequestParameter();

            request.RetryCount     = 0;
            request.Uri            = $"{baseUri.Scheme}{Uri.SchemeDelimiter}{baseUri.Host}{baseUri.LocalPath}{queryValues.ToString(false)}";
            request.Method         = apiRequest.Method;
            request.WriteParameter = apiRequest.PostData;
            request.ContentType    = apiRequest.ContentType ?? request.ContentType;
            this.SetupRequest(request, apiRequest.Version);

            return(request);
        }