MCPcopy Create free account
hub / github.com/algolia/cli / EnsureAuthenticated

Function EnsureAuthenticated

pkg/auth/authenticate.go:14–29  ·  view source on GitHub ↗

EnsureAuthenticated returns a valid access token from the stored session. If no valid session exists and the terminal is interactive, it triggers the browser-based OAuth login flow automatically.

(
	io *iostreams.IOStreams,
	client *dashboard.Client,
)

Source from the content-addressed store, hash-verified

12// If no valid session exists and the terminal is interactive, it triggers the
13// browser-based OAuth login flow automatically.
14func EnsureAuthenticated(
15 io *iostreams.IOStreams,
16 client *dashboard.Client,
17) (string, error) {
18 accessToken, err := GetValidToken(client)
19 if err == nil {
20 return accessToken, nil
21 }
22
23 cs := io.ColorScheme()
24 fmt.Fprintf(io.Out, "%s %s\n", cs.WarningIcon(), err)
25
26 // No flow tracker: this re-authentication belongs to the calling flow,
27 // not to an `auth login` funnel.
28 return RunOAuth(io, client, false, true, nil)
29}
30
31// ReauthenticateIfExpired checks if err is a session-expired error from the API.
32// If so, it clears the invalid token and triggers the login flow.

Callers 6

changePlanFunction · 0.92
runUpdateCmdFunction · 0.92
runListCmdFunction · 0.92
runSelectCmdFunction · 0.92
createApplicationFunction · 0.92
runPlansCmdFunction · 0.92

Calls 4

GetValidTokenFunction · 0.85
RunOAuthFunction · 0.85
ColorSchemeMethod · 0.80
WarningIconMethod · 0.80

Tested by

no test coverage detected