/// <summary> /// NOTE: There is a known issue with the Mixer APIs where authenticating with a short code as opposed to the regular OAuth process, where certain /// Chat Client commands will not work (EX: Timeout, Clear Messages, Delete Message, etc). The current work around to this is to use the traditional /// OAuth authentication methods. /// </summary> /// <param name="clientID"></param> /// <param name="clientSecret"></param> /// <param name="scopes"></param> /// <param name="codeCallback"></param> /// <returns></returns> public static async Task <MixerConnection> ConnectViaShortCode(string clientID, string clientSecret, IEnumerable <OAuthClientScopeEnum> scopes, Action <OAuthShortCodeModel> codeCallback) { Validator.ValidateString(clientID, "clientID"); Validator.ValidateList(scopes, "scopes"); Validator.ValidateVariable(codeCallback, "codeCallback"); OAuthService oauthService = new OAuthService(); OAuthShortCodeModel shortCode = await oauthService.GetShortCode(clientID, clientSecret, scopes); codeCallback(shortCode); string authorizationCode = null; for (int i = 0; i < shortCode.expires_in && string.IsNullOrEmpty(authorizationCode); i++) { await Task.Delay(500); authorizationCode = await oauthService.ValidateShortCode(shortCode); } if (!string.IsNullOrEmpty(authorizationCode)) { return(await MixerConnection.ConnectViaAuthorizationCode(clientID, clientSecret, authorizationCode, authorizationCode)); } return(null); }
/// <summary> /// Validates the specified short code authorization and returns the authorization code. /// </summary> /// <param name="shortCode">The short code authorization to validate</param> /// <returns>The authorization code</returns> public async Task <string> ValidateShortCode(OAuthShortCodeModel shortCode) { Validator.ValidateVariable(shortCode, "shortCode"); HttpResponseMessage response = await this.GetAsync("oauth/shortcode/check/" + shortCode.handle); if (response.StatusCode == HttpStatusCode.OK) { JObject jobject = JObject.Parse(await response.Content.ReadAsStringAsync()); return((string)jobject["code"]); } return(null); }