Documentation
¶
Overview ¶
Package miviaauth provides primitives to interact with the openapi HTTP API.
Code generated by github.com/oapi-codegen/oapi-codegen/v2 version v2.8.0 DO NOT EDIT.
token.go holds the local CLI auth token model shared by the mivia login/refresh flow. The package doc lives on openapi_types.gen.go's generated header; this file intentionally does not repeat a "Package miviaauth" comment, since go/doc concatenates every such comment across a package's files and a second one here would just create noise.
Index ¶
- Constants
- Variables
- func Delete(path string) error
- func Save(path string, t Token) error
- func ServerURLFromEnv() string
- type AcceptInvitationRequest
- type AuthAcceptInvitationJSONRequestBody
- type AuthAcceptInvitationParams
- type AuthCreateInvitationJSONRequestBody
- type AuthDeleteOrganizationJSONRequestBody
- type AuthLoginJSONRequestBody
- type AuthLoginParams
- type AuthPatchMemberRoleJSONRequestBody
- type AuthPatchOrganizationJSONRequestBody
- type AuthPatchProfileJSONRequestBody
- type AuthPreviewInvitationParams
- type AuthRefreshParams
- type AuthRegisterJSONRequestBody
- type AuthRevokeParams
- type AuthVerifyJSONRequestBody
- type AuthVerifyParams
- type Client
- func (c *Client) Login(ctx context.Context, email string, password []byte) (Token, error)
- func (c *Client) Refresh(ctx context.Context, bearer string) (Token, error)
- func (c *Client) Register(ctx context.Context, email string, password []byte, organizationName string) error
- func (c *Client) Revoke(ctx context.Context, bearer string) error
- func (c *Client) Verify(ctx context.Context, token string) (Token, error)
- type CreateInvitationResponseBody
- type InvitationActionResponseBody
- type InvitationRow
- type InviteRequest
- type ListInvitationsResponseBody
- type ListMembersResponseBody
- type LoginRequest
- type LoginResponseBody
- type MemberActionBody
- type MemberRow
- type OrganizationDeleteRequest
- type OrganizationPatchRequest
- type OrganizationProfileBody
- type PatchMemberRoleRequest
- type PatchProfileResponseBody
- type PreviewInvitationResponseBody
- type ProfileRequest
- type RefreshResponseBody
- type RegisterRequest
- type RegisterResponseBody
- type RegistrationStageBody
- type RemoveMemberResponseBody
- type ResendInvitationResponseBody
- type Service
- type SessionExpiry
- type SessionInfo
- type SessionResponseBody
- type StatusError
- type SystemAccessCheckResponseBody
- type Token
- type UserInfo
- type VerifyRequest
- type VerifyResponseBody
- type WireError
- type WireErrorBody
Constants ¶
const DefaultServerURL = "https://api.mivia.app"
DefaultServerURL is the go-mivia API root used when MIVIA_API_BASE_URL is unset. The production API is not live yet; override for local/staging use.
Variables ¶
var ErrNotFound = errors.New("no stored auth token")
ErrNotFound reports that no auth token is stored at the requested path.
var ErrReauthRequired = errors.New("not logged in; run `mivia login`")
ErrReauthRequired means no usable local session exists — the caller should prompt the user to run `mivia login` again. It covers: no stored token, a corrupt stored token, an already-expired stored token (refresh never works past expiry per go-mivia's contract), and a definitive 401 from the refresh endpoint (the stored bearer was revoked/invalid).
var ErrVerifiedNoSession = errors.New("miviaauth: email verified, but no session was issued; run `mivia login`")
ErrVerifiedNoSession means the verification code was accepted but the server did not issue a session (VerifyCreatesSession=false server-side). The caller should tell the user to run `mivia login` next.
Functions ¶
func Delete ¶
Delete removes the token stored at path. A missing file is not an error: Delete is idempotent.
func Save ¶
Save writes t to path as JSON, atomically. The parent directory is created with 0o700 if missing, and the file is written with 0o600 before being renamed into place so a partial write never lands at the final path.
func ServerURLFromEnv ¶
func ServerURLFromEnv() string
ServerURLFromEnv returns MIVIA_API_BASE_URL if set and non-blank, else DefaultServerURL. The process environment wins; ./.env and ~/.mivia/.env are consulted as a fallback, matching how provider API keys are resolved elsewhere in this repo (internal/config/load.go, internal/config.Lookup) -- without this, a value set only in ~/.mivia/.env would be silently invisible here, since that file is never loaded into the OS environment.
Types ¶
type AcceptInvitationRequest ¶
type AcceptInvitationRequest struct {
Password string `json:"password"`
Token string `json:"token"`
}
AcceptInvitationRequest defines model for AcceptInvitationRequest.
type AuthAcceptInvitationJSONRequestBody ¶
type AuthAcceptInvitationJSONRequestBody = AcceptInvitationRequest
AuthAcceptInvitationJSONRequestBody defines body for AuthAcceptInvitation for application/json ContentType.
type AuthAcceptInvitationParams ¶
type AuthAcceptInvitationParams struct {
XMiviaAuthTransport *string `json:"X-Mivia-Auth-Transport,omitempty"`
}
AuthAcceptInvitationParams defines parameters for AuthAcceptInvitation.
type AuthCreateInvitationJSONRequestBody ¶
type AuthCreateInvitationJSONRequestBody = InviteRequest
AuthCreateInvitationJSONRequestBody defines body for AuthCreateInvitation for application/json ContentType.
type AuthDeleteOrganizationJSONRequestBody ¶
type AuthDeleteOrganizationJSONRequestBody = OrganizationDeleteRequest
AuthDeleteOrganizationJSONRequestBody defines body for AuthDeleteOrganization for application/json ContentType.
type AuthLoginJSONRequestBody ¶
type AuthLoginJSONRequestBody = LoginRequest
AuthLoginJSONRequestBody defines body for AuthLogin for application/json ContentType.
type AuthLoginParams ¶
type AuthLoginParams struct {
XMiviaAuthTransport *string `json:"X-Mivia-Auth-Transport,omitempty"`
}
AuthLoginParams defines parameters for AuthLogin.
type AuthPatchMemberRoleJSONRequestBody ¶
type AuthPatchMemberRoleJSONRequestBody = PatchMemberRoleRequest
AuthPatchMemberRoleJSONRequestBody defines body for AuthPatchMemberRole for application/json ContentType.
type AuthPatchOrganizationJSONRequestBody ¶
type AuthPatchOrganizationJSONRequestBody = OrganizationPatchRequest
AuthPatchOrganizationJSONRequestBody defines body for AuthPatchOrganization for application/json ContentType.
type AuthPatchProfileJSONRequestBody ¶
type AuthPatchProfileJSONRequestBody = ProfileRequest
AuthPatchProfileJSONRequestBody defines body for AuthPatchProfile for application/json ContentType.
type AuthPreviewInvitationParams ¶
type AuthPreviewInvitationParams struct {
Token *string `form:"token,omitempty" json:"token,omitempty"`
}
AuthPreviewInvitationParams defines parameters for AuthPreviewInvitation.
type AuthRefreshParams ¶
type AuthRefreshParams struct {
Authorization *string `json:"Authorization,omitempty"`
}
AuthRefreshParams defines parameters for AuthRefresh.
type AuthRegisterJSONRequestBody ¶
type AuthRegisterJSONRequestBody = RegisterRequest
AuthRegisterJSONRequestBody defines body for AuthRegister for application/json ContentType.
type AuthRevokeParams ¶
type AuthRevokeParams struct {
Authorization *string `json:"Authorization,omitempty"`
}
AuthRevokeParams defines parameters for AuthRevoke.
type AuthVerifyJSONRequestBody ¶
type AuthVerifyJSONRequestBody = VerifyRequest
AuthVerifyJSONRequestBody defines body for AuthVerify for application/json ContentType.
type AuthVerifyParams ¶
type AuthVerifyParams struct {
XMiviaAuthTransport *string `json:"X-Mivia-Auth-Transport,omitempty"`
}
AuthVerifyParams defines parameters for AuthVerify.
type Client ¶
type Client struct {
// contains filtered or unexported fields
}
Client talks to the go-mivia bearer-token CLI auth endpoints.
func NewClient ¶
NewClient validates baseURL and returns a Client. baseURL must be an absolute https URL, with one exception: a loopback address (127.0.0.1, ::1, or the literal "localhost") over plain http is accepted for local dev. This exception does NOT consult MIVIA_ALLOW_INSECURE_HTTP — that env var is scoped to credential-free LLM provider traffic; this endpoint carries a password and gets its own, narrower exception with no env override.
func (*Client) Login ¶
Login exchanges an email and password for a Token. password is converted to a string only at the JSON marshal call site below; it is never stored as a Go string anywhere else in this file.
func (*Client) Register ¶
func (c *Client) Register(ctx context.Context, email string, password []byte, organizationName string) error
Register starts account creation. It never returns a session -- the account is unusable until the emailed verification code is submitted via Verify. password is converted to a string only at the JSON marshal call site, matching Login.
func (*Client) Verify ¶
Verify submits an emailed verification code. On success it normally returns a Token (same as Login/Refresh); if the server is configured without auto-login-on-verify it returns ErrVerifiedNoSession instead -- callers must handle that case explicitly, not treat it as a hard error.
type CreateInvitationResponseBody ¶
type CreateInvitationResponseBody struct {
InvitationId string `json:"invitation_id"`
OrganizationId string `json:"organization_id"`
Status string `json:"status"`
}
CreateInvitationResponseBody defines model for CreateInvitationResponseBody.
type InvitationActionResponseBody ¶
type InvitationActionResponseBody struct {
Email string `json:"email"`
InvitationId string `json:"invitation_id"`
OrganizationId string `json:"organization_id"`
Role string `json:"role"`
Status string `json:"status"`
}
InvitationActionResponseBody defines model for InvitationActionResponseBody.
type InvitationRow ¶
type InvitationRow struct {
CreatedAt string `json:"created_at"`
Email string `json:"email"`
ExpiresAt string `json:"expires_at"`
InvitationId string `json:"invitation_id"`
InvitedByAccountId string `json:"invited_by_account_id"`
OrganizationId string `json:"organization_id"`
Role string `json:"role"`
}
InvitationRow defines model for InvitationRow.
type InviteRequest ¶
InviteRequest defines model for InviteRequest.
type ListInvitationsResponseBody ¶
type ListInvitationsResponseBody struct {
Invitations *[]InvitationRow `json:"invitations"`
}
ListInvitationsResponseBody defines model for ListInvitationsResponseBody.
type ListMembersResponseBody ¶
type ListMembersResponseBody struct {
Members *[]MemberRow `json:"members"`
}
ListMembersResponseBody defines model for ListMembersResponseBody.
type LoginRequest ¶
LoginRequest defines model for LoginRequest.
type LoginResponseBody ¶
type LoginResponseBody struct {
Authenticated bool `json:"authenticated"`
Session *SessionInfo `json:"session,omitempty"`
User UserInfo `json:"user"`
}
LoginResponseBody defines model for LoginResponseBody.
type MemberActionBody ¶
type MemberActionBody struct {
AccountId string `json:"account_id"`
Email string `json:"email"`
OrganizationId string `json:"organization_id"`
Role string `json:"role"`
}
MemberActionBody defines model for MemberActionBody.
type MemberRow ¶
type MemberRow struct {
AccountId string `json:"account_id"`
DisplayName *string `json:"display_name"`
Email string `json:"email"`
EmailVerifiedAt *time.Time `json:"email_verified_at,omitempty"`
Lastname *string `json:"lastname"`
Name *string `json:"name"`
OrganizationId string `json:"organization_id"`
Role string `json:"role"`
}
MemberRow defines model for MemberRow.
type OrganizationDeleteRequest ¶
type OrganizationDeleteRequest struct {
ConfirmationKey string `json:"confirmation_key"`
}
OrganizationDeleteRequest defines model for OrganizationDeleteRequest.
type OrganizationPatchRequest ¶
type OrganizationPatchRequest struct {
DisplayName string `json:"display_name"`
}
OrganizationPatchRequest defines model for OrganizationPatchRequest.
type OrganizationProfileBody ¶
type OrganizationProfileBody struct {
CreatedAt time.Time `json:"created_at"`
DisplayName string `json:"display_name"`
OrganizationId string `json:"organization_id"`
OrganizationKey string `json:"organization_key"`
UpdatedAt time.Time `json:"updated_at"`
}
OrganizationProfileBody defines model for OrganizationProfileBody.
type PatchMemberRoleRequest ¶
type PatchMemberRoleRequest struct {
Role string `json:"role"`
}
PatchMemberRoleRequest defines model for PatchMemberRoleRequest.
type PatchProfileResponseBody ¶
type PatchProfileResponseBody struct {
Authenticated bool `json:"authenticated"`
User UserInfo `json:"user"`
}
PatchProfileResponseBody defines model for PatchProfileResponseBody.
type PreviewInvitationResponseBody ¶
type PreviewInvitationResponseBody struct {
AccountExists bool `json:"account_exists"`
Email string `json:"email"`
ExpiresAt time.Time `json:"expires_at"`
NeedsPassword bool `json:"needs_password"`
OrganizationId string `json:"organization_id"`
OrganizationKey string `json:"organization_key"`
OrganizationName string `json:"organization_name"`
Role string `json:"role"`
}
PreviewInvitationResponseBody defines model for PreviewInvitationResponseBody.
type ProfileRequest ¶
type ProfileRequest struct {
DisplayName *string `json:"display_name,omitempty"`
Lastname *string `json:"lastname,omitempty"`
Name *string `json:"name,omitempty"`
}
ProfileRequest defines model for ProfileRequest.
type RefreshResponseBody ¶
type RefreshResponseBody struct {
Authenticated bool `json:"authenticated"`
Session SessionInfo `json:"session"`
User UserInfo `json:"user"`
}
RefreshResponseBody defines model for RefreshResponseBody.
type RegisterRequest ¶
type RegisterRequest struct {
Email string `json:"email"`
OrganizationName string `json:"organization_name"`
Password string `json:"password"`
}
RegisterRequest defines model for RegisterRequest.
type RegisterResponseBody ¶
type RegisterResponseBody struct {
Status string `json:"status"`
}
RegisterResponseBody defines model for RegisterResponseBody.
type RegistrationStageBody ¶
type RegistrationStageBody struct {
Stage string `json:"stage"`
}
RegistrationStageBody defines model for RegistrationStageBody.
type RemoveMemberResponseBody ¶
type RemoveMemberResponseBody struct {
AccountId string `json:"account_id"`
Email string `json:"email"`
OrganizationId string `json:"organization_id"`
Role string `json:"role"`
Status string `json:"status"`
}
RemoveMemberResponseBody defines model for RemoveMemberResponseBody.
type ResendInvitationResponseBody ¶
type ResendInvitationResponseBody struct {
InvitationId string `json:"invitation_id"`
OrganizationId string `json:"organization_id"`
Status string `json:"status"`
}
ResendInvitationResponseBody defines model for ResendInvitationResponseBody.
type Service ¶
type Service struct {
// contains filtered or unexported fields
}
Service manages the local CLI session lifecycle: login, logout, and keeping a stored token usable across calls.
func NewService ¶
NewService builds a Service. client is typically *Client from NewClient; path is typically config.UserAuthPath().
func (*Service) Ensure ¶
Ensure returns a currently-valid bearer, refreshing the stored token if it is within refreshSkew of expiry (or already expired -> ErrReauthRequired, since refresh never works on an already-expired bearer). A definitive 401 from Refresh also yields ErrReauthRequired (and clears the stale local token). A transient failure (429/503/network) leaves the stored token file untouched and returns a wrapped error with an EMPTY bearer string -- Go convention, never return a non-empty value alongside a non-nil error -- so the caller must retry Ensure() later; the file is untouched specifically so that retry can succeed once the transient condition clears.
func (*Service) Logout ¶
Logout revokes the stored bearer server-side on a best-effort basis (a network failure here must NOT prevent the local token file from being deleted — logout must always succeed locally, including offline) and deletes the local token file.
func (*Service) Verify ¶
Verify submits an emailed verification code and, if the server issues a session, persists it -- mirroring Login. If verification succeeded but no session was issued (ErrVerifiedNoSession), that error is returned as-is and nothing is written to disk; the caller should tell the user to run `mivia login`.
type SessionExpiry ¶
SessionExpiry defines model for SessionExpiry.
type SessionInfo ¶
SessionInfo defines model for SessionInfo.
type SessionResponseBody ¶
type SessionResponseBody struct {
Authenticated bool `json:"authenticated"`
Session SessionExpiry `json:"session"`
User UserInfo `json:"user"`
}
SessionResponseBody defines model for SessionResponseBody.
type StatusError ¶
type StatusError struct {
StatusCode int
}
StatusError reports a non-2xx HTTP response from go-mivia's auth endpoints. Callers use errors.As to classify failures (e.g. 401 vs 429/503) without parsing go-mivia's JSON error envelope.
func (*StatusError) Error ¶
func (e *StatusError) Error() string
type SystemAccessCheckResponseBody ¶
type SystemAccessCheckResponseBody struct {
PlatformSuperAdmin bool `json:"platform_super_admin"`
}
SystemAccessCheckResponseBody defines model for SystemAccessCheckResponseBody.
type Token ¶
Token is the local CLI credential issued after a successful login.
func Load ¶
Load reads the token stored at path. A missing file reports an error that satisfies errors.Is(err, ErrNotFound). A malformed file reports a wrapped decode error that does not satisfy that check.
type UserInfo ¶
type UserInfo struct {
AccountId string `json:"account_id"`
DisplayName *string `json:"display_name"`
Email string `json:"email"`
IsPlatformSuperAdmin bool `json:"is_platform_super_admin"`
Lastname *string `json:"lastname"`
Name *string `json:"name"`
OrganizationId string `json:"organization_id"`
OrganizationKey string `json:"organization_key"`
OrganizationName string `json:"organization_name"`
Role string `json:"role"`
}
UserInfo defines model for UserInfo.
type VerifyRequest ¶
type VerifyRequest struct {
Token string `json:"token"`
}
VerifyRequest defines model for VerifyRequest.
type VerifyResponseBody ¶
type VerifyResponseBody struct {
Authenticated bool `json:"authenticated"`
Session *SessionInfo `json:"session,omitempty"`
Status *string `json:"status,omitempty"`
User *UserInfo `json:"user,omitempty"`
}
VerifyResponseBody defines model for VerifyResponseBody.
type WireError ¶
type WireError struct {
Error WireErrorBody `json:"error"`
}
WireError defines model for WireError.
type WireErrorBody ¶
WireErrorBody defines model for WireErrorBody.