
Los usuarios pueden automatizar el proceso de autorización mientras utilizan la API de NinjaRMM desde aquí,https://oc.ninjarmm.com/apidocs-beta/authorization/overview.
El módulo PowerShell, PSAuthClient (https://github.com/alflokken/PSAuthClient),le ayudará con la automatización.
Utilice el siguiente código para empezar. En primer lugar, deberá crear un token API en el portal. Asegúrese de anotar el URI de redireccionamiento y el ámbito, y actualice las variables siguientes para reflejarlos. Tenga en cuenta la última barra inclinada «/» al final de la dirección localhost.
También deberá actualizar el URI ninja para que coincida con su región.
Install-Module PSAuthClient -Confirm:$false
Import-Module PSAuthClient
$clientId = ''
$clientSecret = ''
$redirectUri = 'https://localhost/'
$scope = 'monitoring offline_access'
$custom = @{
"client_secret" = $clientSecret
}
$authParams = @{
Uri = "https://oc.ninjarmm.com/ws/oauth/authorize"
Redirect_uri = $redirectUri
Client_id = $clientId
Scope = $scope
UsePkce = $false
CustomParameters = $custom
}
$auth = Invoke-OAuth2AuthorizationEndpoint @authParams -verbose
$authCode = $auth.code
$tokenParams = @{
uri = 'https://oc.ninjarmm.com/ws/oauth/token'
redirect_uri = $redirectUri
client_secret = $clientSecret
code = $authCode
client_id = $clientId
}
$token = Invoke-OAuth2TokenEndpoint @tokenParams