Exemplo n.º 1
0
        public RecaptchaResultModel CheckIt(string secret, string code)
        {
            var client = new WebRequest2();
            var data   = new Dictionary <string, string>
            {
                { "secret", secret },
                { "response", code }
            };

            var tokenResult = client.PostForm("https://www.google.com/recaptcha/api/siteverify", data);

            return(tokenResult.ParseJson <RecaptchaResultModel>());
        }
Exemplo n.º 2
0
        public ResultModel AddMember(string firstName, string lastName, string email, int listId, TokenResult token)
        {
            var client = new WebRequest2();
            var data   = new Dictionary <string, string>
            {
                { "Email", email },
                { "FirstName", firstName },
                { "LastName", lastName },
                { "ListId", listId.ToString() }
            };
            var resultData = client.PostForm("https://api.mail2inbox.com/api/Member", data, token.access_token);

            return(resultData.ParseJson <ResultModel>());
        }
Exemplo n.º 3
0
        public TokenResult GetToken(string userName, string password)
        {
            var client = new WebRequest2();

            var data = new Dictionary <string, string>
            {
                { "grant_type", "password" },
                { "username", userName },
                { "password", password.ToBase64() }
            };

            var tokenResult = client.PostForm("https://api.mail2inbox.com/token", data);

            return(tokenResult.ParseJson <TokenResult>());
        }
Exemplo n.º 4
0
        public ResultModel SendMail(SendPostModel msg, TokenResult token)
        {
            var client = new WebRequest2();
            var data   = new Dictionary <string, string>
            {
                { "From", msg.From },
                { "To", msg.To },
                { "Reply", msg.Reply },
                { "Cc", msg.Cc },
                { "Bcc", msg.Bcc },
                { "Subject", msg.Subject },
                { "Body", msg.Body }
            };
            var resultData = client.PostForm("https://api.mail2inbox.com/api/send", data, token.access_token);

            return(resultData.ParseJson <ResultModel>());
        }
Exemplo n.º 5
0
        // 2
        public virtual AuthenticationToken GetAuthenticationToken(string code, string redirectUrl)
        {
            var dic = new Dictionary <string, string>();

            if (!code.IsEmpty())
            {
                dic.Add("code", code);
            }
            dic.Add(ClientIdKeyword, _configuration.ClientId);
            dic.Add("grant_type", GrantType);
            if (!_configuration.ClientSecret.IsEmpty())
            {
                dic.Add(ClientSecretKeyword, _configuration.ClientSecret);
            }
            if (!redirectUrl.IsEmpty())
            {
                dic.Add("redirect_uri", redirectUrl);
            }
            var response = _webRequest.PostForm(AccessTokenServiceEndpoint, dic);

            var tokenInfo = new AuthenticationToken();

            try
            {
                if (ResponseType == ResponseTypes.Json)
                {
                    tokenInfo = response.ParseJson <AuthenticationToken>();
                }
                else
                {
                    var query = HttpUtility.ParseQueryString(response);
                    if (query["error"] != null)
                    {
                        tokenInfo.Error = query["error"];
                    }
                    if (query["error_description"] != null)
                    {
                        tokenInfo.ErrorDesc = query["error_description"];
                    }
                    if (query["access_token"] != null)
                    {
                        tokenInfo.AccessToken = query["access_token"];
                    }
                    if (query["refresh_token"] != null)
                    {
                        tokenInfo.RefreshToken = query["refresh_token"];
                    }
                    if (query["token_type"] != null)
                    {
                        tokenInfo.TokenType = query["token_type"];
                    }
                    if (query["expires_in"] != null)
                    {
                        tokenInfo.Expires = int.Parse(query["expires_in"]);
                    }
                }
                return(tokenInfo);
            }
            catch (Exception ex)
            {
                tokenInfo.Error     = "HATA";
                tokenInfo.ErrorDesc = Logger.GetErrorMessage(ex);
            }
            return(tokenInfo);
        }