Skip to content

feat: configure accepted token types - #42

Merged
uniqueg merged 2 commits into
devfrom
feat/41-token-types
Nov 19, 2026
Merged

uniqueg merged 2 commits into
devfrom
feat/41-token-types

Conversation

@uniqueg

@uniqueg uniqueg commented Nov 19, 2026 •

Copy link
Copy Markdown
Member

Summary

On LS Login, exchanged access tokens (and login tokens of its new proxy) carry typ: JWT, which the services refuse with reason type (seen on #10). This makes the accepted types configurable:

  • TESTBED_TOKEN_TYPES, read for the LS Login provider into Settings.token_types: comma-separated, spaces and empty items ignored, repeats removed case-insensitively (services already compare typ case-insensitively). Unset keeps the RFC 9068 default at+jwt,application/at+jwt; a value that names no type (empty, or only commas) is a ValueError, as it would refuse every token.
  • Docs: new row and a "Token types" section in docs/setup/configuration.md, with the trade-off (accepting JWT also lets ID tokens of the same issuer through, so only aud tells them apart), and the variable with the default value in lslogin.env.example.
  • T1: the question "Do exchanged tokens have the same typ, alg and keys as login tokens?" is answered for typ with what was seen, noting that FOCA nodes need security.auth.token_types set the same way. alg and keys stay open.
  • Tests: settings (unset, list parsing, empty and only-commas values, ignored by the mock), and a validator configured from TESTBED_TOKEN_TYPES with JWT accepts such tokens in any case, while a list without at+jwt refuses at+jwt (the setting replaces the default; the default's refusal of JWT was already tested). TokenValidator now takes its default from settings.TOKEN_TYPES, so it can't drift.

FOCA's default and asking LS Login for at+jwt (#17) stay out of scope, as in the issue.

Verification

  • pytest: 263 passed, coverage 100%.
  • Reviews: adversarial-reviewer and quality-reviewer, two rounds; round 1's medium (a test mixing two behaviours) and lows fixed in the second commit.
  • mkdocs build --strict: built without warnings.
  • pre-commit run --all-files: all hooks passed except actionlint, which couldn't run locally (the machine's shellcheck shim has no version set); this PR changes no workflow. CI runs it.
  • CI: all checks green (Lint, Test, Docs, End-to-end tests, CI passed, Read the Docs), run 44504566602.

Declined review findings

  • Template sets the default instead of leaving the key empty like other optional keys (low): deliberate, as an empty value is an error here; the comment says so.

Open questions

None.

Closes #41

🤖 Generated with Claude Code

Summary by Sourcery

Configure accepted access-token types so LS Login JWT tokens can pass validation while preserving the RFC 9068 defaults unless overridden.

New Features:

  • Allow LS Login accepted JWT typ values to be configured through TESTBED_TOKEN_TYPES, including support for LS Login tokens with typ: JWT.

Bug Fixes:

  • Prevent configurations that specify no token types from silently rejecting every token.

Enhancements:

  • Centralize the default RFC 9068 token types for settings and token validation.
  • Document token-type configuration, its security trade-offs, and the corresponding FOCA setting.
  • Clarify token-type findings in the T1 call-chain documentation.

Documentation:

  • Document the new token-type setting, default behavior, security implications, and LS Login integration guidance.

Tests:

  • Add coverage for default, provider-specific, parsed, invalid, and case-insensitive token-type configurations.

uniqueg and others added 2 commits November 19, 2026 11:05
LS Login's exchanged tokens, and login tokens of its new proxy, carry
`typ: JWT`, which the services refuse. `TESTBED_TOKEN_TYPES` now sets
`Settings.token_types` for LS Login: a comma-separated list, compared
case-insensitively. Unset keeps the RFC 9068 types; a value that names
no type is an error, as it would refuse every token.

Document the variable and its trade-off (accepting `JWT` lets ID
tokens through, so only `aud` tells them apart), and answer the T1
question on `typ`, noting FOCA's `security.auth.token_types`.

Closes #41

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Split the validator test into accepted types and one that shows the
setting replaces the default, test that the mock ignores the variable,
and let `TokenValidator` default to `settings.TOKEN_TYPES`. Say in the
template that login tokens of the new proxy carry `JWT`, too, and where
T1 records the types.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@sourcery-ai

sourcery-ai Bot commented Nov 19, 2026

Copy link
Copy Markdown

Reviewer's Guide

Data structures

Define and share the RFC 9068 token-type defaults used by settings and the validator so they cannot drift.

  • src/testbed/settings.py L29-30, L83
  • src/testbed/validation.py L16, L107

Implementation

Parse configured token types for LS Login, deduplicating case-insensitively and rejecting a configured value that names no type.

  • src/testbed/settings.py L204-230, L241-242, L277

Configuration

Set the documented default token types in the LS Login environment example.

  • lslogin.env.example L47-53

Documentation

Document the token-type setting and the security trade-off of accepting JWT, including its effect on distinguishing ID tokens.

  • docs/setup/configuration.md L36, L49-58

Record the observed exchanged-token type in the T1 investigation and explain the corresponding FOCA setting.

  • docs/tests/t1-call-chain.md L131-134

Tests

Test token-type defaults, LS Login list parsing and validation, empty-value errors, and that the mock ignores the setting.

  • tests/test_settings.py L111-139
  • tests/test_validation.py L11-13, L83-118

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

@read-the-docs-community

Copy link
Copy Markdown

Documentation build overview

📚 token-exchange-flow-testbed | 🛠️ Build #36009405 | 📁 Comparing 4cf3ae3 against latest (e9472a3)

  🔍 Preview build  

2 files changed
± setup/configuration/index.html
± tests/t1-call-chain/index.html

@uniqueg
uniqueg marked this pull request as ready for review November 19, 2026 10:21
@sourcery-ai

sourcery-ai Bot commented Nov 19, 2026

Copy link
Copy Markdown

Linked issues

Checked at commit 4cf3ae3

#41 feat: configure accepted token types · 6 of 6 met

# Requirement Status Notes
1 Read TESTBED_TOKEN_TYPES for LS Login as a comma-separated list, compared case-insensitively. ✅ Met The setting parses the variable for LS Login, trims and ignores empty items, and removes repeats case-insensitively.
2 Keep at+jwt and application/at+jwt as the default when the variable is unset. ✅ Met The shared TOKEN_TYPES constant provides the RFC 9068 defaults to Settings and TokenValidator.
3 Treat an empty value as an error. ✅ Met A set value naming no types raises ValueError.
4 Document the variable and its trade-off in lslogin.env.example and docs/setup/configuration.md. ✅ Met Both explain the default and that accepting JWT also admits same-issuer ID tokens, leaving aud to distinguish them.
5 Answer the T1 question for typ with what was observed, and note that FOCA nodes need security.auth.token_types set the same way. ✅ Met The T1 section records JWT for exchanged and new-proxy login tokens, says FOCA must accept the listed types, and leaves alg and keys open.
6 Test settings for set, unset, and empty values, and test that a validator configured with JWT accepts it while the default refuses it. ✅ Met Settings tests cover the default, parsing, empty values, and mock behavior; validator tests cover configured case-insensitive acceptance and replacement of the default, while the existing default refusal test remains.

@sourcery-ai sourcery-ai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey - I've found 1 issue

Prompt for AI Agents
Please address the comments from this code review:

## Individual Comments

### Comment 1
<location path="src/testbed/settings.py" line_range="277" />
<code_context>
         trusted_issuers=(issuer,),
         clients=clients,
         algorithms=tuple(env.get("TESTBED_ALGORITHMS", "RS256").split(",")),
+        token_types=_token_types(env),
         required_entitlement=env.get("TESTBED_REQUIRED_ENTITLEMENT") or None,
         entitlement_claims=_entitlement_claims(env),
</code_context>
<issue_to_address>
**ID tokens authenticate as access tokens**

When an operator enables `JWT` and a user presents a signed ID token whose audience is the service’s client ID, `Service` passes the configured types to `TokenValidator`, which accepts `JWT` before checking the signature, issuer and audience; an ID token issued to that service’s client ID therefore authenticates as a bearer access token, including where no entitlement policy is configured.

Avoid treating generic `JWT` as sufficient evidence of an access token: validate a provider-guaranteed access-token marker or audience distinction, or keep this option disabled for services that cannot make that distinction.
</issue_to_address>

Sourcery assessment

Needs a human reviewer. 1 finding to address first, and if an operator adds JWT, an ID token from the same issuer addressed to that service’s client ID can pass the type and audience checks as an access token. Removing the setting blocks future acceptance, but does not undo any access or actions already performed using such a token.

Blocking findings: src/testbed/settings.py:277


Sourcery is free for open source - if you like our reviews please consider sharing them ✨

Comment thread src/testbed/settings.py Resolved
@uniqueg
uniqueg merged commit c04b80b into dev Nov 19, 2026
7 checks passed
@uniqueg
uniqueg deleted the feat/41-token-types branch November 19, 2026 10:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

feat: configure accepted token types

1 participant