Documentation
¶
Overview ¶
Package apihelper provides helper functions for API client operations.
Index ¶
- Variables
- type Helper
- func (h *Helper) AuthMethod(ctx context.Context) string
- func (h *Helper) GetClient(ctx context.Context) (*client.SolidPingClient, error)
- func (h *Helper) Login(ctx context.Context, org, email, password string) (string, *client.UserSummary, error)
- func (h *Helper) Logout(ctx context.Context, callAPI bool) error
- func (h *Helper) ResetClient()
- func (h *Helper) SavePAT(pat string) error
- func (h *Helper) SaveTokens(accessToken, refreshToken string) error
- func (h *Helper) TryAuthRecovery(ctx context.Context) (string, error)
- type TokenData
Constants ¶
This section is empty.
Variables ¶
var ( // ErrNoAuthentication is returned when no authentication method is configured. ErrNoAuthentication = errors.New( "no authentication configured: please run 'sp auth login' or configure PAT in settings.json") // ErrNoAccessToken is returned when no access token is received. ErrNoAccessToken = errors.New("no access token received") // ErrInvalidToken is returned when a token cannot be parsed. ErrInvalidToken = errors.New("invalid token") // ErrRefreshTokenInvalid is returned when refresh token is invalid or expired. ErrRefreshTokenInvalid = errors.New("refresh token is invalid or expired") )
Functions ¶
This section is empty.
Types ¶
type Helper ¶
type Helper struct {
// contains filtered or unexported fields
}
Helper manages API client creation and authentication.
func (*Helper) AuthMethod ¶
AuthMethod reports how the currently-resolved credential authenticates: "pat" for a Personal Access Token, "jwt" otherwise. It resolves the token the same way GetClient does, so it reflects the credential a request would use.
func (*Helper) Login ¶
func (h *Helper) Login(ctx context.Context, org, email, password string) (string, *client.UserSummary, error)
Login performs login and saves token.
func (*Helper) ResetClient ¶
func (h *Helper) ResetClient()
ResetClient clears the cached API client, forcing re-authentication on next GetClient call.
func (*Helper) SavePAT ¶
SavePAT saves a Personal Access Token as the sole credential in the token file, replacing any prior JWT session. Used by the browser-login flow after self-minting a PAT, and by the `--token` / SP_TOKEN paste fallback.
func (*Helper) SaveTokens ¶
SaveTokens saves new access and refresh tokens to the token file.
type TokenData ¶
type TokenData struct {
AccessToken string `json:"accessToken"`
AccessTokenExpiresAt time.Time `json:"accessTokenExpiresAt"`
RefreshToken string `json:"refreshToken"`
RefreshTokenExpiresAt time.Time `json:"refreshTokenExpiresAt"`
// PAT holds a Personal Access Token saved by the browser-login flow
// (`sp auth login`). When set, it is used directly as the bearer
// credential and never expires client-side — the server enforces any
// expiry. A PAT and a JWT session are mutually exclusive in one file.
PAT string `json:"pat,omitempty"`
}
TokenData represents the stored token information.
func (*TokenData) IsAccessTokenValid ¶
IsAccessTokenValid checks if the access token is still valid.
func (*TokenData) IsRefreshTokenValid ¶
IsRefreshTokenValid checks if the refresh token is still valid.