Skip to content
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

Add audience flag to api token create #927

Merged
merged 1 commit into from
May 1, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 8 additions & 5 deletions command/api/token/create.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,11 @@ func createCommand() cli.Command {
Action: cli.ActionFunc(createAction),
Usage: "create a new token",
UsageText: `**step api token create** <team-id> <crt-file> <key-file>
[**--api-url**=<url>]
[**--api-url**=<url>] [**--audience**=<name>]
`,
Flags: []cli.Flag{
apiURLFlag,
audienceFlag,
},
Description: `**step ca api token create** creates a new token for connecting to the Smallstep API.

Expand All @@ -49,8 +50,9 @@ $ step api token create ff98be70-7cc3-4df5-a5db-37f5d3c96e23 internal.crt intern
}

type createTokenReq struct {
TeamID string `json:"teamID"`
Bundle [][]byte `json:"bundle"`
TeamID string `json:"teamID"`
Bundle [][]byte `json:"bundle"`
Audience string `json:"audience,omitempty"`
}

type createTokenResp struct {
Expand Down Expand Up @@ -86,8 +88,9 @@ func createAction(ctx *cli.Context) (err error) {
}
b := &bytes.Buffer{}
r := &createTokenReq{
TeamID: teamID,
Bundle: clientCert.Certificate,
TeamID: teamID,
Bundle: clientCert.Certificate,
Audience: ctx.String("audience"),
}
err = json.NewEncoder(b).Encode(r)
if err != nil {
Expand Down
4 changes: 4 additions & 0 deletions command/api/token/token.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,4 +26,8 @@ var (
Usage: "URL where the Smallstep API can be found",
Value: "https://gateway.smallstep.com",
}
audienceFlag = cli.StringFlag{
Name: "audience",
Usage: "Request a token for an audience other than the API Gateway",
}
)