public BoxDocumentProvider(AuthData authData)
 {
     if (string.IsNullOrEmpty(authData.Token))
     {
         //Get auth_ticket
         GetAuthTicket();
     }
     else
     {
         _authToken = authData.Token;
     }
 }
        public GoogleDriveProviderInfo(int id, string providerKey, string customerTitle, AuthData authData, Guid owner, FolderType rootFolderType, DateTime createOn)
        {
            if (string.IsNullOrEmpty(providerKey))
                throw new ArgumentNullException("providerKey");
            if (string.IsNullOrEmpty(authData.Token))
                throw new ArgumentException("Token can't be null");

            ID = id;
            CustomerTitle = customerTitle;
            Owner = owner == Guid.Empty ? SecurityContext.CurrentAccount.ID : owner;

            ProviderKey = providerKey;
            _authData = authData;
            _rootFolderType = rootFolderType;
            _createOn = createOn;
        }
        public SharpBoxProviderInfo(int id, string providerKey, string customerTitle, AuthData authData, Guid owner, FolderType rootFolderType, DateTime createOn)
        {
            if (string.IsNullOrEmpty(providerKey))
                throw new ArgumentNullException("providerKey");
            if (string.IsNullOrEmpty(authData.Token) && string.IsNullOrEmpty(authData.Password))
                throw new ArgumentNullException("token", "Both token and password can't be null");
            if (!string.IsNullOrEmpty(authData.Login) && string.IsNullOrEmpty(authData.Password) && string.IsNullOrEmpty(authData.Token))
                throw new ArgumentNullException("password", "Password can't be null");

            ID = id;
            CustomerTitle = customerTitle;
            Owner = owner == Guid.Empty ? SecurityContext.CurrentAccount.ID : owner;

            _providerKey = (nSupportedCloudConfigurations) Enum.Parse(typeof (nSupportedCloudConfigurations), providerKey, true);
            _authData = authData;
            _rootFolderType = rootFolderType;
            _createOn = createOn;
        }
        public SharePointProviderInfo(int id, string providerKey, string customerTitle, AuthData authData, Guid owner,
                                      FolderType rootFolderType, DateTime createOn)
        {
            if (string.IsNullOrEmpty(providerKey))
                throw new ArgumentNullException("providerKey");
            if (!string.IsNullOrEmpty(authData.Login) && string.IsNullOrEmpty(authData.Password))
                throw new ArgumentNullException("password", "Password can't be null");

            ID = id;
            ProviderKey = providerKey;
            CustomerTitle = customerTitle;
            Owner = owner == Guid.Empty ? SecurityContext.CurrentAccount.ID : owner;
            RootFolderType = rootFolderType;
            CreateOn = createOn;
            RootFolderId = MakeId();

            InitClientContext(authData);
        }
 public GoogleDocumentProvider(AuthData authData)
 {
     _accessToken = authData.Token;
     _consumer = new WebConsumer(GoogleConsumer.ServiceDescription, ImportConfiguration.GoogleTokenManager);
 }
Esempio n. 6
0
        public ItemList<FileOperationResult> ExecImportDocs(string login, string password, string token, string source, string parentId, string ignoreCoincidenceFiles, List<DataToImport> dataToImport)
        {
            var authData = new AuthData(login, password, token);

            IDocumentProvider provider;
            String folderName;

            switch (source)
            {
                case "boxnet":
                    provider = new BoxDocumentProvider(authData);
                    folderName = FilesCommonResource.ImportFromBoxNet;
                    return ImportDocuments(provider, dataToImport, parentId, ignoreCoincidenceFiles, folderName);
                case "google":
                    folderName = FilesCommonResource.ImportFromGoogle;
                    using (var google = new GoogleDocumentProvider(authData))
                    {
                        return ImportDocuments(google, dataToImport, parentId, ignoreCoincidenceFiles, folderName);
                    }
                case "zoho":
                    provider = new ZohoDocumentProvider(authData);
                    folderName = FilesCommonResource.ImportFromZoho;
                    return ImportDocuments(provider, dataToImport, parentId, ignoreCoincidenceFiles, folderName);
                default:
                    ErrorIf(true, "Unknown provider");
                    return null;
            }
        }
Esempio n. 7
0
 public ItemList<DataToImport> GetImportDocs(string source, AuthData authData)
 {
     switch (source)
     {
         case "boxnet":
             return DocumentsToDataImport(new BoxDocumentProvider(authData).GetDocuments());
         case "google":
             using (var google = new GoogleDocumentProvider(authData))
             {
                 return DocumentsToDataImport(google.GetDocuments());
             }
         case "zoho":
             try
             {
                 var zoho = new ZohoDocumentProvider(authData);
                 return DocumentsToDataImport(zoho.GetDocuments());
             }
             catch (Exception e)
             {
                 ErrorIf(true, e.Message);
                 return null;
             }
         default:
             ErrorIf(true, "Unknown provider");
             return null;
     }
 }
        private const string Scheme = "https"; //Fix for may 7 2011.

        public ZohoDocumentProvider(AuthData authData)
        {
            _authTokenWriter = GetAuthToken("ZohoWriter/DataAPI", authData.Login, authData.Password);
            _authTokenSheet = GetAuthToken("ZohoSheet/DataAPI", authData.Login, authData.Password);
            _authTokenShow = GetAuthToken("ZohoShow/DataAPI", authData.Login, authData.Password);
        }
        private static AuthData GetEncodedAccesToken(AuthData authData, ProviderTypes provider)
        {
            switch (provider)
            {
                case ProviderTypes.GoogleDrive:

                    var code = authData.Token;

                    var token = OAuth20TokenHelper.GetAccessToken(GoogleLoginProvider.GoogleOauthTokenUrl,
                                                                  GoogleLoginProvider.GoogleOAuth20ClientId,
                                                                  GoogleLoginProvider.GoogleOAuth20ClientSecret,
                                                                  GoogleLoginProvider.GoogleOAuth20RedirectUrl,
                                                                  code);

                    if (token == null) throw new UnauthorizedAccessException(string.Format(FilesCommonResource.ErrorMassage_SecurityException_Auth, provider));

                    authData.Token = EncryptPassword(token.ToJson());

                    break;
                case ProviderTypes.SkyDrive:

                    code = authData.Token;

                    token = OAuth20TokenHelper.GetAccessToken(OneDriveLoginProvider.OneDriveOauthTokenUrl,
                                                              OneDriveLoginProvider.OneDriveOAuth20ClientId,
                                                              OneDriveLoginProvider.OneDriveOAuth20ClientSecret,
                                                              OneDriveLoginProvider.OneDriveOAuth20RedirectUrl,
                                                              code);

                    if (token == null) throw new UnauthorizedAccessException(string.Format(FilesCommonResource.ErrorMassage_SecurityException_Auth, provider));

                    var accessToken = AppLimit.CloudComputing.SharpBox.Common.Net.oAuth20.OAuth20Token.FromJson(token.ToJson());

                    var config = CloudStorage.GetCloudConfigurationEasy(nSupportedCloudConfigurations.SkyDrive);
                    var storage = new CloudStorage();
                    var base64AccessToken = storage.SerializeSecurityTokenToBase64Ex(accessToken, config.GetType(), new Dictionary<string, string>());

                    authData.Token = base64AccessToken;

                    break;
                case ProviderTypes.SharePoint:
                case ProviderTypes.WebDav:
                    break;
                default:
                    authData.Url = null;
                    break;
            }

            return authData;
        }
Esempio n. 10
0
 private static IProviderInfo ToProviderInfo(int id, string providerKey, string customerTitle, AuthData authData, string owner, FolderType type, DateTime createOn)
 {
     return ToProviderInfo(new object[] {id, providerKey, customerTitle, authData.Login, EncryptPassword(authData.Password), authData.Token, owner, (int) type, createOn, authData.Url});
 }
Esempio n. 11
0
        public virtual int SaveProviderInfo(string providerKey, string customerTitle, AuthData authData, FolderType folderType)
        {
            ProviderTypes prKey;
            try
            {
                prKey = (ProviderTypes) Enum.Parse(typeof (ProviderTypes), providerKey, true);
            }
            catch (Exception)
            {
                throw new ArgumentException("Unrecognize ProviderType");
            }

            authData = GetEncodedAccesToken(authData, prKey);

            if (!CheckProviderInfo(ToProviderInfo(0, providerKey, customerTitle, authData, SecurityContext.CurrentAccount.ID.ToString(), folderType, TenantUtil.DateTimeToUtc(TenantUtil.DateTimeNow()))))
                throw new UnauthorizedAccessException(string.Format(FilesCommonResource.ErrorMassage_SecurityException_Auth, providerKey));

            var queryInsert = new SqlInsert(TableTitle, true)
                .InColumnValue("id", 0)
                .InColumnValue("tenant_id", TenantID)
                .InColumnValue("provider", prKey.ToString())
                .InColumnValue("customer_title", Global.ReplaceInvalidCharsAndTruncate(customerTitle))
                .InColumnValue("user_name", authData.Login)
                .InColumnValue("password", EncryptPassword(authData.Password))
                .InColumnValue("folder_type", (int) folderType)
                .InColumnValue("create_on", TenantUtil.DateTimeToUtc(TenantUtil.DateTimeNow()))
                .InColumnValue("user_id", SecurityContext.CurrentAccount.ID.ToString())
                .InColumnValue("token", authData.Token)
                .InColumnValue("url", authData.Url)
                .Identity(0, 0, true);

            return Int32.Parse(DbManager.ExecuteScalar<string>(queryInsert));
        }
Esempio n. 12
0
        public ItemList<FileOperationResult> ExecImportDocs(String login, String password, String token, String source, String parentId, bool ignoreCoincidenceFiles, List<DataToImport> dataToImport)
        {
            var authData = new AuthData(login, password, token);

            IDocumentProvider provider;
            String folderName;


            switch (source)
            {
                case "boxnet":
                    provider = new BoxDocumentProvider(authData);
                    folderName = FilesCommonResource.ImportFromBoxNet;

                    return ImportDocuments(provider, dataToImport, parentId, ignoreCoincidenceFiles, folderName);
                case "google":
                    folderName = FilesCommonResource.ImportFromGoogle;
                    using (var google = new GoogleDocumentProvider(authData))
                    {
                        return ImportDocuments(google, dataToImport, parentId, ignoreCoincidenceFiles, folderName);
                    }
                case "zoho":
                    provider = new ZohoDocumentProvider(authData);
                    folderName = FilesCommonResource.ImportFromZoho;

                    return ImportDocuments(provider, dataToImport, parentId, ignoreCoincidenceFiles, folderName);
                default:
                    throw GenerateException(new ArgumentException(FilesCommonResource.ErrorMassage_UnknownrProvider));
            }
        }
Esempio n. 13
0
 public ItemList<DataToImport> GetImportDocs(String source, AuthData authData)
 {
     try
     {
         switch (source)
         {
             case "boxnet":
                 return DocumentsToDataImport(new BoxDocumentProvider(authData).GetDocuments());
             case "google":
                 using (var google = new GoogleDocumentProvider(authData))
                 {
                     return DocumentsToDataImport(google.GetDocuments());
                 }
             case "zoho":
                 var zoho = new ZohoDocumentProvider(authData);
                 return DocumentsToDataImport(zoho.GetDocuments());
         }
     }
     catch(Exception e)
     {
         throw GenerateException(e);
     }
     throw GenerateException(new ArgumentException(FilesCommonResource.ErrorMassage_UnknownrProvider));
 }
        private void InitClientContext(AuthData authData)
        {
            var authUrl = authData.Url;
            ICredentials credentials = new NetworkCredential(authData.Login, authData.Password);

            if (authData.Login.EndsWith("onmicrosoft.com"))
            {
                var personalPath = string.Concat("/personal/", authData.Login.Replace("@", "_").Replace(".", "_").ToLower());
                SpRootFolderId = string.Concat(personalPath, "/Documents");

                var ss = new SecureString();
                foreach (var p in authData.Password)
                {
                    ss.AppendChar(p);
                }
                authUrl = string.Concat(authData.Url.TrimEnd('/'), personalPath);
                credentials = new SharePointOnlineCredentials(authData.Login, ss);

            }

            clientContext = new ClientContext(authUrl)
            {
                AuthenticationMode = ClientAuthenticationMode.Default,
                Credentials = credentials
            };
        }
        private const string Scheme = "https"; //Fix for may 7 2011.

        public ZohoDocumentProvider(AuthData authData)
        {
            _ticket = Authenticate(authData.Login, authData.Password);
        }
        private static AuthData GetEncodedAccesToken(AuthData authData, ProviderTypes provider)
        {
            switch (provider)
            {
                case ProviderTypes.Google:
                case ProviderTypes.GoogleDrive:

                    var tokenSecret = ImportConfiguration.GoogleTokenManager.GetTokenSecret(authData.Token);
                    var consumerKey = ImportConfiguration.GoogleTokenManager.ConsumerKey;
                    var consumerSecret = ImportConfiguration.GoogleTokenManager.ConsumerSecret;

                    var accessToken = GoogleDocsAuthorizationHelper.BuildToken(authData.Token, tokenSecret, consumerKey, consumerSecret);
                    var storage = new CloudStorage();

                    authData.Token = storage.SerializeSecurityTokenToBase64Ex(accessToken, typeof(GoogleDocsConfiguration), null);

                    break;
            }

            return authData;
        }