Git Product home page Git Product logo

Comments (6)

rhymeswithmogul avatar rhymeswithmogul commented on May 24, 2024

Sadly, no. If they've turned that off, then I’ll need to research and implement the v2 API.

from ninjarmm-powershell.

xasz avatar xasz commented on May 24, 2024

Found any? I am trying to use the API v2 with some Powershell, but cannot get any OAUTH work. NinjaRMM could not provide any example for me until now. Anyone of u gotten any further?

from ninjarmm-powershell.

rhymeswithmogul avatar rhymeswithmogul commented on May 24, 2024

I did not. Since then, I've changed jobs, and I no longer have access to NinjaRMM. I'm going to freeze this project unless another maintainer comes along. I apologize.

from ninjarmm-powershell.

dkattan avatar dkattan commented on May 24, 2024

I did not. Since then, I've changed jobs, and I no longer have access to NinjaRMM. I'm going to freeze this project unless another maintainer comes along. I apologize.

Hey @rhymeswithmogul I'm happy to take it over.

I made progress with OAuth2 yesterday @xasz

Go into your Ninja instance and under Configuration -> Integrations -> API click Add

image

image

The following code will open your browser and bring you to a consent screen that you'll have to consent to once, and upon consent will redirect to the URL provided https://localhost:8080 in this case, and in the URL params you'll find the tokens you need to actually perform the API calls.

The next steps would be to store those tokens somewhere secure, most importantly the refresh_token, and have some code that periodically refreshes the refresh_token so you have access forever. I think I read the default refresh_token lifetime for Ninja is 30 days.

The refresh_token itself isn't used to access the APIs, instead it can be traded for an access_token by posting to the /oauth/token endpoint. I haven't tried that yet, but I think it will be trivial.

function New-HttpQueryString
{
    [CmdletBinding()]
    param 
    (
        [Parameter(Mandatory = $true)]
        [String]
        $Uri,

        [Parameter(Mandatory = $true)]
        [Hashtable]
        $QueryParameter
    )
    # Add System.Web
    Add-Type -AssemblyName System.Web
    
    # Create a http name value collection from an empty string
    $nvCollection = [System.Web.HttpUtility]::ParseQueryString([String]::Empty)
    
    foreach ($key in $QueryParameter.Keys)
    {
        $nvCollection.Add($key, $QueryParameter.$key)
    }
    
    # Build the uri
    $uriRequest = [System.UriBuilder]$uri
    $uriRequest.Query = $nvCollection.ToString()
    
    return $uriRequest.Uri.OriginalString
}

Function Authorize-NRMM
{
    Param ($applicationId,$secret,$redirectUrl, 
    [Parameter(Mandatory)]
    [ValidateSet("monitoring","management", "offline_access")]
    [string[]]$scopes)
    $RequestAccessTokenUri = "$($BaseUrl)/oauth/authorize" 
    $Params = @{response_type="code";client_id=$applicationId;client_secret=$Secret;}   
    #$RequestAccessTokenUri += "?response_type=code&client_id=$($applicationId)&client_secret=$($Secret)"
    if($redirectUrl)
    {
        $Params.redirect_uri = $redirectUrl
    }
    if($scopes)
    {
        $Params.scope = $scopes -join " "
    }
    $Uri = New-HttpQueryString -Uri $RequestAccessTokenUri -QueryParameter $Params
    $contentType = 'text/html'
    try
    {
        Start $Uri        
        return $Token    
    }
    catch { throw }
}

$AuthorizeResponse = Authorize-NRMM -applicationId $ClientId -secret $Secret -redirectUrl https://localhost:8080/ -scopes monitoring,offline_access
$AuthorizeResponse
return 

from ninjarmm-powershell.

dkattan avatar dkattan commented on May 24, 2024

Also, it appears they have brought back "Legacy API keys" in the UI so this issue can be closed:

image

from ninjarmm-powershell.

rhymeswithmogul avatar rhymeswithmogul commented on May 24, 2024

@dkattan: Message sent! If you want to keep this project alive, I can't really do the NinjaRMM stuff anymore, but I'll gladly help you out with the PowerShell side of things.

from ninjarmm-powershell.

Related Issues (2)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.