Automatically generate a new Installation Access Token from On-Premise Orchestrator - Identity Server

How to automatically generate a new Installation Access Token from the On-premise Orchestrator?

Approach 1 – Powershell:

Copy and paste into a text editor and save with the .ps1 extension.

$orchstrUrl = “https://xxxxxxxxxxx”

$antif = $orchstrUrl + "/identity/api/antiforgery/generate"

$webresponse = Invoke-WebRequest -Uri $antif -Method Get -ContentType "application/json" -UseBasicParsing -Session websession

$websession.Cookies.GetCookies($antif)[1].Name = "XSRF-TOKEN"

$login = $orchstrUrl+ "/identity/api/Account/Login"

$user = "admin"

$password = "1qazXSW@"

$dataLogin = @{

 tenant = "host"

 partitionName = "host"

 usernameOrEmail = $user        

 password = $password        

 rememberLogin = $true    

} | ConvertTo-Json

$temp = $websession.Cookies.GetCookies($antif)[1].Value

$websession.Headers.'X-XSRF-TOKEN' = $temp

$webresponse2 = Invoke-WebRequest -Uri $login -Method Post -Body $dataLogin -ContentType "application/json" -WebSession $websession

$tokenUrl = $orchstrUrl+"/identity/api/Account/ClientAccessToken"

$webresponse3 = Invoke-WebRequest -Uri $tokenUrl -Method Get -ContentType "application/json" -WebSession $websession

#token is here

$webresponse3.Content

Approach 2 – Bash Script:

Copy and paste into a text editor and save with .sh, .csh, or ksh file extension.

#!/bin/bash

# Base URL of your web site.

orchstrUrl="https://*********"

antif=$orchstrUrl"/identity/api/antiforgery/generate"

login=$orchstrUrl"/identity/api/Account/Login"

tokenUrl=$orchstrUrl"/identity/api/Account/ClientAccessToken"

dataLogin='{

   "tenant": "host",

   "partitionName": "host",

   "usernameOrEmail": "admin",

   "password": "******",

   "rememberLogin": true

}'

cookie_file="cookfile.txt"

cookie_file_new="cookfile_new.txt"

# Get token and construct the cookie, save the returned token.

cookeResponse=$(curl -c $cookie_file --request GET "$antif" )



sed 's/XSRF-TOKEN-IS/XSRF-TOKEN/g' $cookie_file > $cookie_file_new

token=$(cat $cookie_file_new | grep XSRF-TOKEN | cut -f7 -d$'\t')

echo $token

# Authentication. POST to $login_url with the token in header "X-CSRF-Token: $token".

loginResponse=$(curl -H "X-XSRF-TOKEN: $token" -c $cookie_file_new -b $cookie_file_new -d "$dataLogin" --request POST "$login" -H "Content-Type: application/json")

tokenResponse=$(curl -H "X-XSRF-TOKEN: $token" -b $cookie_file_new "$tokenUrl" -H "Content-Type: application/json")

# tokenResponse contains identity token

echo $tokenResponse