コード例 #1
0
        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);
        }
コード例 #2
0
        public static async Task <string> GetAuthorizationCodeURLForOAuthBrowser(string clientID, string clientSecret, IEnumerable <OAuthClientScopeEnum> scopes, string redirectUri, bool forceApprovalPrompt = false)
        {
            Validator.ValidateString(clientID, "clientID");
            Validator.ValidateList(scopes, "scopes");
            Validator.ValidateString(redirectUri, "redirectUri");

            string url = "https://mixer.com/oauth/authorize";

            Dictionary <string, string> parameters = new Dictionary <string, string>()
            {
                { "client_id", clientID },
                { "scope", MixerConnection.ConvertClientScopesToString(scopes) },
                { "response_type", "code" },
                { "redirect_uri", redirectUri },
            };

            if (!string.IsNullOrEmpty(clientSecret))
            {
                parameters.Add("client_secret", clientSecret);
            }

            if (forceApprovalPrompt)
            {
                parameters.Add("approval_prompt", "force");
            }

            FormUrlEncodedContent content = new FormUrlEncodedContent(parameters.AsEnumerable());

            return(url + "?" + await content.ReadAsStringAsync());
        }
コード例 #3
0
        /// <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);
        }
コード例 #4
0
        public static async Task <MixerConnection> ConnectViaOAuthToken(OAuthTokenModel token, bool refreshToken = true)
        {
            Validator.ValidateVariable(token, "token");

            MixerConnection connection = new MixerConnection(token);

            if (refreshToken)
            {
                await connection.RefreshOAuthToken();
            }

            return(connection);
        }
コード例 #5
0
 public static async Task <MixerConnection> ConnectViaAuthorizationCode(string clientID, string authorizationCode, string redirectUrl = null)
 {
     return(await MixerConnection.ConnectViaAuthorizationCode(clientID, null, authorizationCode, redirectUrl));
 }
コード例 #6
0
 public static async Task <string> GetAuthorizationCodeURLForOAuthBrowser(string clientID, IEnumerable <OAuthClientScopeEnum> scopes, string redirectUri, bool forceApprovalPrompt = false)
 {
     return(await MixerConnection.GetAuthorizationCodeURLForOAuthBrowser(clientID, null, scopes, redirectUri, forceApprovalPrompt));
 }
コード例 #7
0
 /// <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="scopes"></param>
 /// <param name="codeCallback"></param>
 /// <returns></returns>
 public static async Task <MixerConnection> ConnectViaShortCode(string clientID, IEnumerable <OAuthClientScopeEnum> scopes, Action <OAuthShortCodeModel> codeCallback)
 {
     return(await MixerConnection.ConnectViaShortCode(clientID, null, scopes, codeCallback));
 }