Skip to content
This repository has been archived by the owner on Feb 12, 2019. It is now read-only.

Authenticate with windows domain #103

Open
pascalzieglerenvision opened this issue Jun 15, 2016 · 1 comment
Open

Authenticate with windows domain #103

pascalzieglerenvision opened this issue Jun 15, 2016 · 1 comment

Comments

@pascalzieglerenvision
Copy link

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
Copy link

medboz commented Jul 12, 2016

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.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants