Repository navigation
Apply JWT defaults in jwt create when options are omitted - #1988
Open
waldekmastykarz wants to merge 1 commit into
Open
waldekmastykarz wants to merge 1 commit into
waldekmastykarz wants to merge 1 commit into
Conversation
…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
Contributor
There was a problem hiding this comment.
🟡 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 on lines
+43
to
+46
| var token = new JwtSecurityTokenHandler().ReadJwtToken(JwtTokenGenerator.CreateToken(options)); | ||
|
|
||
| Assert.Equal(["https://myserver.com"], token.Audiences); | ||
| Assert.Equal(TimeSpan.FromMinutes(60), token.ValidTo - token.ValidFrom); |
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.

Closes #1951
devproxy jwt createwithout--valid-for/--audiencesproduced tokens withexp == nbf == iatand noaud, because--valid-forwas anOption<double>(0 when omitted) and--audiencesreturned an empty list. TheJwtCreatorOptionsdefaults therefore never applied.Changes:
--valid-foris nowOption<double?>, so omitting it yieldsnull.--audienceslist is treated as omitted.JwtOptionsmapping extracted toGetJwtOptionsfor testability.Now the CLI matches
POST /proxy/jwtToken: 60-minute validity andhttps://myserver.comaudience 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.Testspasses (21/21). Verified manually by decoding tokens fromdevproxy jwt createanddevproxy jwt create -v 5 -a foo.