Login to TeamCity server using REST API without passing credentials to URL

As an answer to the previous question, I asked: How to transfer the username and password in the TeamCity REST API , I would like to check something.

Can someone tell me if it is possible to access the TeamCity REST API in a more secure way and not pass the username and password to the URL?

It just seems crazy to me that passing the credentials in the URL is the only way, since it is so easy for the sniffer to access the URL and use the credentials themselves.

+5
source share
3 answers

, , , :

(/ntlmLogin.html) - NTLM.
cookie, TeamCity.
cookie API.

. https://github.com/eduaquiles/TeamCityNtlmApiWrapper , .

+8

- , .

TeamCity:

Rest API

http://devnet.jetbrains.net/message/5461520#5461520

, , HTTP-. NTLM, - , REST API.

, NTLM REST API. , , , .

+2

Eduardo Aquiles, TeamCity HTTP NTLM (HTTP- TeamCity 8.x NTLM), cookie (TCSESSIONID) URL/ntlmLogin.html API REST.

- , . PowerShell :

function Get-TeamCityNtlmAuthCookie()
{
    param( [string] $serverUrl )
    $url = "$serverUrl/ntlmLogin.html";
    $cookies = new-object System.Net.CookieContainer;
    $request = [System.Net.WebRequest]::Create($url);
    $request.CookieContainer = $cookies;
    $request.Credentials = [System.Net.CredentialCache]::DefaultNetworkCredentials;
    $request.PreAuthenticate = $true;
    $response = $request.GetResponse();
    return $cookies;
}

function Get-TeamCityBuildPinnedState()
{
    param( [string] $serverUrl, [string] $buildTypeId)
    # get a session cookie to use with the rest api
    $cookies = Get-TeamCityNtlmAuthCookie $serverUrl;
    # query the rest api using the session cookie for authentication
    $url = "$serverUrl/httpAuth/app/rest/builds/id:$buildTypeId/pin/";
    $request = [System.Net.WebRequest]::Create($url);
    $request.CookieContainer = $cookies;
    $response = $request.GetResponse();
    $stream = $response.GetResponseStream();
    $reader = new-object System.IO.StreamReader($stream);
    $text = $reader.ReadToEnd();
    $reader.Close();
    return [bool]::Parse($text);
}

$myServerUrl = "http://myTeamCityServer";
$myBuildId = "6";

$pinned = Get-TeamCityBuildPinnedState $myServerUrl $myBuildId;
write-host $pinned;

. , JetBrains, , TeamCity, 8.0.2 ( 27482).

+2

All Articles