tokenx-auth

tokenx-auth is a skill for Claude Code, Codex from navikt/copilot. It costs 23 tokens per session (2,344 once invoked), scanned A, original, MIT.

A guide for service-to-service authentication with TokenX on Nais. TokenX lets one application exchange its credentials for a token that another protected application accepts.

In plain words
What is it for?
Enabling TokenX in a Nais manifest, setting outbound access rules, calling downstream services, protecting Ktor endpoints, and testing authentication with MockOAuth2Server.
Why use it?
It provides a consistent way to configure permissions, obtain and cache exchanged tokens, and verify incoming requests. This prevents services from calling each other without controlled authentication.

Skill for Claude CodeCodex

Written for no agent in particular: nothing here depends on one.

Good fit Enabling TokenX in a Nais manifest, setting outbound access rules, calling downstream…

Compare 6 skills from other repositories ↓
Install with agentmods
npx agentmods add skills/navikt/copilot/tokenx-auth
Install

Getting it into your agent

One page per mod, every tool's command on it. A separate URL per tool would split the same page into five that compete with each other.

Any agent
npx skills add navikt/copilot --skill tokenx-auth
Clone the repo
git clone --depth 1 https://github.com/navikt/copilot

Made for: Claude Code, Codex.

Wrote this? Show the measurements

A badge with what this costs and how it scanned, read live from this page, so it follows the numbers instead of freezing them. Markdown for a README, HTML for a documentation site or a project page.

agentmods badge for tokenx-auth

README.md
[![agentmods](https://agentmods.dev/badge/skills/navikt/copilot/tokenx-auth.svg)](https://agentmods.dev/skills/navikt/copilot/tokenx-auth)
Your own site
<a href="https://agentmods.dev/skills/navikt/copilot/tokenx-auth"><img src="https://agentmods.dev/badge/skills/navikt/copilot/tokenx-auth.svg" alt="Measured on agentmods" height="20"></a>
Per session 23 Skills are progressive disclosure: only the name and description are preloaded; the body loads when the skill is used.
When invoked 2,344 The whole file, excluding the scripts and references it only reads on demand.
Security scan A 0 findings. A grade says what 26 rules found in the file — not that it is safe.
Origin original No closer match found in the catalogue.
Token cost

What it costs to keep this loaded

Counted locally with the o200k_base tokenizer, which is exact for GPT models; Claude uses its own tokenizer and its counts differ. Treat this as one consistent yardstick across the catalogue rather than a bill. Prices are per million input tokens.

ModelPer sessionOnce invoked
Fable 5.1 $0.00023 $0.02344
Opus 5 $0.00012 $0.01172
Sonnet 5 $0.00005 $0.00469
Haiku 4.5 $0.00002 $0.00234

Measured 7d ago against content hash efa91db0fb79, method: parsed. Prices are Anthropic first-party input rates as of 2026-09-06, from the pricing page.

Security

Grade A, and why

tokenx-auth scanned grade A with 0 findings against 26 rules in 11 categories — prompt injection, anti-refusal, data exfiltration, privilege escalation, supply chain, agent snooping, system-prompt leakage, SSRF and excessive agency — measured 7d ago.

A static scan of the body, not an audit. Every finding is printed with the line that produced it so you can judge whether it matters here. A mod is markdown that instructs an agent; that is exactly why what it instructs is worth reading.

Nothing flagged

None of the 26 patterns this scan looks for appear in this file: no shell pipes, no recursive deletes, no credential paths, no hidden text, no instruction-override or anti-refusal phrasing, no agent-config snooping. That is not a guarantee, it is the absence of the things that are checkable.

skills/tokenx-auth/SKILL.md · 383 lines

How it starts

The opening of the file, as written. The whole thing — 383 lines — stays where its author put it; the contents beside it link to each section on GitHub.

TokenX Authentication Skill

This skill provides patterns for secure service-to-service authentication using TokenX.

Workflow

  1. Enable TokenX in the Nais manifest and define access policies
  2. Implement token exchange (basic or with caching)
  3. Call downstream services with the exchanged token
  4. Validate inbound TokenX tokens on protected endpoints
  5. Integrate with Ktor authentication
  6. Test with MockOAuth2Server

1. Nais Manifest Setup

apiVersion: nais.io/v1alpha1
kind: Application
metadata:
  name: my-app
spec:
  tokenx:
    enabled: true

  accessPolicy:
    outbound:
      rules:
        - application: user-service
          namespace: team-user

This creates environment variables:

  • TOKEN_X_WELL_KNOWN_URL
  • TOKEN_X_CLIENT_ID
  • TOKEN_X_PRIVATE_JWK

2. Token Exchange with Caching

Production pattern from navikt/tms-ktor-token-support - used across 198+ Nav repositories:

import com.github.benmanes.caffeine.cache.Cache
import com.github.benmanes.caffeine.cache.Caffeine
import com.nimbusds.jose.jwk.RSAKey

class CachingTokendingsService(
    private val tokendingsConsumer: TokendingsConsumer,
    private val jwtAudience: String,
    private val clientId: String,
    privateJwk: String,
    maxCacheEntries: Long = 10000,
    cacheExpiryMarginSeconds: Int = 10
) : TokendingsService {

    private val cache: Cache<String, AccessTokenEntry> = Caffeine.newBuilder()
        .maximumSize(maxCacheEntries)
        .expireAfter(ExpiryPolicy(cacheExpiryMarginSeconds))
        .build()

    private val privateRsaKey = RSAKey.parse(privateJwk)

    override suspend fun exchangeToken(token: String, targetApp: String): String {
        val cacheKey = "$token:$targetApp".hashCode().toString()
        return cache.get(cacheKey) {
            performTokenExchange(token, targetApp)
        }.accessToken
    }

    private suspend fun performTokenExchange(
        token: String,
        targetApp: String
    ): AccessTokenEntry {
        val clientAssertion = createSignedAssertion(clientId, jwtAudience, privateRsaKey)
        return tokendingsConsumer.exchangeToken(
            subjectToken = token,
            clientAssertion = clientAssertion,
            targetApp = "cluster:namespace:$targetApp"
        )
    }
}

Read the full file on GitHub · 383 lines

Files

What ships with it

1 file beside SKILL.md in the same directory: the scripts, references and assets a skill reads on demand. Not counted in the per-session cost; read them before you install if any of them is executable.

Changes

What this file has done since we first saw it

Hashed on every crawl. A supply-chain change to an agent config is a question of when, not whether, so the history is kept rather than the latest state alone.

  1. 7d ago First seen · 383 lines · 23 tokens per session scan A efa91db0fb79

Subscribe to this mod's changes

tokenx-auth is a skill published in the GitHub repository navikt/copilot (54 stars, last pushed today), licensed MIT. It adds 23 tokens to every session and 2,344 once invoked, about $0.0001 per session on Opus 5. A static security scan graded it A with 0 findings. No closer match exists in the catalogue, so it is treated as the original; first seen 2026-08-30.

Related

Other skills, from other repositories

aspire-dev

Orchestrates Aspire distributed applications using the Aspire CLI and MCP tools. USE FOR: aspire start/stop, aspire describe, aspire doctor, view logs/traces, add integrations, debug resources, AppHost management. Also trigger for DistributedApplication.CreateBuilder, AddProject, AddContainer, or Aspire resource…

AndyElessar/skills · 146 tokens

cloudflare

Comprehensive Cloudflare platform skill covering Workers, Pages, storage (KV, D1, R2), AI (Workers AI, Vectorize, Agents SDK), feature flags (Flagship), networking (Tunnel, Spectrum), security (WAF, DDoS), and infrastructure-as-code (Terraform, Pulumi). Use for any Cloudflare development task. Biases towards retrieval…

cloudflare/skills · 87 tokens

sandbox-stable

Use when building or changing Cloudflare Sandbox apps on the current stable @cloudflare/sandbox package (default npm tag)—commands, sessions, files, ports, tunnels, terminals, bridge, production, or deprecated-API cleanup while staying on stable. Not for @cloudflare/sandbox@next (use sandbox-next) or for porting to…

cloudflare/skills · 85 tokens

cloudflare-email-service

Send and receive transactional emails with Cloudflare Email Service (Email Sending + Email Routing). Use when building email sending (Workers binding or REST API), email routing, Agents SDK email handling, or integrating email into any app — Workers, Node.js, Python, Go, etc. Also use for email deliverability…

cloudflare/skills · 114 tokens

sandbox-next

Use when building or changing Cloudflare Sandbox apps on @cloudflare/sandbox@next (Sandbox SDK 1.0 preview)—code execution, AI runners, interpreters, CI-like jobs, terminals, files, mounts, tunnels, preview URLs, lifecycle, or errors. Not for the default stable package (use sandbox-stable) or for porting stable to…

cloudflare/skills · 86 tokens

workers-best-practices

Reviews and authors Cloudflare Workers code against production best practices. Load when writing new Workers, reviewing Worker code, configuring wrangler.jsonc, or checking for common Workers anti-patterns (streaming, floating promises, global state, secrets, bindings, observability). Biases towards retrieval from…

cloudflare/skills · 72 tokens