Skip to content

Make dotnet user-jwts create scriptable #42146

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
1 task done
martincostello opened this issue Jun 11, 2022 · 2 comments · Fixed by #42249
Closed
1 task done

Make dotnet user-jwts create scriptable #42146

martincostello opened this issue Jun 11, 2022 · 2 comments · Fixed by #42249
Assignees
Labels
area-commandlinetools Includes: Command line tools, dotnet-dev-certs, dotnet-user-jwts, and OpenAPI feature-userjwts The `dotnet user-jwts` CLI tool old-area-web-frameworks-do-not-use *DEPRECATED* This label is deprecated in favor of the area-mvc and area-minimal labels
Milestone

Comments

@martincostello
Copy link
Member

Is there an existing issue for this?

  • I have searched the existing issues

Is your feature request related to a problem? Please describe the problem.

While looking at #42125 I noticed that, because it's designed for humans to use, the output from the dotnet user-jwts create command is quite "wordy".

> dotnet dotnet-user-jwts create --claim foo=bar --role baz
New JWT saved with ID '35ed49ea'.
Name: safia
Roles: baz
Custom Claims: foo=bar

Token: eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1bmlxdWVfbmFtZSI6InNhZmlhIiwic3ViIjoic2FmaWEiLCJqdGkiOiIzNWVkNDllYSIsInJvbGUiOiJiYXoiLCJmb28iOiJiYXIiLCJhdWQiOlsiaHR0cHM6Ly9sb2NhbGhvc3Q6NzI1OSIsImh0dHA6Ly9sb2NhbGhvc3Q6NTI1OSJdLCJuYmYiOjE2NTQ4NDQxMTMsImV4cCI6MTY2Mjc5MjkxMywiaWF0IjoxNjU0ODQ0MTE0LCJpc3MiOiJkb3RuZXQtdXNlci1qd3RzIn0.S9Edhjcw26uc1KKnQdrIHkBsSMLj8m_Z6K3QV3XjaHg

That's cool, it's a tool to help devs do manual testing of their APIs. They can read it, then copy the token from the terminal.

However, if a dev then wanted to script things with a created JWT, it's suddenly a bit hacky to run the tool and try and parse the output to get the generated JWT.

Describe the solution you'd like

An additional flag that can be passed to dotnet user-jwts create that will just output the JWT to the output with no other information (in the case of success, at least).

I can't think of a good name for it right now, so for the purpose of the example it's called --only-output-jwt:

> dotnet dotnet-user-jwts create --claim foo=bar --role baz --only-output-jwt
eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1bmlxdWVfbmFtZSI6InNhZmlhIiwic3ViIjoic2FmaWEiLCJqdGkiOiIzNWVkNDllYSIsInJvbGUiOiJiYXoiLCJmb28iOiJiYXIiLCJhdWQiOlsiaHR0cHM6Ly9sb2NhbGhvc3Q6NzI1OSIsImh0dHA6Ly9sb2NhbGhvc3Q6NTI1OSJdLCJuYmYiOjE2NTQ4NDQxMTMsImV4cCI6MTY2Mjc5MjkxMywiaWF0IjoxNjU0ODQ0MTE0LCJpc3MiOiJkb3RuZXQtdXNlci1qd3RzIn0.S9Edhjcw26uc1KKnQdrIHkBsSMLj8m_Z6K3QV3XjaHg

Then using PowerShell as an example, you could generate a valid JWT and assign it directly into a variable, then use it to make HTTP requests:

$jwt = (dotnet dotnet-user-jwts create --claim foo=bar --role baz --only-output-jwt)
Invoke-WebRequest https://localhost:5001/my-secret-resource -Headers @{ "Authorization" = "Bearer $jwt" }

Additional context

No response

@javiercn javiercn added the old-area-web-frameworks-do-not-use *DEPRECATED* This label is deprecated in favor of the area-mvc and area-minimal labels label Jun 11, 2022
@pinkfloydx33
Copy link

Other tools I've used before have a --machine-readable flag, but the output is usually tabulated, etc. and not just a single value. There's always --output=token|full or maybe even --quiet (?) though that kinda implies no output at all. In either case I would definitely appreciate this for the same reasons cited in OP

@captainsafia captainsafia added this to the 7.0-preview6 milestone Jun 15, 2022
@captainsafia captainsafia added the feature-userjwts The `dotnet user-jwts` CLI tool label Jun 15, 2022
@DamianEdwards
Copy link
Member

I was initially thinking we'd just do something like --json-output that emits all relevant data as a JSON blob but I do like the idea of --output default|token|full|json|etc where --output default is the implied default. Also could alias it, e.g. -o|--output like many of the other commands that have an output option.

@ghost ghost locked as resolved and limited conversation to collaborators Jul 17, 2022
@amcasey amcasey added the area-commandlinetools Includes: Command line tools, dotnet-dev-certs, dotnet-user-jwts, and OpenAPI label Jun 2, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
area-commandlinetools Includes: Command line tools, dotnet-dev-certs, dotnet-user-jwts, and OpenAPI feature-userjwts The `dotnet user-jwts` CLI tool old-area-web-frameworks-do-not-use *DEPRECATED* This label is deprecated in favor of the area-mvc and area-minimal labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

6 participants