Authenticating to REST API with AD authentication enabled

Hi all,

 

I am trying to authenticate against the REST API with basic authentication but we have NTLM enabled as well as the basic plugin in our environment.  Whenever I do this I am getting a username or password failure and a form to log into TeamCity.

 

Here is my code:

 

$teamCityCredential = get-credential
$teamCityHost = "https://teamcity.domain.com/"
$headers = @{
"Content-Type" = "text/plain";
}

$body = "true"
$api = "$($teamCityHost)httpAuth/app/rest/agents/name:my%20agent/authorized"
$response = Invoke-WebRequest -Uri $api -Headers $headers -Method Put -Body $body -Credential $teamCityCredential

 

When I run without credentials I get an unauthorized message whereas if I push the credentials I am getting a username/password failure so I think the creds are getting through.  I also tried creating the Authorization header in the script and get the same results.

 

I have seen some examples of using the .Net API to contact TeamCity but want to use pure PowerShell if possible.

 

Thanks,

Andrew.

0
1 comment

Hi Andrew,

passing the credentials should work also when you have NTLM enabled, assuming that you kept Basic HTTP authentication also enabled (it's mentioned in the REST API that you need it: https://confluence.jetbrains.com/display/TCD10/REST+API#RESTAPI-RESTAuthentication)

Remember to pass the credentials correctly, here are some powershell examples: https://confluence.jetbrains.com/display/TCD10/REST+API?focusedCommentId=74845195#comment-74845195

0

Please sign in to leave a comment.