SVN Repository Authentication using SharpSVN
Asked Answered
M

4

28

Can any one tell me how to authenticate users(SVN users) for a repository using SharpSVN Library. That repository should only be committed by those users. Thanks

Maddocks answered 23/6, 2010 at 6:34 Comment(0)
J
48

Use the Authenticate properties of SVNClient:

client.Authentication.Clear(); // Clear a previous authentication
client.Authentication.DefaultCredentials = new System.Net.NetworkCredential("user", "password");
Josettejosey answered 2/3, 2011 at 8:37 Comment(2)
This isn't working for me, is there some prerequisite for this?Dejesus
Only the SharpSVN library. Are you sure of your user name and password?Politesse
D
14
client.Authentication.ForceCredentials("user", "password");

For those of you who don't want to blow away your default credentials (if you're running TortoiseSVN on the same machine).

Diphosgene answered 28/3, 2013 at 16:24 Comment(1)
With this I can authenticate but it change my default credentials on TortoiseSVN.Boigie
T
10

You can also override SSL certificate errors by adding an event handler to SslServerTrustHandlers like this:

SVN_Conn.Authentication.SslServerTrustHandlers += new EventHandler<SharpSvn.Security.SvnSslServerTrustEventArgs>(SVN_SSL_Override);

static void SVN_SSL_Override(object sender, SharpSvn.Security.SvnSslServerTrustEventArgs e)
{
    e.AcceptedFailures = e.Failures;
    e.Save = true;
}
Toadfish answered 14/5, 2011 at 16:52 Comment(2)
Just so that it's been mentioned: Do not call 'client.authentication.clear()' after subscribing to the event, or otherwise it will not fire.Pauly
@Pauly Thank you, thank you, thank you! I was hung up on that point for hours today.Understrapper
B
4

In my case, the SVN server was running VisualSVN Server 3.5.3 with Integrated Windows Authentication enabled. Using SharpSvn 1.9004.3879.127, the SVN client tried to use Windows authentication even when I configured it with a username and password:

client = new SvnClient();
client.Authentication.Clear(); //Prevents saving/loading config to/from disk
client.Authentication.DefaultCredentials = new NetworkCredential("username", "password");

This resulted in the following error when the application code was run by a Windows user that didn't have access to the repository:

SvnRepositoryIOException: Unable to connect to a repository at URL 'https://mysvnserver/svn/reponame'

I fixed this by only allowing basic and digest authentication:

client = new SvnClient();
client.Configuration.SetOption("servers", "global", "http-auth-types", "basic;digest");
client.Authentication.Clear(); // Prevents saving/loading config to/from disk
client.Authentication.DefaultCredentials = new NetworkCredential("username", "password");
Bedivere answered 6/10, 2016 at 0:56 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.