Skip to content

Apply JWT defaults in jwt create when options are omitted - #1988

Merged
waldekmastykarz merged 4 commits into
dotnet:mainfrom
waldekmastykarz:ubiquitous-train
Oct 26, 2026
Merged

waldekmastykarz merged 4 commits into
dotnet:mainfrom
waldekmastykarz:ubiquitous-train

Conversation

@waldekmastykarz

Copy link
Copy Markdown
Collaborator

Closes #1951

devproxy jwt create without --valid-for / --audiences produced tokens with exp == nbf == iat and no aud, because --valid-for was an Option<double> (0 when omitted) and --audiences returned an empty list. The JwtCreatorOptions defaults therefore never applied.

Changes:

  • --valid-for is now Option<double?>, so omitting it yields null.
  • An empty --audiences list is treated as omitted.
  • Option-to-JwtOptions mapping extracted to GetJwtOptions for testability.

Now the CLI matches POST /proxy/jwtToken: 60-minute validity and https://myserver.com audience by default. Explicit values are still honored.

Tests: added JwtCommandTests (defaults left null, explicit values used, generated token has 60-min lifetime and default audience). DevProxy.Tests passes (21/21). Verified manually by decoding tokens from devproxy jwt create and devproxy jwt create -v 5 -a foo.

…otnet#1951

`--valid-for` was an `Option<double>`, yielding 0 when omitted, and
`--audiences` yielded an empty list, so the `JwtCreatorOptions` defaults
(60 minutes, https://myserver.com) never applied. Tokens expired
immediately and had no audience. Make `--valid-for` nullable and treat an
empty audience list as omitted so the CLI matches `POST /proxy/jwtToken`.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Copilot-Session: 5ef9e780-1aa5-4a65-bafe-6113ab5f1d4b
@waldekmastykarz
waldekmastykarz requested a review from a team as a code owner October 21, 2026 13:56
Copilot AI balanced review requested due to automatic review settings October 21, 2026 13:56

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🟡 Changes recommended

The exact-lifetime assertion can fail intermittently when timestamp reads cross a second boundary.

1 open issue
What changed in this PR

Aligns jwt create defaults with the API, addressing #1951.

Changes:

  • Preserves omitted validity and audience options as null so existing defaults apply.
  • Extracts option mapping and adds regression tests for default and explicit values.
File Description
DevProxy/​Commands/​JwtCommand.cs Applies omitted-option defaults through extracted mapping.
DevProxy.Tests/​JwtCommandTests.cs Tests option mapping and generated token defaults.

Review effort: Balanced

Comment thread DevProxy.Tests/JwtCommandTests.cs Resolved

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🔵 Needs a closer look

The exact token-lifetime assertion can fail intermittently because token timestamps use separate clock reads.

1 open issue

Review effort: Balanced

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🟢 Approval recommended

The focused fix preserves explicit values, covers the reported defaulting failures, and has no unresolved review findings.

No open issues 🎉

1 resolved since last review

Review effort: Balanced

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🟢 Approval recommended

The focused changes correctly apply shared defaults, preserve explicit inputs, and include targeted regression coverage with no unresolved findings.

No open issues 🎉

Review effort: Balanced

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🟢 Approval recommended

The focused changes restore shared defaults, preserve explicit values, and include regression coverage with no unresolved issues.

No open issues 🎉

Review effort: Balanced

@waldekmastykarz
waldekmastykarz merged commit b9865a6 into dotnet:main Oct 26, 2026
4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

2 participants