public static async Task <string> ValidateShortCode(ShortCode shortCode)
        {
            if (shortCode == null)
            {
                throw new ArgumentException("Short Code is null");
            }

            for (int i = 0; i < shortCode.expires_in; i++)
            {
                using (HttpClientWrapper client = new HttpClientWrapper())
                {
                    HttpResponseMessage response = await client.GetAsync("oauth/shortcode/check/" + shortCode.handle);

                    if (response.StatusCode == HttpStatusCode.OK)
                    {
                        string result = await response.Content.ReadAsStringAsync();

                        JObject jobject = JObject.Parse(result);
                        return((string)jobject["code"]);
                    }
                }
                await Task.Delay(1000);
            }
            return(null);
        }
Beispiel #2
0
        public static async Task <MixerClient> ConnectViaShortCode(string clientID, IEnumerable <ClientScopeEnum> scopes, Action <string> codeCallback)
        {
            Validator.ValidateString(clientID, "clientID");
            Validator.ValidateList(scopes, "scopes");
            Validator.ValidateVariable(codeCallback, "codeCallback");

            ShortCode shortCode = await AuthorizationToken.GenerateShortCode(clientID, scopes);

            codeCallback(shortCode.code);

            string authorizationCode = await AuthorizationToken.ValidateShortCode(shortCode);

            if (authorizationCode != null)
            {
                return(await MixerClient.ConnectViaAuthorizationCode(clientID, authorizationCode));
            }
            return(null);
        }