feat(frontend): add API integration playground

This commit is contained in:
wizardchen
2026-06-30 21:14:06 +08:00
committed by lyingbug
parent a24567a951
commit ee1014f87c
10 changed files with 1186 additions and 136 deletions
+38
View File
@@ -245,6 +245,7 @@ type APIPrincipalConfig struct {
SignedTokenHeaderName string `json:"signed_token_header_name"`
RequireDirectHeader bool `json:"require_direct_header"`
HasHMACSecret bool `json:"has_hmac_secret"`
HMACSecret string `json:"hmac_secret,omitempty"`
}
type apiPrincipalConfigResponse struct {
@@ -261,6 +262,26 @@ type UpdateAPIPrincipalConfigRequest struct {
HMACSecret string `json:"hmac_secret,omitempty"`
}
// CreateAPIPrincipalTestTokenRequest signs a short-lived JWT for API integration testing.
type CreateAPIPrincipalTestTokenRequest struct {
ExternalUserID string `json:"external_user_id"`
ExpiresInSeconds int `json:"expires_in_seconds,omitempty"`
}
// APIPrincipalTestToken is a short-lived JWT signed with the tenant API principal HMAC secret.
type APIPrincipalTestToken struct {
Token string `json:"token"`
HeaderName string `json:"header_name"`
ExpiresInSeconds int `json:"expires_in_seconds"`
ExpiresAtUnix int64 `json:"expires_at_unix"`
ExternalUserID string `json:"external_user_id"`
}
type apiPrincipalTestTokenResponse struct {
Success bool `json:"success"`
Data APIPrincipalTestToken `json:"data"`
}
// GetAPIPrincipalConfig returns how X-API-Key requests map to principals for a tenant.
func (c *Client) GetAPIPrincipalConfig(ctx context.Context, tenantID uint64) (*APIPrincipalConfig, error) {
path := fmt.Sprintf("/api/v1/tenants/%d/api-principal-config", tenantID)
@@ -292,3 +313,20 @@ func (c *Client) UpdateAPIPrincipalConfig(
}
return &response.Data, nil
}
// CreateAPIPrincipalTestToken signs a short-lived JWT with the tenant API principal HMAC secret.
func (c *Client) CreateAPIPrincipalTestToken(
ctx context.Context, tenantID uint64, req *CreateAPIPrincipalTestTokenRequest,
) (*APIPrincipalTestToken, error) {
path := fmt.Sprintf("/api/v1/tenants/%d/api-principal-test-token", tenantID)
resp, err := c.doRequest(ctx, http.MethodPost, path, req, nil)
if err != nil {
return nil, err
}
var response apiPrincipalTestTokenResponse
if err := parseResponse(resp, &response); err != nil {
return nil, err
}
return &response.Data, nil
}