Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Setting a new WebProxy still uses the old proxy #583

Open
rtrugman opened this issue Aug 12, 2019 · 6 comments
Open

Setting a new WebProxy still uses the old proxy #583

rtrugman opened this issue Aug 12, 2019 · 6 comments

Comments

@rtrugman
Copy link

Description of the Issue

Once you set a WebProxy and attempt authentication, setting a new proxy does not take effect. The code seems to still be using the old proxy.

Setting Proxy Address: proxyabc
Error: One or more errors occurred. An error occurred while sending the request. The remote name could not be resolved: 'proxyabc'.
Setting Proxy Address: proxyxyz
Error: One or more errors occurred. An error occurred while sending the request. The remote name could not be resolved: 'proxyabc'.

Versions Used

.NET 4.51:

Steps to Reproduce

Error Message, Including Stack Trace

@mattwiller
Copy link
Contributor

@rtrugman Could you provide a bit more context to help us understand the issue you're experiencing? It would be really helpful to see how you're trying to set the proxy for the SDK to use in your application, so we can start troubleshooting what might be going on.

@rtrugman
Copy link
Author

I have a .NET Forms UI program where the user can configure the Box settings including the proxy. If the user attempts authentication and then goes and changes the proxy, the next authentication attempt uses the first proxy setting. Does not matter is the first authentication succeeded or failed.

                //Set Proxy
                if ( theSettings.ProxyServer != String.Empty )
                {
                    Output( "Setting Proxy Address: {0}", theSettings.ProxyServer );

                    WebProxy theProxy = new WebProxy( theSettings.ProxyServer );

                    // Create a NetworkCredential object and associate it with the Proxy property of request object.
                    if ( theSettings.ProxyUserName != String.Empty )
                    {
                        Output( "Setting Proxy Credentials User: {0} Domain: {1}", theSettings.ProxyUserName, theSettings.ProxyDomain );

                        theProxy.Credentials = new NetworkCredential( theSettings.ProxyUserName, theSettings.ProxyPassword, theSettings.ProxyDomain );
                    }

                    config.WebProxy = theProxy;
                }
                else
                {
                    config.WebProxy = new WebProxy();
                }
            }

            // Create JWT auth using config file
            var boxJWT = new BoxJWTAuth( config );

            // Create admin client
            var adminToken = boxJWT.AdminToken();
            _boxclient = boxJWT.AdminClient( adminToken );

@mattwiller
Copy link
Contributor

@rtrugman To clarify, what do you mean when you say the application "changes the proxy"? In your code sample, it's hard to tell what the overall flow is; the code appears to just set the proxy once. Are you re-creating a new client with a new config each time?

@rtrugman
Copy link
Author

That's the code that gets executed each time the user authenticates with new settings. The user updates the settings and then the code in this method is called to authenticate. Here is the full method that's a WInForms link event.

private void linkLogOn_LinkClicked( object sender, LinkLabelLinkClickedEventArgs e )
    {
        this.listBox1.Items.Clear();
        this.Cursor = Cursors.WaitCursor;

        Output( "Connecting using config file : {0} ", this.txtConfigFile.Text );

        try
        {
            if (null != _boxclient)
            {
                _boxclient.Auth.LogoutAsync();
            }
            // Read in config file
            IBoxConfig config = null;
            using ( FileStream fs = new FileStream( this.txtConfigFile.Text, FileMode.Open ) )
            {
                config = BoxConfig.CreateFromJsonFile( fs );

                //Set Proxy
                if ( theSettings.ProxyServer != String.Empty )
                {
                    Output( "Setting Proxy Address: {0}", theSettings.ProxyServer );

                    WebProxy theProxy = new WebProxy( theSettings.ProxyServer );

                    // Create a NetworkCredential object and associate it with the Proxy property of request object.
                    if ( theSettings.ProxyUserName != String.Empty )
                    {
                        Output( "Setting Proxy Credentials User: {0} Domain: {1}", theSettings.ProxyUserName, theSettings.ProxyDomain );

                        theProxy.Credentials = new NetworkCredential( theSettings.ProxyUserName, theSettings.ProxyPassword, theSettings.ProxyDomain );
                    }

                    config.WebProxy = theProxy;
                }
                else
                {
                    config.WebProxy = new WebProxy();
                }
            }

            // Create JWT auth using config file
            var boxJWT = new BoxJWTAuth( config );

            // Create admin client
            var adminToken = boxJWT.AdminToken();
            _boxclient = boxJWT.AdminClient( adminToken );

            // Create Managed User client
            var userId = this.txtUserId.Text;
            if ( !String.IsNullOrEmpty( userId ) )
            {
                var auth = new Box.V2.Auth.OAuthSession( adminToken, "NOT NEEDED", 10, "bearer" );

                var userClient = new BoxClient( config, auth, asUser: userId );

                _boxclient = userClient;
               
            }
            if ( chkJSON.Checked )
            {
                string jsonData = Newtonsoft.Json.JsonConvert.SerializeObject( _boxclient );
                Output( "Json: {0}", jsonData );
            }
            Output( "Authentication Successful." );

            this.linkLogout.Enabled = true;

        }
        catch ( Exception ex )
        {
            Output( "Error: " + ex.MessageWithInner() );
            Output( ex.StackTrace );
        }
        Output( String.Empty );
        this.Cursor = Cursors.Default;
    }

@mattwiller
Copy link
Contributor

mattwiller commented Aug 14, 2019

@rtrugman Ah, I think I see what the issue is — the SDK uses a shared, static pool of HttpClient instances internally across all SDK clients; these are not re-initialized when the proxy is updated. I'll add this to our backlog to fix (SDK-1019), but you're of course welcome to make a PR of your own if you need the fix sooner than we can get to it. Either way, I'll keep this issue open to track progress, and we'll update here when we have a fix ready.

@PJSimon PJSimon added the bug label Mar 4, 2020
@stale
Copy link

stale bot commented Dec 19, 2022

This issue has been automatically marked as stale because it has not been updated in the last 30 days. It will be closed if no further activity occurs within the next 7 days. Feel free to reach out or mention Box SDK team member for further help and resources if they are needed.

@stale stale bot added the stale label Dec 19, 2022
@mwwoda mwwoda added dontstale and removed stale labels Dec 20, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants