Example #1
0
        protected IShareFileClient GetShareFileClient()
        {
            try
            {
                using (var fileStream = System.IO.File.OpenRead("TestConfig.json"))
                using (var streamReader = new StreamReader(fileStream))
                {
                    var info = streamReader.ReadToEnd();
                    var userInfo = JsonConvert.DeserializeObject<UserInfo>(info);

                    var sfClient = new ShareFileClient(userInfo.GetBaseUri().ToString());

                    lock (oauthTokenLock)
                    {
                        if (token == null)
                        {
                            var oauthService = new OAuthService(sfClient, userInfo.ClientId, userInfo.ClientSecret);
                            token = oauthService.GetPasswordGrantRequestQuery(userInfo.Email, userInfo.Password, userInfo.Subdomain, userInfo.Domain).Execute();
                        }
                    }

                    sfClient.BaseUri = token.GetUri();
                    sfClient.AddOAuthCredentials(token);
                    return sfClient;
                }
            }
            catch (Exception exception)
            {
                Assert.Inconclusive(string.Format("No UserInfo found in TestConfig.json. Exception: {0}", exception));
                throw;
            }
        }
        protected IShareFileClient GetShareFileClient()
        {
            try
            {
                using (var fileStream = System.IO.File.OpenRead("TestConfig.json"))
                    using (var streamReader = new StreamReader(fileStream))
                    {
                        var info     = streamReader.ReadToEnd();
                        var userInfo = JsonConvert.DeserializeObject <UserInfo>(info);

                        var sfClient = new ShareFileClient(userInfo.GetBaseUri().ToString());

                        lock (oauthTokenLock)
                        {
                            if (token == null)
                            {
                                var oauthService = new OAuthService(sfClient, userInfo.ClientId, userInfo.ClientSecret);
                                token = oauthService.GetPasswordGrantRequestQuery(userInfo.Email, userInfo.Password, userInfo.Subdomain, userInfo.Domain).Execute();
                            }
                        }

                        sfClient.BaseUri = token.GetUri();
                        sfClient.AddOAuthCredentials(token);
                        return(sfClient);
                    }
            }
            catch (Exception exception)
            {
                Assert.Inconclusive(string.Format("No UserInfo found in TestConfig.json. Exception: {0}", exception));
                throw;
            }
        }
Example #3
0
        private async void ExchangeAuthorizationCode(OAuthAuthorizationCode code)
        {
            var oauthToken = await _oauthService.ExchangeAuthorizationCodeAsync(code);

            _sfClient.AddOAuthCredentials(oauthToken);
            _sfClient.BaseUri = oauthToken.GetUri();

            var session = await _sfClient.Sessions.Login().Expand("Principal").ExecuteAsync();

            MessageBox.Show("User: "******"Successful");
        }
        private ShareFileClient CreateClient(AuthenticationDomain domain)
        {
            var client = new ShareFileClient(domain.Uri);

            if (domain.OAuthToken != null)
            {
                client.AddOAuthCredentials(new Uri(domain.Uri), domain.OAuthToken);
            }
            client.AddExceptionHandler(OnException);
            client.AddChangeDomainHandler(OnDomainChange);
            return(client);
        }
Example #5
0
        private async Task <IShareFileClient> GetAuthenticatedClient()
        {
            var baseUrl = $"https://{_sfConfig.Subdomain}.sf-api.com/sf/v3/";

            _logger.LogInformation("BaseUrl: " + baseUrl);
            var client = new ShareFileClient(baseUrl);

            var oauthService = new OAuthService(client, _sfConfig.ClientId, _sfConfig.ClientSecret);
            var token        = await oauthService.PasswordGrantAsync(_sfConfig.Username, _sfConfig.Password, _sfConfig.Subdomain, "sharefile.com");

            client.AddOAuthCredentials(token);
            return(client);
        }
Example #6
0
        async Task <IShareFileClient> BuildShareFileClient(OAuthAuthorizationCode authCode)
        {
            string           baseUriFormat = "https://{0}.{1}/sf/v3";
            string           baseUri       = String.Format(baseUriFormat, authCode.Subdomain, authCode.ApiControlPlane);
            IShareFileClient api           = new ShareFileClient(baseUri);
            var oauth = new OAuthService(api, Globals.OAuthClientID, Globals.OAuthClientSecret);
            var token = await oauth.ExchangeAuthorizationCodeAsync(authCode);

            api.AddOAuthCredentials(token);
            api.BaseUri = new Uri(String.Format(baseUriFormat, token.Subdomain, token.ApiControlPlane));
            await Login(api);

            return(api);
        }
Example #7
0
        private async Task <ShareFileClient> GetShareFileClient()
        {
            var sfClient = new ShareFileClient("https://secure.sf-api.com/sf/v3/");
            //sfClient.Configuration.ProxyConfiguration = new WebProxy(new Uri("http://127.0.0.1:8888"), false);
            var oauthService = new OAuthService(sfClient, ConfigurationHelper.ClientId, ConfigurationHelper.ClientSecret);

            var oauthToken = await oauthService.PasswordGrantAsync(username,
                                                                   password, subdomain, applicationControlPlane);

            _oathToken = oauthToken.AccessToken;

            sfClient.AddOAuthCredentials(oauthToken);
            sfClient.BaseUri = oauthToken.GetUri();
            return(sfClient);
        }
        private ShareFileClient CreateClient(AuthenticationDomain domain)
        {
            Configuration config = Configuration.Default();

            config.HttpTimeout = 200000;
            var client = new ShareFileClient(domain.Uri, config);

            if (domain.OAuthToken != null)
            {
                client.AddOAuthCredentials(new Uri(domain.Uri), domain.OAuthToken);
            }
            client.AddExceptionHandler(OnException);
            client.AddChangeDomainHandler(OnDomainChange);
            return(client);
        }
Example #9
0
        public static async Task <ShareFileClient> PasswordAuthentication(SampleUser user, string clientId, string clientSecret)
        {
            // Initialize ShareFileClient.
            var configuration = Configuration.Default();

            configuration.Logger = new DefaultLoggingProvider();

            var sfClient     = new ShareFileClient("https://secure.sf-api.com/sf/v3/", configuration);
            var oauthService = new OAuthService(sfClient, clientId, clientSecret);

            // Perform a password grant request.  Will give us an OAuthToken
            var oauthToken = await oauthService.PasswordGrantAsync(user.Username, user.Password, user.Subdomain, user.ControlPlane);

            // Add credentials and update sfClient with new BaseUri
            sfClient.AddOAuthCredentials(oauthToken);
            sfClient.BaseUri = oauthToken.GetUri();

            return(sfClient);
        }
Example #10
0
        private async Task <ShareFileClient> PasswordAuthenticationAsync()
        {
            var shareFileConfiguration = _auditConfiguration.ShareFileConfiguration;
            var configuration          = Configuration.Default();

            configuration.Logger = new DefaultLoggingProvider();

            var client       = new ShareFileClient(@"https://secure.sf-api.com/sf/v3/", configuration);
            var oauthService = new OAuthService(client, shareFileConfiguration.ClientId, shareFileConfiguration.ClientSecret);

            // Perform a password grant request.
            var oauthToken = await oauthService.PasswordGrantAsync(shareFileConfiguration.UserName, shareFileConfiguration.Password, shareFileConfiguration.SubDomain, shareFileConfiguration.ControlPlane);

            // Add credentials and update client with new BaseUri
            client.AddOAuthCredentials(oauthToken);
            client.BaseUri = oauthToken.GetUri();

            return(client);
        }
Example #11
0
        static void Main(string[] args)
        {
            //var redirectUri = new Uri("https://secure.sharefile.com/oauth/oauthcomplete.aspx");

            //var state = Guid.NewGuid().ToString();

            var sfClient = new ShareFileClient("https://ppgindustries.sharefile.com/share/view/66482373c0dc4c48/fob2b3c3-f8ec-4de8-893c-5a1b8d4d02c3");

            var oua = new OAuthService(sfClient, "k697344", "Nala200531+*");


            var oauthToken = oua.PasswordGrantAsync("k697344", "Nala200531+*", "", "");

            // Add credentials and update sfClient with new BaseUri
            sfClient.AddOAuthCredentials(oua);
            sfClient.BaseUri = oauthToken.GetUri();

            //var sesion = sfClient.Sessions.Login();

            //var user = sfClient.Users.Get().ExecuteAsync();

            //var folder = sfClient.Items.Get().ExecuteAsync();

            //var oauthService = new OAuthService(sfClient, "[client_id]", "[client_secret]");

            //var authorizationUrl = oauthService.GetAuthorizationUrl("sharefile.com", "code", "clientId", redirectUri.ToString(),
            //        state);

            string usuarioSharePoint  = "K697344";
            string passwordSharePoint = "Nala200531+*";

            string urlCompleto         = "https://ppgindustries.sharefile.com/share/view/66482373c0dc4c48/fob2b3c3-f8ec-4de8-893c-5a1b8d4d02c3";
            string pathArchivoCompleto = "\\\\10.104.175.150\\Campania\\WSCampania\\Reporte\\7f70795a-788f-4f8b-83dc-db81459b2c29.pdf";

            using (WebClient client = new WebClient())
            {
                client.Credentials = new NetworkCredential(usuarioSharePoint, passwordSharePoint);
                client.UploadFile(urlCompleto, "PUT", pathArchivoCompleto);
                client.DownloadFile("\\\\10.104.175.150\\Campania\\WSCampania\\Reporte", "0 Indice Gral Powder.xls");
            }
        }
Example #12
0
        private ShareFileClient PasswordAuthentication()
        {
            var shareFileConfiguration = _auditConfiguration.ShareFileConfiguration;

            var configuration = Configuration.Default();

            configuration.Logger = new DefaultLoggingProvider();

            var client       = new ShareFileClient(shareFileConfiguration.Url, configuration);
            var oauthService = new OAuthService(client, shareFileConfiguration.ClientId, shareFileConfiguration.ClientSecret);

            // Perform a password grant request.
            var oauthToken = oauthService.PasswordGrantAsync(
                shareFileConfiguration.UserName,
                shareFileConfiguration.Password,
                shareFileConfiguration.SubDomain,
                shareFileConfiguration.ControlPlane).Result;

            // Add credentials and update client with new BaseUri
            client.AddOAuthCredentials(oauthToken);
            client.BaseUri = oauthToken.GetUri();

            return(client);
        }