public static async Task <MixerConnection> ConnectViaLocalhostOAuthBrowser(string clientID, string clientSecret, IEnumerable <OAuthClientScopeEnum> scopes, bool forceApprovalPrompt = false, string oauthListenerURL = DEFAULT_OAUTH_LOCALHOST_URL, string loginSuccessHtmlPageFilePath = null) { Validator.ValidateString(clientID, "clientID"); Validator.ValidateList(scopes, "scopes"); OAuthHttpListenerServer oauthServer = new OAuthHttpListenerServer(oauthListenerURL, loginSuccessHtmlPageFilePath); oauthServer.Start(); string url = await MixerConnection.GetAuthorizationCodeURLForOAuthBrowser(clientID, scopes, oauthListenerURL, forceApprovalPrompt); ProcessStartInfo startInfo = new ProcessStartInfo() { FileName = url, UseShellExecute = true }; Process.Start(startInfo); string authorizationCode = await oauthServer.WaitForAuthorizationCode(); oauthServer.End(); if (authorizationCode != null) { return(await MixerConnection.ConnectViaAuthorizationCode(clientID, clientSecret, authorizationCode, redirectUrl : oauthListenerURL)); } return(null); }
/// <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); }
public static async Task <MixerConnection> ConnectViaAuthorizationCode(string clientID, string authorizationCode, string redirectUrl = null) { return(await MixerConnection.ConnectViaAuthorizationCode(clientID, null, authorizationCode, redirectUrl)); }