Obtain REST API access in a user context
try {
$wellKnownResponse = Invoke-RestMethod -Method Get -Uri $wellKnownEndpoint
$tokenEndpoint = $wellKnownResponse.token_endpoint
$deviceCodeEndpoint = $wellKnownResponse.device_authorization_endpoint
} catch {
Write-Error "Error obtaining server information"
exit
}$body = "client_id=$clientId&scope=$([uri]::EscapeDataString($scope))"
try {
$deviceCodeResponse = Invoke-RestMethod -Method Post -Uri $deviceCodeEndpoint `
-ContentType "application/x-www-form-urlencoded" -Body $body
} catch {
Write-Error "Failed to obtain device code: $_"
exit
}
# Extract values from the response (field names may vary by provider)
$device_code = $deviceCodeResponse.device_code
$user_code = $deviceCodeResponse.user_code
$verification_uri = $deviceCodeResponse.verification_uri
$verification_uri_complete = $deviceCodeResponse.verification_uri_complete
$interval = 10 # in seconds
$expires_in = $deviceCodeResponse.expires_in # in seconds
# Provide a default interval if none was returned or if it's zero/null
if (-not $interval -or $interval -eq 0) {
$interval = 5
Write-Host "Interval not provided or invalid; defaulting to $interval seconds."
}
# Instead of instructing the user, open the browser to the verification_uri_complete
if ($verification_uri_complete) {
Write-Host "Opening browser for device authorization..."
Start-Process $verification_uri_complete
} else {
Write-Host "verification_uri_complete not provided. Please manually go to $verification_uri and enter the code: $user_code"
}See also
PreviousMove the Devolutions Server application to the default web site rootNextOffboard users from Devolutions Server
Last updated
Was this helpful?