stack72 / TeamCitySharp

No Longer Maintained - please use https://github.com/mavezeau/TeamCitySharp
Other
200 stars 165 forks source link

Authenticate with windows domain #103

Open pascalzieglerenvision opened 8 years ago

pascalzieglerenvision commented 8 years ago

Hey,

How would y'all implement it if you want to authenticate per windows user name + password without the need to acually let the user type in the information everytime. My code trying it on my own (without teamcitysharp) which failed:

var webRequest = (HttpWebRequest)WebRequest.Create("URL"); NetworkCredential creditsDefault = CredentialCache.DefaultNetworkCredentials; NetworkCredential myCredits = new NetworkCredential("pascal.ziegler", "Password");

        Console.WriteLine("Default Credits: " + creditsDefault.Domain + creditsDefault.UserName + creditsDefault.Password);
        Console.WriteLine("My Credits: " + myCredits.Domain + myCredits.UserName + myCredits.Password);

        webRequest.Credentials = creditsDefault;
        webRequest.GetResponse();

using myCredits works fine. i get access and get the information in return. using creditsDefault gives me a 401 access denied. the server log seems to be able to read my user name but not my password: [2016-06-14 15:10:34,797] INFO [:37cc; http-nio-8080-exec-4471] - Login for username "pascal.ziegler" failed, see details below [2016-06-14 15:10:34,797] INFO [:37cc; http-nio-8080-exec-4471] - Login for user "pascal.ziegler" failed for module "jetbrains.buildServer.serverSide.impl.auth.SpecialUsersLoginModule": jetbrains.buildServer.serverSide.auth.TeamCityFailedLoginException: Not a special user or login as special user is not allowed [2016-06-14 15:10:34,797] INFO [:37cc; http-nio-8080-exec-4471] - Login for user "pascal.ziegler" failed for module "jetbrains.buildServer.serverSide.impl.auth.NTDomainLoginModule": com.sun.jna.platform.win32.Win32Exception: The user name or password is incorrect.

medboz commented 8 years ago

Hello pascal, You can use HttpClient instead of WebClient.

var handler = new HttpClientHandler() { UseDefaultCredentials = true }; httpClient = new HttpClient(handler);

You can find many examples when googling.