46 lines
1.1 KiB
PowerShell
46 lines
1.1 KiB
PowerShell
|
|
|
|
Function Get-SectigoApiToken {
|
|
|
|
#[CmdletBinding()]
|
|
|
|
. $PSScriptRoot\..\Private\Set-Onload.ps1
|
|
[string]$tokenEndpoint = $AuthBaseAPIUrl + "/auth/realms/apiclients/protocol/openid-connect/token"
|
|
|
|
$clientId=$env:Sectigoclientid
|
|
$clientSecret=$env:SectigoclientSecret
|
|
|
|
if (-Not $clientid) {
|
|
$clientid=Read-Host "Please enter your clientid"
|
|
}
|
|
|
|
if (-Not $clientSecret) {
|
|
$clientSecret=Read-Host "Please enter your clientSecret"
|
|
}
|
|
|
|
Write-Verbose -Verbose "tokenEndpoint: $tokenEndpoint "
|
|
|
|
# Prepare the body for the token request
|
|
$body = @{
|
|
grant_type = "client_credentials"
|
|
client_id = $clientId
|
|
client_secret = $clientSecret
|
|
|
|
}
|
|
|
|
. $PSScriptRoot\..\Private\Set-Onload.ps1
|
|
|
|
# Request the access token
|
|
try {
|
|
$tokenResponse = Invoke-RestMethod -Uri $tokenEndpoint -Method Post -Body $body -ContentType "application/x-www-form-urlencoded"
|
|
$accessToken = $tokenResponse.access_token
|
|
$env:SectigoToken=$accessToken
|
|
if ($accesstoken) { Write-Verbose -Verbose 'Token Set $ENV:SectigoToken'}
|
|
|
|
}
|
|
catch {
|
|
Write-Error "Failed to obtain access token: $($_.Exception.Message)"
|
|
#exit 1
|
|
}
|
|
|
|
} |