我现在使用以下链接对用户进行身份验证:
https://<instance>.-now.com/oauth_token?client_id=<client_key>&client_secret=<client_secret>&username=admin&password=admin
但是我无法得到结果。我得到的输出如下:
{
"error_description": "access_denied",
"error": "server_error"
}
我需要在 Powershell 脚本中使用 SNOW REST API 对用户进行身份验证。提前致谢..
最佳答案
使用 OAuth 的第一部分是获取访问 token ,第二部分是利用它从服务实例中获取数据(我已在代码中进行了注释,以便您可以找到每个部分并根据您的实例编辑变量) :
#For getting access token you can use this code:
$username = “admin”
$password = 'Zen123$$'
$ClientID = “62a88515890332007975e610a3216c62”
$ClientSecret = “pass@word1”
$RestEndpoint = ‘https://myinstance.service-now.com/oauth_token.do’
$body = [System.Text.Encoding]::UTF8.GetBytes(‘grant_type=password&username=’+$username+’&password=’+$password+’&client_id=’+$ClientID+’&client_secret=’+$ClientSecret)
$result = Invoke-RestMethod -Uri $RestEndpoint -Body $Body -ContentType ‘application/x-www-form-urlencoded’ -Method Post
$access_token = $result.access_token
#Once you have access token, you can utilize the invoke-restmethod to fetch data from servicenow :
$URI = ‘https://myinstance.service-now.com/api/now/table/incident?sysparm_limit=1’
$headers = @{“authorization” = “Bearer $access_token”}
$result = Invoke-RestMethod -Uri $URI -Headers $headers
$result
关于rest - 如何使用 powershell 脚本使用 SNOW OAuth REST API 对用户进行身份验证?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44240898/