---
title: Call the Nodinite Web API with OAuth 2.0 Client Credentials
description: Call the Nodinite Web API from a script, service, scheduled job, or CI/CD pipeline without a signed-in user. Register a client in Microsoft Entra ID, map its app role to a Nodinite Role, get an OAuth 2.0 access token, and send it as a bearer token.
---

# :fa-key: Call the Nodinite Web API with OAuth 2.0 Client Credentials

When :Nodinite: runs in **OpenID Connect / OAuth 2.0** mode, every [Web API][] request needs a **bearer access token**. This guide shows how to let another application call the Web API **without a signed-in user**: an integration, a background service, a scheduled job, or a **CI/CD** pipeline.

The calling application uses the OAuth 2.0 **client credentials** flow: it proves who it is with its own client ID and secret (or certificate), gets an access token from your identity provider, and sends that token with each request.

The steps use **Microsoft Entra ID** (formerly Azure AD). For Keycloak, Okta, and other providers, see [Other identity providers](#other-identity-providers).

>[!TIP]
>The Web API is **deterministic**: the same request with the same permissions returns the same result every time. That makes it the right choice for scripts and pipelines. To **ask questions** about your integration landscape in natural language from VS Code, Claude Desktop, or similar tools, use the [MCP Endpoint][] instead. See [Web API or MCP Endpoint?][Web API or MCP Endpoint].

## :fa-diagram-project: Understanding the Client Credentials Flow

<div class="mermaid">
sequenceDiagram
    participant C as Client application
    participant IDP as Identity provider (Entra ID)
    participant API as Nodinite Web API
    C->>IDP: 1. Request access token (client ID + secret)
    IDP-->>C: 2. Access token with app role claim
    C->>API: 3. HTTP request + Authorization: Bearer token
    API->>API: 4. Map role claim to Claim, Policy, Role
    API-->>C: 5. Response, limited by the Nodinite Role
</div>

*The client gets a token from the identity provider and sends it to the Web API. :Nodinite: maps the role claim in the token to a Nodinite Role, which decides what the client can see and do.*

### :fa-puzzle-piece: Key Components

| Component | Where | Role in the flow |
| --- | --- | --- |
| **Client app registration** | Entra ID | The identity of the calling system. Holds the client ID and the secret or certificate. One per calling system. |
| **Nodinite Web API app registration** | Entra ID | The protected API, created during [installation][Install Nodinite v7 - OpenID - EntraID]. Defines the **app roles** that clients can be granted. |
| **App role** (for example `Nodinite.Integration`) | Entra ID | Sent in the token as a `roles` claim. Tells :Nodinite: which kind of client is calling. |
| **[Claim][Claims] → [Policy][Policies] → [Role][Roles]** | :Nodinite: [Web Client][] | Maps the app role to a Nodinite Role with exactly the permissions the client needs. |
| **Access token** | Runtime | Short-lived (about one hour). Sent as `Authorization: Bearer <token>`. |

### :fa-code-compare: Dedicated Client vs Installation Client

The [installation guide][Install Nodinite v7 - OpenID - EntraID] creates a `NodiniteInstallationClient` with the `AppRole_WebApi_all` app role. Don't reuse it for your own scripts.

| | Dedicated client (this guide) | Installation client |
| --- | --- | --- |
| Purpose | Your script, service, or pipeline | :Nodinite: installation and internal services |
| Permissions | Only what the client needs, through its own Nodinite Role | Full access |
| Revoke or rotate | On its own, without affecting :Nodinite: | Affects the :Nodinite: installation |
| Audit | Each calling system has its own identity in [Log Audits][] | All callers look the same |

## :fa-clipboard-check: Prerequisites

* :Nodinite: is installed in OpenID/OAuth mode, and users can sign in to the [Web Client][]. See [Install Nodinite v7 - OpenID][].
* You know these values for your environment:
  * The **Tenant ID** of your Entra ID tenant.
  * The **Application ID URI** of the :Nodinite: Web API app registration, for example `api://nodinite-prod-webapi`. Tokens must be issued for the Web API **Audiences** value set in the :Nodinite: Portal, in the [Auth step, Web API][Portal Web API Audiences].
  * The **Web API base URL** of your environment: scheme, host, and port of the environment's Web API site, 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][Base URL].
* You can create app registrations and grant admin consent in Entra ID.
* You are a :Nodinite: administrator.

## :fa-list-ol: Step 1: Register the Client App

1. In the **Microsoft Entra admin center**, go to **Identity → Applications → App registrations → New registration**.
2. **Name**: a descriptive name, for example `nodinite-prod-client-<system>`. Use one registration per calling system, so that you can audit and revoke each one on its own.
3. **Supported account types**: *Accounts in this organizational directory only*.
4. **Redirect URI**: leave it empty.
5. Select **Register** and note the **Application (client) ID**.
6. Open **Certificates & secrets** and create a **client secret**, or upload a certificate.
7. Store the secret in a secret store, such as Azure Key Vault. Never put it in source code. Note the expiry date: when the secret expires, the client stops working.

## :fa-list-ol: Step 2: Give the Client Permission to Call the Web API

### Add an App Role to the Nodinite Web API

Skip this if a suitable app role already exists.

1. Open the **Nodinite Web API** app registration → **App roles → Create app role**.
2. Fill in the fields:
   * **Display name**: `Nodinite Integration`
   * **Allowed member types**: **Applications**
   * **Value**: `Nodinite.Integration`. You use this value again in Step 3.
   * **Description**: `Applications calling the Nodinite Web API`
3. Select **Apply**.

>[!TIP]
>Create one app role per access level, for example `Nodinite.Integration.Read` and `Nodinite.Integration.Repository`, when different clients need different permissions in :Nodinite:.

### Assign the App Role to the Client

1. Open the **client** app registration → **API permissions → Add a permission → My APIs**, and select the **Nodinite Web API**.
2. Choose **Application permissions** and select `Nodinite.Integration`.
3. Select **Add permissions**, then **Grant admin consent for &lt;tenant&gt;**.

## :fa-list-ol: Step 3: Give the Client Access in Nodinite {#step-3-give-the-client-access-in-nodinite}

The app role from Step 2 is what :Nodinite: uses to decide what the client can access. Map it to a Nodinite Role:

1. In the :Nodinite: Web Client, go to **Administration → [Access Management][] → [Claims][]** and create a Claim:
   * **Key**: `http://schemas.microsoft.com/ws/2008/06/identity/claims/role`
   * **Value**: `Nodinite.Integration`. Use the exact **Value** from Step 2.
2. Go to **Administration → Access Management → [Policies][]**, create a Policy (for example `Integration clients`), and add the Claim to it.
3. Go to **Administration → Access Management → [Roles][]**. Add the Policy to a Role that has only the permissions the client needs, for example read access to specific [Monitor Views][]. Create a new Role if necessary.

>[!WARNING]
>Don't add clients to the **Administrators** Role unless they really need full administrative access.

>[!NOTE]
>:Nodinite: picks up changes to Claims, Policies, and Roles within about 15 seconds, also for a client that already has a valid token. A change in the identity provider, such as a new app role assignment, needs a new token, because the claim is in the token.

## :fa-list-ol: Step 4: Get a Token and Call the Web API

Replace these placeholders in the examples:

| Placeholder | Value |
| --- | --- |
| `<tenant-id>` | Your Entra ID Tenant ID |
| `<client-id>` | The Application (client) ID from [Step 1](#fa-list-ol-step-1-register-the-client-app) |
| `<client-secret>` | The client secret from [Step 1](#fa-list-ol-step-1-register-the-client-app). Read it from a vault or environment variable at run time. |
| `<api-app-id-uri>` | The :Nodinite: [Web API][]'s Application ID URI, for example `api://nodinite-prod-webapi` |
| `<webapi-base-url>` | The [Web API base URL][Base URL], for example `https://nodinite.contoso.com:40001` |

The token request always uses the scope `<api-app-id-uri>/.default`. Each example calls `api/Users/whoami`, which returns the identity of the caller and its Nodinite Roles. Once that works, call any operation you find in Scalar or Swagger (see [Find Operations in Scalar or Swagger][Find Operations]). To change [System Parameters][Web API System Parameters] from a pipeline, the client needs the Administrator Role, so use a separate client for that job only (see the warning in [Step 3](#step-3-give-the-client-access-in-nodinite)).

![PowerShell 7 in a pipeline against a Web API in OAuth 2.0 mode: whoami without a token gets 401; the client credentials body with the client ID and the secret from an environment variable; an access token from the identity provider's token endpoint; whoami with the Bearer token lists the Role Contoso: Warehouse Staff; api/LogViews returns only that Role's Log View as JSON, animated walkthrough (7.12)][1]  
*Animated walkthrough: a pipeline script calls a Web API in OAuth 2.0 mode. Without a token, `whoami` gets `401`. The script gets an access token with the client credentials grant, reading the secret from an environment variable, and `whoami` with the bearer token lists the Role **Contoso: Warehouse Staff**. `api/LogViews` then returns only what that Role may read. The identity provider here is Keycloak; with Entra ID, the token request adds `scope=<api-app-id-uri>/.default`, as in the examples below.*  

### :fa-terminal: curl

```bash
TOKEN=$(curl -s -X POST "https://login.microsoftonline.com/<tenant-id>/oauth2/v2.0/token" \
  -d "grant_type=client_credentials" \
  -d "client_id=<client-id>" \
  -d "client_secret=<client-secret>" \
  -d "scope=<api-app-id-uri>/.default" | jq -r .access_token)

curl -H "Authorization: Bearer $TOKEN" "<webapi-base-url>/api/Users/whoami"
```

### :fa-scroll: PowerShell

```powershell
$body = @{
    grant_type    = 'client_credentials'
    client_id     = '<client-id>'
    client_secret = '<client-secret>'
    scope         = '<api-app-id-uri>/.default'
}
$token = (Invoke-RestMethod -Method Post `
    -Uri 'https://login.microsoftonline.com/<tenant-id>/oauth2/v2.0/token' `
    -Body $body).access_token

Invoke-RestMethod -Uri '<webapi-base-url>/api/Users/whoami' `
    -Headers @{ Authorization = "Bearer $token" }
```

### :fa-code: C# (.NET) with MSAL

Package: `Microsoft.Identity.Client`.

```csharp
using System.Net.Http.Headers;
using Microsoft.Identity.Client;

var app = ConfidentialClientApplicationBuilder
    .Create("<client-id>")
    .WithClientSecret("<client-secret>")          // or .WithCertificate(cert)
    .WithAuthority("https://login.microsoftonline.com/<tenant-id>")
    .Build();

// MSAL caches the token and renews it when needed. Keep 'app' as a singleton.
var result = await app
    .AcquireTokenForClient(["<api-app-id-uri>/.default"])
    .ExecuteAsync();

using var http = new HttpClient { BaseAddress = new Uri("<webapi-base-url>/") };
http.DefaultRequestHeaders.Authorization =
    new AuthenticationHeaderValue("Bearer", result.AccessToken);

var whoAmI = await http.GetStringAsync("api/Users/whoami");
```

### :fab fa-python: Python

Install the dependency first: `pip install requests`.

```python
import os
import requests

token_response = requests.post(
    "https://login.microsoftonline.com/<tenant-id>/oauth2/v2.0/token",
    data={
        "grant_type": "client_credentials",
        "client_id": "<client-id>",
        "client_secret": os.environ["NODINITE_CLIENT_SECRET"],
        "scope": "<api-app-id-uri>/.default",
    },
    timeout=30,
)
token_response.raise_for_status()
access_token = token_response.json()["access_token"]

response = requests.get(
    "<webapi-base-url>/api/Users/whoami",
    headers={"Authorization": f"Bearer {access_token}"},
    timeout=30,
)
response.raise_for_status()
print(response.json())
```

### :fab fa-node-js: Node.js

Requires Node.js 18 or later (built-in `fetch`).

```javascript
const tokenResponse = await fetch(
  'https://login.microsoftonline.com/<tenant-id>/oauth2/v2.0/token',
  {
    method: 'POST',
    body: new URLSearchParams({
      grant_type: 'client_credentials',
      client_id: '<client-id>',
      client_secret: process.env.NODINITE_CLIENT_SECRET,
      scope: '<api-app-id-uri>/.default'
    })
  }
);
const { access_token } = await tokenResponse.json();

const response = await fetch('<webapi-base-url>/api/Users/whoami', {
  headers: { Authorization: `Bearer ${access_token}` }
});
console.log(await response.json());
```

### Token Lifetime

Tokens expire after about an hour. Request a new token before it expires, or when you get a `401` response. MSAL does this for you; in the other examples, request a new token at the start of each run, or cache it with its expiry time.

## :fa-list-ol: Step 5: Verify

Call `GET <webapi-base-url>/api/Users/whoami` with the token. The response shows the client and the **Roles** it has in :Nodinite:. To see the response model, open the operation in Scalar at `<webapi-base-url>/scalar`.

The response looks like this (shortened). This example is from a Windows user in the Administrators Role. A client has no user name in its token, so its `Name`, `Domain`, and `UserId` are `null`: :Nodinite: identifies it by the token's issuer and subject, and lists its Roles:

```json
{
  "Collection": {
    "Version": "7.10.4.0",
    "Href": "https://nodinite.contoso.com:40001/api/Users/current",
    "Items": [
      {
        "Href": "https://nodinite.contoso.com:40001/api/Users/12",
        "Data": {
          "UserId": 12,
          "Domain": "DEV",
          "Name": "Administrator",
          "Roles": [
            {
              "RoleId": 0,
              "Name": "Administrators",
              "IsActive": true,
              "IsDeleted": false
            }
          ],
          "IsActive": true,
          "IsDeleted": false
        }
      }
    ],
    "Error": null
  }
}
```

Check `Collection.Items[0].Data.Roles`: it lists the Nodinite Roles the client has. To print only the Role names in PowerShell:

```powershell
$me = Invoke-RestMethod -Uri '<webapi-base-url>/api/Users/whoami' -Headers @{ Authorization = "Bearer $token" }
$me.Collection.Items[0].Data.Roles.Name
```

| Result | Meaning |
| --- | --- |
| `200` and the expected Roles | The setup is complete. |
| `200` but no Roles | The client is connected but has no access. Check [Step 3](#step-3-give-the-client-access-in-nodinite). |
| `401` | The token was not accepted. See [Troubleshooting](#troubleshooting). |

## :fa-stethoscope: Troubleshooting {#troubleshooting}

| Symptom | Fix |
| --- | --- |
| `401` from the [Web API][] | Check that the token was requested with `<api-app-id-uri>/.default` for the **Nodinite Web API**, and that the token has not expired. |
| `401`, and the token's `iss` is `https://sts.windows.net/...` | The webApi app registration still issues **version 1** tokens. Set `requestedAccessTokenVersion` to `2` in its manifest, as in [Set Access Token Version to 2][Token Version 2], then request a **new** token. |
| Token request fails: invalid client secret | Check that you used the secret **Value**, not the secret ID, and that the secret has not expired. |
| Token request fails: consent required | Grant admin consent on the client's **API permissions** page ([Step 2](#fa-list-ol-step-2-give-the-client-permission-to-call-the-web-api)). |
| `whoami` shows no [Roles][] | Check that the [Claim][Claims] value matches the app role value exactly, and that the [Policy][Policies] is added to a [Role][Roles] ([Step 3](#step-3-give-the-client-access-in-nodinite)). A fix in :Nodinite: applies within about 15 seconds with the same token; a fix in the identity provider needs a new token. |

>[!TIP]
>To see what a token contains, paste it into [jwt.ms](https://jwt.ms)<sup>:fa-arrow-up-right-from-square:</sup>, which decodes it in your browser. Check `iss`, `aud`, `roles`, and `exp`.

For token validation errors on the :Nodinite: side, see [Troubleshooting OAuth2 Validation Failures][] and the [Web API Troubleshooting][Troubleshooting] guide.

## :fa-id-card: Other Identity Providers {#other-identity-providers}

:Nodinite: works with any OpenID Connect identity provider, for example Keycloak or Okta. The steps are the same:

1. Create a confidential client that can use the **client credentials** grant.
2. Configure the provider so that the client's tokens are issued for the :Nodinite: Web API audience (in Keycloak, use an *audience mapper*), and include a role or group claim.
3. Map that claim to a :Nodinite: Policy and Role, as in Step 3.
4. Request the token from the provider's token endpoint and send it as `Authorization: Bearer <token>`.

>[!TIP]
>In Keycloak, a *Hardcoded claim* mapper named `roles` makes the client's token carry a `roles` claim like an Entra ID app role. :Nodinite: then receives it with the same Claim key as in Step 3, `http://schemas.microsoft.com/ws/2008/06/identity/claims/role`.

## :fa-shield-halved: Security Checklist

* [ ] One app registration per calling system, with an owner and a description.
* [ ] Certificates, or secrets kept in a vault, with a reminder before they expire.
* [ ] The client's Nodinite Role has only the permissions it needs, and is never Administrators by default.
* [ ] Tokens and secrets are never logged.
* [ ] Always call the Web API over **HTTPS**. See [Hardening][].

## :fa-hand-point-right: Next Steps

* :fa-screwdriver: [Manage the Web API][]  
* :fa-list-ul: [Web API Scenarios][Scenarios]  
* :fa-user-shield: [Roles][]  

## :fa-link-horizontal: Related Topics

* :fab fa-windows: [Call the Web API with Windows Authentication][Windows Authentication]  
* :fa-shield-halved: [Register Nodinite Applications in Azure AD (Entra ID) with OpenID][Install Nodinite v7 - OpenID - EntraID]  
* :fa-plug: [MCP Endpoint][]  
* :fa-robot: [AI in Nodinite][AI]  
* :fa-scroll: [Log Audits][]  
* :fa-shield-halved: [OAuth Security and Compliance Reference][]  

[1]:{ndm}/Documentation%20Pictures/IM/CoreServices/WebAPI/WebAPI_OAuthClientCredentials.gif

[Access Management]:{ndr}/Administration/3.%20Access%20Management/Overview.md
[AI]:{ndr}/AI/Overview.md
[Base URL]:{ndr}/Core%20Services/Web%20API/Features/Managing%20the%20Web%20API.md#find-the-base-url
[Claims]:{ndr}/Administration/3.%20Access%20Management/4.%20Claims/Features/Add%20or%20manage%20Claim.md
[Find Operations]:{ndr}/Core%20Services/Web%20API/Features/Managing%20the%20Web%20API.md#find-operations
[Hardening]:{ndr}/Install%20and%20Update/Troubleshooting/IIS/How%20to%20perform%20hardening%20on%20your%20Nodinite%20installation.md
[Install Nodinite v7 - OpenID]:{ndr}/Install%20and%20Update/Getting%20started/Version%207/Install%20Nodinite%20v7%20-%20OpenID.md
[Install Nodinite v7 - OpenID - EntraID]:{ndr}/Install%20and%20Update/Getting%20started/Version%207/Install%20Nodinite%20v7%20-%20OpenID%20-%20EntraID.md
[Log Audits]:{ndr}/Administration/6.%20Tools/2.%20Log%20Audit%20Search.md
[Manage the Web API]:{ndr}/Core%20Services/Web%20API/Features/Managing%20the%20Web%20API.md
[MCP Endpoint]:{ndr}/AI/MCP%20Endpoint.md
[Monitor Views]:{ndr}/Administration/2.%20Monitor%20Management/1.%20Monitor%20Views/Features/What%20is%20a%20Monitor%20View.md
[OAuth Security and Compliance Reference]:{ndr}/Install%20and%20Update/Getting%20started/Version%207/OAuth%20Security%20and%20Compliance%20Reference.md
[Policies]:{ndr}/Administration/3.%20Access%20Management/5.%20Policies/Features/Add%20or%20manage%20Policy.md
[Portal Web API Audiences]:{ndr}/Install%20and%20Update/Getting%20started/Version%207/Install%20Nodinite%20v7%20Steps/02%20-%20Auth.md#web-api
[Roles]:{ndr}/Administration/3.%20Access%20Management/1.%20Roles/Features/Add%20or%20manage%20Role.md
[Scenarios]:{ndr}/Core%20Services/Web%20API/Scenarios/Overview.md
[Servers step]:{ndr}/Install%20and%20Update/Getting%20started/Version%207/Install%20Nodinite%20v7%20Steps/04%20-%20Servers.md#core-platform-services
[Token Version 2]:{ndr}/Install%20and%20Update/Getting%20started/Version%207/Install%20Nodinite%20v7%20-%20OpenID%20-%20EntraID.md#webapi-set-access-token-version-to-2
[Troubleshooting]:{ndr}/Core%20Services/Web%20API/Troubleshooting/Overview.md
[Troubleshooting OAuth2 Validation Failures]:{ndr}/Install%20and%20Update/Troubleshooting/OAuth%202.0/Troubleshooting%20OAuth2%20Validation%20Failures.md
[Web API]:{ndr}/Core%20Services/Web%20API/Overview.md
[Web API or MCP Endpoint]:{ndr}/Core%20Services/Web%20API/Features/Managing%20the%20Web%20API.md#web-api-or-mcp-endpoint
[Web API System Parameters]:{ndr}/Core%20Services/Web%20API/Features/Managing%20the%20Web%20API.md#system-parameters
[Web Client]:{ndr}/Getting%20Started/Overview.md
[Windows Authentication]:{ndr}/Core%20Services/Web%20API/Scenarios/Call%20the%20Web%20API%20with%20Windows%20Authentication.md