MCPcopy Index your code
hub / github.com/coder/coder / CreateToken

Method CreateToken

codersdk/apikey.go:66–78  ·  view source on GitHub ↗

CreateToken generates an API key for the user ID provided with custom expiration. These tokens can be used for long-lived access, like for use with CI.

(ctx context.Context, userID string, req CreateTokenRequest)

Source from the content-addressed store, hash-verified

64// custom expiration. These tokens can be used for long-lived access,
65// like for use with CI.
66func (c *Client) CreateToken(ctx context.Context, userID string, req CreateTokenRequest) (GenerateAPIKeyResponse, error) {
67 res, err := c.Request(ctx, http.MethodPost, fmt.Sprintf("/api/v2/users/%s/keys/tokens", userID), req)
68 if err != nil {
69 return GenerateAPIKeyResponse{}, err
70 }
71 defer res.Body.Close()
72 if res.StatusCode > http.StatusCreated {
73 return GenerateAPIKeyResponse{}, ReadBodyAsError(res)
74 }
75
76 var apiKey GenerateAPIKeyResponse
77 return apiKey, json.NewDecoder(res.Body).Decode(&apiKey)
78}
79
80// CreateAPIKey generates an API key for the user ID provided.
81// CreateToken should be used over CreateAPIKey. CreateToken allows better

Calls 3

RequestMethod · 0.95
ReadBodyAsErrorFunction · 0.85
CloseMethod · 0.65