auth

package module
v0.2.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 18, 2026 License: Apache-2.0 Imports: 9 Imported by: 0

README

vex-auth-sdk-go

Typed Go SDK for vex-auth, generated from the canonical Smithy spec.

go get github.com/vextura/vex-auth-sdk-go

Usage

import "github.com/vextura/vex-auth-sdk-go"

func main() {
    client := auth.New("https://gate.example.com", "<bearer-token>")
    // typed method per Smithy operation
}

Generated

This package is generated by vexctl clientgen. Do not edit the generated files (client.go, types.go, operations.go, errors.go, doc.go) by hand — regenerate from the Smithy source when the API changes.

License

Apache 2.0 — see LICENSE.

Documentation

Overview

Package auth is the typed Go SDK for AuthService.

Usage:

c := auth.New("", "<bearer-token>")
out, err := c.OperationName(ctx, auth.OperationNameInput{...})
if err != nil {
    var nf auth.ErrorEnvelope
    if errors.As(err, &nf) { ... typed error ... }
}

The SDK shares its wire types with the server's generated handlers by construction — both sides emit from the same Smithy spec, so they cannot drift apart. Add new operations to the .smithy and regenerate both halves.

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrValidation   = errors.New("validation failed")
	ErrUnauthorized = errors.New("unauthorized")
	ErrForbidden    = errors.New("forbidden")
	ErrNotFound     = errors.New("not found")
	ErrConflict     = errors.New("conflict")
	ErrInternal     = errors.New("internal error")
)

Sentinel errors callers can match with errors.Is. Decoded from ErrorEnvelope.Code on every non-2xx response.

Functions

This section is empty.

Types

type AssumeRoleInput

type AssumeRoleInput struct {
	RoleSlug        string `json:"role_slug"`
	SessionName     string `json:"session_name,omitempty"`
	DurationSeconds int    `json:"duration_seconds,omitempty"`
}

AssumeRoleInput mirrors the Smithy structure of the same name.

type AssumeRoleOutput

type AssumeRoleOutput struct {
	AccessToken   string         `json:"access_token"`
	ExpiresAt     string         `json:"expires_at"`
	AssumedClaims *AssumedClaims `json:"assumed_claims"`
}

AssumeRoleOutput mirrors the Smithy structure of the same name.

type AssumedClaims

type AssumedClaims struct {
	Iss         string `json:"iss"`
	Sub         string `json:"sub"`
	Exp         int64  `json:"exp"`
	Iat         int64  `json:"iat"`
	Tenant      string `json:"tenant"`
	Role        string `json:"role"`
	AssumedBy   string `json:"assumed_by"`
	SessionName string `json:"session_name,omitempty"`
}

AssumedClaims mirrors the Smithy structure of the same name.

type Client

type Client struct {
	// contains filtered or unexported fields
}

Client is the typed SDK for AuthService.

Construct with New(); every operation is a typed method on Client. Default HTTPClient has a 30s timeout and follows redirects; override with WithHTTPClient(...) when you need different behavior.

func New

func New(endpoint, token string, opts ...Option) *Client

New constructs a Client. endpoint is the service base URL (e.g. "http://vex-vault:8200"); token is the bearer credential sent on every request. Either may be empty for tests against httptest.NewServer.

func (*Client) AssumeRole

func (c *Client) AssumeRole(ctx context.Context, in AssumeRoleInput) (AssumeRoleOutput, error)

AssumeRole calls POST /auth/assume-role.

func (*Client) CreateServiceAccount

CreateServiceAccount calls POST /auth/service-accounts.

func (*Client) DeleteServiceAccount

func (c *Client) DeleteServiceAccount(ctx context.Context, in ServiceAccountIdInput) error

DeleteServiceAccount calls DELETE /auth/service-accounts/{clientId}.

func (*Client) Endpoint

func (c *Client) Endpoint() string

Endpoint returns the service base URL the client is targeting.

func (*Client) GetHealth

func (c *Client) GetHealth(ctx context.Context) (HealthOutput, error)

GetHealth calls GET /health.

func (*Client) GetJWKS

func (c *Client) GetJWKS(ctx context.Context) (JWKSet, error)

GetJWKS calls GET /.well-known/jwks.json.

func (*Client) GetOpenIDConfiguration

func (c *Client) GetOpenIDConfiguration(ctx context.Context) (OpenIDConfiguration, error)

GetOpenIDConfiguration calls GET /.well-known/openid-configuration.

func (*Client) GetServiceAccount

func (c *Client) GetServiceAccount(ctx context.Context, in ServiceAccountIdInput) (ServiceAccount, error)

GetServiceAccount calls GET /auth/service-accounts/{clientId}.

func (*Client) GetSession

func (c *Client) GetSession(ctx context.Context, in SessionIdInput) (SessionDetail, error)

GetSession calls GET /auth/sessions/{sessionId}.

func (*Client) IssueToken

func (c *Client) IssueToken(ctx context.Context, in TokenRequest) (TokenResponse, error)

IssueToken calls POST /auth/token.

func (*Client) ListServiceAccounts

ListServiceAccounts calls GET /auth/service-accounts.

func (*Client) Login

func (c *Client) Login(ctx context.Context, in LoginInput) (LoginOutput, error)

Login calls POST /auth/login.

func (*Client) Logout

func (c *Client) Logout(ctx context.Context, in LogoutInput) error

Logout calls POST /auth/logout.

func (*Client) RefreshSession

func (c *Client) RefreshSession(ctx context.Context, in RefreshInput) (LoginOutput, error)

RefreshSession calls POST /auth/refresh.

func (*Client) RevokeToken added in v0.2.0

RevokeToken calls POST /auth/revoke.

func (*Client) SignUp added in v0.2.0

func (c *Client) SignUp(ctx context.Context, in SignUpInput) (SignUpOutput, error)

SignUp calls POST /auth/signup.

type CreateServiceAccountInput

type CreateServiceAccountInput struct {
	ClientId    string   `json:"client_id"`
	Name        string   `json:"name"`
	Tenant      string   `json:"tenant"`
	Description string   `json:"description,omitempty"`
	Scope       []string `json:"scope,omitempty"`
}

CreateServiceAccountInput mirrors the Smithy structure of the same name.

type CreateServiceAccountOutput

type CreateServiceAccountOutput struct {
	ClientId     string `json:"client_id"`
	ClientSecret string `json:"client_secret"`
	Name         string `json:"name"`
	Tenant       string `json:"tenant"`
}

CreateServiceAccountOutput mirrors the Smithy structure of the same name.

type ErrorEnvelope

type ErrorEnvelope struct {
	Code      string         `json:"code"`
	Message   string         `json:"message"`
	RequestID string         `json:"request_id,omitempty"`
	TraceID   string         `json:"trace_id,omitempty"`
	Details   map[string]any `json:"details,omitempty"`
	// Status is the HTTP status code observed on the wire. Not part of the
	// JSON shape; set by the decoder so callers can switch on it.
	Status int `json:"-"`
}

ErrorEnvelope is the wire shape every server returns on error.

func (ErrorEnvelope) Error

func (e ErrorEnvelope) Error() string

type HealthOutput

type HealthOutput struct {
	Status string `json:"status"`
}

HealthOutput mirrors the Smithy structure of the same name.

type JWK

type JWK struct {
	Kty string `json:"kty"`
	Use string `json:"use"`
	Alg string `json:"alg"`
	Kid string `json:"kid"`
	N   string `json:"n,omitempty"`
	E   string `json:"e,omitempty"`
	X   string `json:"x,omitempty"`
	Y   string `json:"y,omitempty"`
	Crv string `json:"crv,omitempty"`
}

JWK mirrors the Smithy structure of the same name.

type JWKSet

type JWKSet struct {
	Keys []*JWK `json:"keys"`
}

JWKSet mirrors the Smithy structure of the same name.

type ListServiceAccountsInput

type ListServiceAccountsInput struct {
	Tenant string `json:"tenant,omitempty"`
}

ListServiceAccountsInput mirrors the Smithy structure of the same name.

type ListServiceAccountsOutput

type ListServiceAccountsOutput struct {
	Accounts []*ServiceAccount `json:"accounts"`
}

ListServiceAccountsOutput mirrors the Smithy structure of the same name.

type LoginInput

type LoginInput struct {
	Username string `json:"username"`
	Password string `json:"password"`
	Tenant   string `json:"tenant,omitempty"`
}

LoginInput mirrors the Smithy structure of the same name.

type LoginOutput

type LoginOutput struct {
	SessionId string   `json:"session_id"`
	Token     string   `json:"token"`
	ExpiresAt string   `json:"expires_at"`
	Tenant    string   `json:"tenant"`
	Roles     []string `json:"roles,omitempty"`
}

LoginOutput mirrors the Smithy structure of the same name.

type LogoutInput

type LogoutInput struct {
	SessionId string `json:"session_id"`
}

LogoutInput mirrors the Smithy structure of the same name.

type OpenIDConfiguration

type OpenIDConfiguration struct {
	Issuer                           string   `json:"issuer"`
	AuthorizationEndpoint            string   `json:"authorization_endpoint"`
	TokenEndpoint                    string   `json:"token_endpoint"`
	JwksUri                          string   `json:"jwks_uri"`
	ResponseTypesSupported           []string `json:"response_types_supported"`
	SubjectTypesSupported            []string `json:"subject_types_supported"`
	IdTokenSigningAlgValuesSupported []string `json:"id_token_signing_alg_values_supported"`
	GrantTypesSupported              []string `json:"grant_types_supported,omitempty"`
	ScopesSupported                  []string `json:"scopes_supported,omitempty"`
}

OpenIDConfiguration mirrors the Smithy structure of the same name.

type Option

type Option func(*Client)

Option configures a Client at construction time.

func WithHTTPClient

func WithHTTPClient(h *http.Client) Option

WithHTTPClient overrides the default http.Client. Use this to plug in custom transports, retry middleware, or test doubles.

func WithTimeout

func WithTimeout(d time.Duration) Option

WithTimeout sets the per-request timeout on the default http.Client. Ignored if WithHTTPClient already supplied a fully-configured client.

type RefreshInput

type RefreshInput struct {
	SessionId string `json:"session_id"`
}

RefreshInput mirrors the Smithy structure of the same name.

type RevokeTokenRequest added in v0.2.0

type RevokeTokenRequest struct {
	Token         string `json:"token"`
	TokenTypeHint string `json:"token_type_hint,omitempty"`
}

RevokeTokenRequest mirrors the Smithy structure of the same name.

type RevokeTokenResponse added in v0.2.0

type RevokeTokenResponse struct {
}

RevokeTokenResponse mirrors the Smithy structure of the same name.

type ServiceAccount

type ServiceAccount struct {
	ClientId    string   `json:"client_id"`
	Name        string   `json:"name"`
	Tenant      string   `json:"tenant"`
	Description string   `json:"description,omitempty"`
	Scope       []string `json:"scope,omitempty"`
	CreatedAt   string   `json:"created_at"`
}

ServiceAccount mirrors the Smithy structure of the same name.

type ServiceAccountIdInput

type ServiceAccountIdInput struct {
	ClientId string `json:"client_id"`
}

ServiceAccountIdInput mirrors the Smithy structure of the same name.

type ServiceClaims

type ServiceClaims struct {
	Iss      string   `json:"iss"`
	Sub      string   `json:"sub"`
	Aud      []string `json:"aud"`
	Exp      int64    `json:"exp"`
	Iat      int64    `json:"iat"`
	Tenant   string   `json:"tenant"`
	Roles    []string `json:"roles,omitempty"`
	Scope    []string `json:"scope,omitempty"`
	ClientId string   `json:"client_id,omitempty"`
}

ServiceClaims mirrors the Smithy structure of the same name.

type SessionDetail

type SessionDetail struct {
	SessionId string   `json:"session_id"`
	Subject   string   `json:"subject"`
	Tenant    string   `json:"tenant"`
	IssuedAt  string   `json:"issued_at"`
	ExpiresAt string   `json:"expires_at"`
	Roles     []string `json:"roles,omitempty"`
}

SessionDetail mirrors the Smithy structure of the same name.

type SessionIdInput

type SessionIdInput struct {
	SessionId string `json:"session_id"`
}

SessionIdInput mirrors the Smithy structure of the same name.

type SignUpInput added in v0.2.0

type SignUpInput struct {
	CompanyName string `json:"company_name"`
	Tenant      string `json:"tenant"`
	Username    string `json:"username"`
	Email       string `json:"email"`
	Password    string `json:"password"`
	DisplayName string `json:"display_name,omitempty"`
}

SignUpInput mirrors the Smithy structure of the same name.

type SignUpOutput added in v0.2.0

type SignUpOutput struct {
	Tenant           string   `json:"tenant"`
	Username         string   `json:"username"`
	AccessToken      string   `json:"access_token"`
	TokenType        string   `json:"token_type"`
	ExpiresIn        int      `json:"expires_in"`
	ProvisionedRoles []string `json:"provisioned_roles"`
	RootRole         string   `json:"root_role"`
}

SignUpOutput mirrors the Smithy structure of the same name.

type TokenRequest

type TokenRequest struct {
	GrantType    string   `json:"grant_type"`
	ClientId     string   `json:"client_id,omitempty"`
	ClientSecret string   `json:"client_secret,omitempty"`
	Username     string   `json:"username,omitempty"`
	Password     string   `json:"password,omitempty"`
	RefreshToken string   `json:"refresh_token,omitempty"`
	Tenant       string   `json:"tenant,omitempty"`
	Scope        []string `json:"scope,omitempty"`
}

TokenRequest mirrors the Smithy structure of the same name.

type TokenResponse

type TokenResponse struct {
	AccessToken           string   `json:"access_token"`
	TokenType             string   `json:"token_type"`
	ExpiresIn             int      `json:"expires_in"`
	RefreshToken          string   `json:"refresh_token,omitempty"`
	RefreshTokenExpiresIn int      `json:"refresh_token_expires_in,omitempty"`
	Scope                 []string `json:"scope,omitempty"`
}

TokenResponse mirrors the Smithy structure of the same name.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL