Skip to content
Documentation
Updated 6 minutes to read
Markdown

Call the Nodinite Web API with Windows Authentication

Section titled “ Call the Nodinite Web API with Windows Authentication”

When Nodinite uses Windows Authentication, the Web API accepts the Windows identity of the caller (Kerberos or NTLM). A script that runs as a domain user or service account doesn't need a token: the HTTP client negotiates authentication with IIS, and Nodinite grants access based on the Windows account or its Windows AD Groups and their Roles.

Use this guide when your Nodinite environment runs in Windows Authentication mode. When it runs in OpenID Connect / OAuth 2.0 mode, use Call the Web API with OAuth 2.0 Client Credentials instead.

graph LR Script["fa:fa-terminal Script or service
runs as a Windows account"] -->|Kerberos / NTLM| IIS["fa:fa-globe IIS"] IIS --> API["fa:fa-cloud-sun Web API"] API --> Access["fa:fa-user-shield User or Windows AD Group
mapped to a Role"] API --> DB["fa:fa-database Databases"]

The script runs as a Windows account. IIS authenticates it, and Nodinite maps the account, or a Windows AD Group it belongs to, to a Role.

Approach When to use Examples below
Current Windows identity (integrated) The script runs on a domain-joined Windows host as a user or service account. No password in the script. PowerShell, Python (Windows), C#
Explicit credentials (NTLM) The script runs on Linux, in a container, or as another account. Read the password from a secret store. Python (Linux), Node.js
  • Nodinite runs in Windows Authentication mode, set for the environment in the Nodinite Portal (Auth step).
  • The Windows account that runs the script is added as a User, or belongs to a Windows AD Group, with a suitable Role.
  • You know the Web API base URL of your environment. The examples use <webapi-base-url>, for example https://nodinite.contoso.com:40001. The port is set for each environment in the Nodinite Portal (Servers step). To check it, add /scalar and open it in your browser. See Find the base URL.

Each example reads the Integrations in the Repository Model and prints the first Integration Id.

Use Invoke-RestMethod with -UseDefaultCredentials.

PowerShell 7 as a Windows account: a search for the Contoso Integrations, five per page; without credentials the Web API answers 401 with WWW-Authenticate Negotiate; with -UseDefaultCredentials the five Contoso Integrations come back as JSON, animated walkthrough (7.12)
Animated walkthrough: PowerShell 7 runs as a Windows account on a server in the domain. The same search for the Contoso Integrations first runs without credentials and gets 401 with WWW-Authenticate: Negotiate. With -UseDefaultCredentials, the Windows identity signs in and the five Integrations come back as JSON.

Terminal window
$nodiniteWebApiUrl = "<webapi-base-url>/api"
$getResponse = Invoke-RestMethod -Uri "$nodiniteWebApiUrl/integrations" -Method Get -UseDefaultCredentials
$getResponse.Collection.Items[0].Data.IntegrationId

Example: Retrieve the first Integration Id with the current Windows identity.

requests-negotiate-sspi uses the Windows SSPI interface and the current Windows identity. Install the dependencies first: pip install requests requests-negotiate-sspi.

import requests
from requests_negotiate_sspi import HttpNegotiateAuth
url = "<webapi-base-url>/api/integrations"
# Uses the current Windows identity (Kerberos/NTLM negotiation)
response = requests.get(url, auth=HttpNegotiateAuth(), timeout=30)
response.raise_for_status()
print(response.json()["Collection"]["Items"][0]["Data"]["IntegrationId"])

Example: Retrieve the first Integration Id with the current Windows identity.

SSPI isn't available outside Windows, but NTLM works cross-platform with a username and password. Install the dependencies first: pip install requests requests-ntlm.

import os
import requests
from requests_ntlm import HttpNtlmAuth
url = "<webapi-base-url>/api/integrations"
# Read credentials from environment variables - never hardcode secrets
username = os.environ["NODINITE_USERNAME"] # e.g. "DOMAIN\\serviceaccount"
password = os.environ["NODINITE_PASSWORD"]
response = requests.get(url, auth=HttpNtlmAuth(username, password), timeout=30)
response.raise_for_status()
print(response.json()["Collection"]["Items"][0]["Data"]["IntegrationId"])

Example: Retrieve the first Integration Id from a Linux host with NTLM.

HttpClientHandler with UseDefaultCredentials sends the current Windows identity.

using System.Text.Json;
using var handler = new HttpClientHandler { UseDefaultCredentials = true };
using var http = new HttpClient(handler) { BaseAddress = new Uri("<webapi-base-url>/") };
var json = await http.GetStringAsync("api/integrations");
using var doc = JsonDocument.Parse(json);
var firstIntegration = doc.RootElement
.GetProperty("Collection").GetProperty("Items")[0]
.GetProperty("Data").GetProperty("IntegrationId");
Console.WriteLine(firstIntegration);

Example: Retrieve the first Integration Id with the current Windows identity.

This example uses httpntlm. Run npm install httpntlm first.

const httpntlm = require('httpntlm');
httpntlm.get({
url: '<webapi-base-url>/api/integrations',
username: process.env.NODINITE_USERNAME,
password: process.env.NODINITE_PASSWORD,
domain: process.env.NODINITE_DOMAIN
}, (err, res) => {
if (err) return console.error(err);
const jsonBody = JSON.parse(res.body);
console.log(`First Integration Id: ${jsonBody.Collection.Items[0].Data.IntegrationId}`);
});

Example: Retrieve the first Integration Id with explicit Windows credentials.

Symptom Fix
401 from the Web API First check that the call sends Windows credentials: -UseDefaultCredentials in PowerShell, UseDefaultCredentials = true in C#. A call without them gets 401 with WWW-Authenticate: Negotiate. Then check that the account is a domain account that IIS accepts, and that the host and URL match the SPN when you use Kerberos. See HTTP SPN for IIS.
200 but empty results The account is authenticated but has no access to the data. Check its Roles.
Works interactively, fails as a scheduled task The task runs as another account. Give that service account access in Nodinite.

...

Version:
Release date: N/A
Loading...

Explore Nodinite for 30 days – completely free

  • Find out why this is the leading O&M software
  • Prove your business case
  • Test the self-service for the business side

Loading...

See how Nodinite resolves your technical issues, in a LIVE Demo!

Once you submit this request:

  • We will give you a short call to understand the issues you want to tackle.
  • Understand solutions you have tried and why were you not happy with them.
  • Book a convenient slot for a LIVE demo!

Loading...