How to navigate directly into a webpage bypassing keycloak login page using powershell script?

148 views Asked by At

I'm trying to navigate directly into my item page (by provided item ID). I can generate access token using client id and client secret. But even though I pass it through header, it responds with the keycloak login page.

My sample PowerShell script is as below.

$TokenEndpoint = "$server_location/auth/realms/$key_cloak_client/protocol/openid-connect/token"
$itemID = 100

$OauthTokensClient = Invoke-RestMethod -Uri $TokenEndpoint -Method POST -Body @{
   grant_type   = 'client_credentials'
   client_id    = <Client_ID>
   client_secret = <Client_Secret>
   scope        = 'openid profile'
}

$AccessTokenClient = $OauthTokensClient.access_token
$HeaderClient = @{"Accept" = "application/json" ; "authorization" = "Bearer $AccessTokenClient"}

$Result = Invoke-WebRequest -Uri "$server_location/item/?item_id=$itemID" -Header $HeaderClient
"$Result"

$Result prints contents on keycloak login page instead of my item page content. Please help or shed some lite on correct path to archive this task.

0

There are 0 answers