Documentation
¶
Overview ¶
Package session signs the customer in on the web (OAuth 2.0 Device Authorization Grant against Keycloak), keeps the tokens on disk, refreshes them and revokes them on logout.
Index ¶
Constants ¶
const ClientId = "openvicloud-cli"
ClientId is the public Keycloak client of the CLI (gitops/keycloak/realm-import/configmap.yaml).
Variables ¶
var ( ErrLoginDenied = errors.New("the login was refused on the web page") ErrLoginExpired = errors.New("the login code expired before it was confirmed on the web page") ErrSessionExpired = errors.New("the session has expired or was revoked") ErrRevokeFailed = errors.New("the server did not confirm the session was revoked") )
var ErrNotLoggedIn = errors.New("not logged in")
var ErrOtherEndpoint = errors.New("the saved session belongs to another endpoint")
Functions ¶
Types ¶
type DeviceCode ¶
type DeviceCode struct {
DeviceCode string `json:"device_code"`
UserCode string `json:"user_code"`
VerificationUri string `json:"verification_uri"`
VerificationUriComplete string `json:"verification_uri_complete"`
ExpiresIn int `json:"expires_in"`
Interval int `json:"interval"`
}
DeviceCode is what Keycloak hands out to start a login: the user opens VerificationUriComplete (or VerificationUri and types UserCode) while the CLI polls with DeviceCode.
type Endpoints ¶
Endpoints are where the CLI talks to: the /v1 API, the Keycloak realm (issuer URL) and the customer portal, where a customer accepts the terms.
type Keycloak ¶
type Keycloak struct {
Issuer string
HTTP *http.Client
Sleep func(time.Duration)
Now func() time.Time
}
Keycloak talks to the OpenID Connect endpoints of one realm. Sleep and Now are injected so tests do not wait.
type Manager ¶
func (*Manager) AccessToken ¶
AccessToken returns a token valid for the configured API, refreshing it first when it is about to expire.
func (*Manager) Current ¶
Current is the saved session as it is on disk, whichever endpoint it belongs to.
type Session ¶
type Session struct {
Api string `json:"api"`
Issuer string `json:"issuer"`
Username string `json:"username"`
AccessToken string `json:"accessToken"`
AccessExpiresAt time.Time `json:"accessExpiresAt"`
RefreshToken string `json:"refreshToken"`
}
Session is what one `auth login` leaves on disk. Api and Issuer record where it belongs, so a token issued for one environment is never sent to another.