Example #1
0
        public string getRequestString()
        {
            string _result = "https://id.twitch.tv/oauth2/authorize";

            _result += "?client_id=" + Uri.EscapeDataString(ClientID);
            _result += "&redirect_uri=" + Uri.EscapeDataString(RedirectURI);
            _result += "&response_type=" + Uri.EscapeDataString(ResponseType);
            _result += "&scope=" + Uri.EscapeDataString(TwitchScopeUtil.getScopeString(Scope));
            if (ForceVerify != null)
            {
                _result += "&force_verify=" + Uri.EscapeDataString("" + ForceVerify);
            }
            if (State != null)
            {
                _result += "&state=" + Uri.EscapeDataString(State);
            }
            return(_result);
        }
        public static OAuthAppAccessToken parseToken(string jsonData)
        {
            JObject token = JObject.Parse(jsonData);

            string      AccessToken;
            string      RefreshToken;
            TimeSpan    ExpiresIn;
            TwitchScope Scope = TwitchScope.NONE;

            JToken?currToken = token["access_token"];

            if (currToken != null)
            {
                string?s = currToken.Value <string>();
                AccessToken = (s == null) ? "" : s;
            }
            else
            {
                AccessToken = "";
            }

            currToken = token["refresh_token"];
            if (currToken != null)
            {
                string?s = currToken.Value <string>();
                RefreshToken = (s == null) ? "" : s;
            }
            else
            {
                RefreshToken = "";
            }

            currToken = token["expires_in"];
            if (currToken != null)
            {
                int?secs = currToken.Value <int>();
                ExpiresIn = new TimeSpan(0, 0, (secs == null) ? 0 : (int)secs);
            }
            else
            {
                ExpiresIn = new TimeSpan(0);
            }

            currToken = token["scope"];
            if (currToken != null)
            {
                IEnumerable <string?> scopes = currToken.Values <string>();
                if (scopes != null)
                {
                    foreach (string?s in scopes)
                    {
                        if ((s != null) && !string.IsNullOrWhiteSpace(s))
                        {
                            Scope |= TwitchScopeUtil.getScope(s);
                        }
                    }
                }
            }

            return(new OAuthAppAccessToken(AccessToken, RefreshToken, ExpiresIn, Scope));
        }