Documentation
¶
Overview ¶
Package auth implements the Auth0 device code login and token refresh for one context. Commands in internal/cmd/auth are thin wrappers.
Index ¶
- Constants
- Variables
- func CheckBackend(store credstore.Store, insecure bool) error
- func DeviceLogin(ctx context.Context, c contexts.Context, store credstore.Store, ...) (string, error)
- func IdentityFromIDToken(idToken string) string
- func Logout(store credstore.Store, insecure bool) error
- func OpenStore(f *cmdutil.Factory) (contexts.Context, credstore.Store, error)
- func Token(ctx context.Context, c contexts.Context, store credstore.Store, insecure bool) (string, error)
- func TokenLogin(store credstore.Store, refreshToken string, insecure bool) error
- func TokenResolver(f *cmdutil.Factory) func(context.Context) (string, error)
- type Claims
- type LoginOptions
Constants ¶
const UsernameClaim = "http://lfx.dev/claims/username"
UsernameClaim is the LFID username claim in education API access tokens. The delivery service returns 401 without it.
Variables ¶
var Auth0BaseURL = func(c contexts.Context) string {
return "https://" + c.Auth0Domain
}
Auth0BaseURL returns the tenant base URL for c without a trailing slash. Tests replace it with an httptest server URL.
var ErrNoRefreshToken = errors.New(`no refresh token stored; run "lfed auth login"`)
ErrNoRefreshToken is returned when the cached token is stale and no refresh token exists to renew it.
var ErrNotLoggedIn = errors.New(`not logged in; run "lfed auth login"`)
ErrNotLoggedIn is returned when no credentials exist for the context.
var ErrSessionExpired = errors.New(`session expired or revoked; run "lfed auth login"`)
ErrSessionExpired is returned when Auth0 rejects the refresh token.
var Scopes = []string{"openid", "email", "profile", "offline_access"}
Scopes requested at login. offline_access yields the refresh token; the others identify the user.
Functions ¶
func CheckBackend ¶
CheckBackend compares the stored login state with the --insecure-storage flag. The state file is shared by both backends, so a mismatch means the credentials live in the other backend. A missing state is ErrNotLoggedIn: the state file is written at login and removed at logout, so callers MUST NOT touch the system store before this check. A locked Secret Service collection prompts on first access; a logged-out user must not see that prompt.
func DeviceLogin ¶
func DeviceLogin(ctx context.Context, c contexts.Context, store credstore.Store, opts LoginOptions) (string, error)
DeviceLogin runs the device code flow for c and persists the result in store. It returns the identity from the id_token, or "" when absent.
func IdentityFromIDToken ¶
IdentityFromIDToken returns a display name from an id_token for the "Logged in as" message. It returns "" when nothing usable is present.
func Logout ¶
Logout removes credentials and login state for the store's context. Without a login state there is nothing to remove, and the system store is not touched.
func OpenStore ¶
OpenStore resolves the active context and opens its credential store with the backend selected by --insecure-storage.
func Token ¶
func Token(ctx context.Context, c contexts.Context, store credstore.Store, insecure bool) (string, error)
Token returns a valid access token for c. It returns the cached token when it expires more than 60 seconds from now. Otherwise it refreshes and persists the new credentials.
func TokenLogin ¶
TokenLogin stores a refresh token supplied by the user. No access token is cached; the next Token call exchanges the refresh token for one.
Types ¶
type Claims ¶
Claims are the access token fields that `lfed auth status` shows. They come from an unverified decode; the API verifies the token on each call.
func DecodeClaims ¶
DecodeClaims decodes the payload of a JWT without signature checks.
type LoginOptions ¶
type LoginOptions struct {
// Out receives the user code and verification URL. Use stderr so
// `lfed auth login` never pollutes a piped stdout.
Out io.Writer
// OpenBrowser launches the verification URL in the default browser.
OpenBrowser bool
// Insecure is recorded in the login state; see CheckBackend.
Insecure bool
}
LoginOptions controls the interactive device code flow.