diff --git a/api/client.go b/api/client.go index 56bf6d9863..3e0bd83e22 100644 --- a/api/client.go +++ b/api/client.go @@ -301,8 +301,8 @@ func (c Client) DeleteAccessKey(id uid.ID) error { return delete(c, fmt.Sprintf("/v1/access-keys/%s", id)) } -func (c Client) CreateToken(req *CreateTokenRequest) (*CreateTokenResponse, error) { - return post[CreateTokenRequest, CreateTokenResponse](c, "/v1/tokens", req) +func (c Client) CreateToken() (*CreateTokenResponse, error) { + return post[EmptyRequest, CreateTokenResponse](c, "/v1/tokens", &EmptyRequest{}) } func (c Client) Introspect() (*Introspect, error) { diff --git a/api/token.go b/api/token.go index 3495cc33b4..7f60b93959 100644 --- a/api/token.go +++ b/api/token.go @@ -1,13 +1,5 @@ package api -import ( - "github.com/infrahq/infra/uid" -) - -type CreateTokenRequest struct { - UserID uid.ID `json:"userID" validate:"required"` -} - type CreateTokenResponse struct { Expires Time `json:"expires"` Token string `json:"token"` diff --git a/docs/api/openapi3.json b/docs/api/openapi3.json index 1eed73c460..95857e792a 100644 --- a/docs/api/openapi3.json +++ b/docs/api/openapi3.json @@ -3462,26 +3462,6 @@ "post": { "description": "CreateToken", "operationId": "CreateToken", - "requestBody": { - "content": { - "application/json": { - "schema": { - "properties": { - "userID": { - "example": "4yJ3n3D8E2", - "format": "uid", - "pattern": "[\\da-zA-HJ-NP-Z]{1,11}", - "type": "string" - } - }, - "required": [ - "userID" - ], - "type": "object" - } - } - } - }, "responses": { "400": { "content": { diff --git a/internal/cmd/tokens.go b/internal/cmd/tokens.go index 8d82d22f38..098b4a39ec 100644 --- a/internal/cmd/tokens.go +++ b/internal/cmd/tokens.go @@ -49,22 +49,7 @@ func tokensCreate() error { return err } - config, err := currentHostConfig() - if err != nil { - return err - } - - id := config.PolymorphicID - if id == "" { - return fmt.Errorf("no active identity") - } - - identityID, err := id.ID() - if err != nil { - return err - } - - token, err := client.CreateToken(&api.CreateTokenRequest{UserID: identityID}) + token, err := client.CreateToken() if err != nil { if errors.Is(err, api.ErrForbidden) { fmt.Fprintln(os.Stderr, "Session has expired.") diff --git a/internal/server/handlers.go b/internal/server/handlers.go index 757c476032..2b28d41121 100644 --- a/internal/server/handlers.go +++ b/internal/server/handlers.go @@ -349,7 +349,7 @@ func (a *API) DeleteDestination(c *gin.Context, r *api.Resource) error { return access.DeleteDestination(c, r.ID) } -func (a *API) CreateToken(c *gin.Context, r *api.CreateTokenRequest) (*api.CreateTokenResponse, error) { +func (a *API) CreateToken(c *gin.Context, r *api.EmptyRequest) (*api.CreateTokenResponse, error) { if access.CurrentIdentity(c) != nil { currentIDP, err := access.CurrentIdentityProvider(c) if err != nil {