Esempio n. 1
0
        public PublishApiWebService GeneratePublishService(PublishAccount publishAccount)
        {
            string url = publishAccount.Url.EndsWith("/") ? publishAccount.Url.Substring(0, publishAccount.Url.Length - 1) : publishAccount.Url;

            if (!url.StartsWith("http://") && url.StartsWith("https://"))
            {
                throw new WebServiceException("The provided url must be started with 'http://' or 'https://'");
            }

            int lastIdx = url.LastIndexOf("/");

            if (lastIdx != -1)
            {
                string baseAddress = url.Substring(0, lastIdx + 1);
                if (baseAddress.Equals("http://") || baseAddress.Equals("https://"))
                {
                    throw new WebServiceException(string.Format("The \"{0}\" url is incorrect.", publishAccount.Url));
                }

                string prefix             = url.Substring(lastIdx + 1);
                PublishApiWebService temp = new PublishApiWebService(baseAddress, prefix, FotoShoutUtils.Constants.MEDIATYPE_APPLICATION_JSON);
                string ret = temp.Authenticate(publishAccount.ApiKey.ToString(), new LoginModel {
                    UserName = publishAccount.Email,
                    Password = publishAccount.Password
                });

                return(temp);
            }
            else
            {
                throw new WebServiceException(string.Format("The \"{0}\" url is incorrect.", publishAccount.Url));
            }
        }
Esempio n. 2
0
        private bool Authenticate(FotoShoutData.Models.Credentials credential)
        {
            try {
                FotoShoutUtils.Log.LogManager.Info(_logger, string.Format("Authenticating for the \"{0}\" user...", credential.Email));
                User = _fsWebService.Login(credential);
                if (User == null)
                {
                    FotoShoutUtils.Log.LogManager.Error(_logger, "Unexpected error - There is no user on the central fotoShout associated with the fotoShout Authorization key.\r\n");
                    return(false);
                }
                FotoShoutUtils.Log.LogManager.Info(_logger, "Succeeded logged");
                FotoShoutUtils.Log.LogManager.Info(_logger, "Getting publish configuration information...");
                PublishAccount publishAccount = _fsWebService.GetPublishConfiguration();
                if (publishAccount != null && !string.IsNullOrEmpty(publishAccount.Url))
                {
                    string url     = publishAccount.Url.EndsWith("/") ? publishAccount.Url.Substring(0, publishAccount.Url.Length - 1) : publishAccount.Url;
                    int    lastIdx = url.LastIndexOf("/");
                    if (lastIdx != -1)
                    {
                        string baseAddress = url.Substring(0, lastIdx + 1);
                        string prefix      = url.Substring(lastIdx + 1);
                        _c9WebService = new PublishApiWebService(baseAddress, prefix, FotoShoutUtils.Constants.MEDIATYPE_APPLICATION_JSON);
                        string ret = _c9WebService.Authenticate(publishAccount.ApiKey.ToString(), new LoginModel {
                            UserName = publishAccount.Email,
                            Password = publishAccount.Password
                        });

                        if (string.IsNullOrEmpty(ret))
                        {
                            FotoShoutUtils.Log.LogManager.Error(_logger, "Unable to authorize to the publishing API.\r\n");
                            return(false);
                        }
                    }
                    else
                    {
                        FotoShoutUtils.Log.LogManager.Error(_logger, string.Format("Unable to authorize to the publishing API - The \"{0}\" url is incorrect.\r\n", publishAccount.Url));
                        return(false);
                    }
                }
                else
                {
                    FotoShoutUtils.Log.LogManager.Error(_logger, string.Format("There is no publish configuration for the \"{0}\" user.\r\n", publishAccount.Url));
                    return(false);
                }

                FotoShoutUtils.Log.LogManager.Info(_logger, "Successfully authenticated.\r\n");

                return(true);
            }
            catch (HttpClientServiceException ex) {
                FotoShoutUtils.Log.LogManager.Error(_logger, string.Format("Failed to authenticate : {0} (Status Code: {1})\r\n", ex.Message, (int)ex.StatusCode));
            }
            catch (Exception ex) {
                FotoShoutUtils.Log.LogManager.Error(_logger, string.Format("Failed to authenticate: {0}\r\n", ex.ToString()));
            }

            return(false);
        }
Esempio n. 3
0
        protected void InitAuthentication(HttpCookie authCookie)
        {
            FormsAuthenticationTicket ticket = FormsAuthentication.Decrypt(authCookie.Value);
            string fsAuthorization           = AuthenticationWebService.ExtractAuthorizationString(ticket.UserData);

            if (string.IsNullOrEmpty(fsAuthorization))
            {
                return;
            }

            fsWebService.Authorization = fsAuthorization;
            publishWebService          = GeneratePublishService();
        }