-2

I want to access Thycotic Secret Server Rest APIS,But when I try to authenticate and get token,I am getting html response,instead of token?Any suggestions

sha
  • 1
  • 1

2 Answers2

0

Sorry this is very late, but I have a base auth script that I use and just craft my API call around. Hope it helps. Below is an example of a GET request for a secret

try {
    $site = "https://company.secretservercloud.com"
    $creds = @{
        username   = "user1"
        password   = "password1"
        grant_type = "password"
    }

    $response = Invoke-RestMethod "$site/oauth2/token" -Method Post -Body $creds 
    $token = $response.access_token
    
    $headers = New-Object "System.Collections.Generic.Dictionary[[String],[String]]"
    $headers.Add("Authorization", "Bearer $token")
    #======================================
    #=======PASTE POWERSHELL HERE=========
    #=====================================
    $response = Invoke-RestMethod $site'/api/v1/secrets/1662' -Method 'GET' -Headers $headers
    $response = $response | ConvertTo-Json
    write-host $response
    #======================================
    #=======PASTE POWERSHELL HERE=========
    #=====================================
}
catch [System.Net.WebException] {
    Write-Host "----- Exception -----"
    Write-Host  $_.Exception
    Write-Host  $_.Exception.Response.StatusCode
    Write-Host  $_.Exception.Response.StatusDescription
    $result = $_.Exception.Response.GetResponseStream()
    $reader = New-Object System.IO.StreamReader($result)
    $reader.BaseStream.Position = 0
    $reader.DiscardBufferedData()
    $responseBody = $reader.ReadToEnd()

    Write-Host $responseBody
}
Tyler2P
  • 2,324
  • 26
  • 22
  • 31
Ayyub
  • 33
  • 3
0

you're hitting the wrong url/api end. remove 'SecretServer' from the uri and try again. so the uri should look below:

"https://COMPANY_NAME.secretservercloud.com/oauth2/token"

if it helps, you can also use the below powershell script to get the token.

function Get-ThycoticToken {

[cmdletbinding()]   
Param (     
    [Parameter(Mandatory=$true,ValueFromPipelineByPropertyName=$true,Position=0)]
    [System.String]$BaseUrl,

    [Parameter(Mandatory=$false,ValueFromPipelineByPropertyName=$true,Position=1)]
    [System.String]$UserName,

    [Parameter(Mandatory=$false,ValueFromPipelineByPropertyName=$true,Position=1)]
    [System.String]$Password
)


$OauthApi = "$BaseUrl/oauth2/token"




$payload = @{
"Accept" = "application/json"
"username" = $UserName
"password" = $Password
"grant_type" = "password"
}


$response = Invoke-RestMethod $OauthApi -Method Post -Body $payload


$token = $response.access_token

$token

}

Abul Ahmed
  • 26
  • 1