MCPcopy Create free account
hub / github.com/TheThingsNetwork/lorawan-stack / requireAuth

Function requireAuth

cmd/ttn-lw-cli/commands/root.go:352–368  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

350}
351
352func requireAuth() error {
353 if apiKey, ok := cache.Get("api_key").(string); ok && apiKey != "" {
354 logger.Debug("Using API key")
355 api.SetAuth("bearer", apiKey)
356 return nil
357 }
358 if token, ok := cache.Get("oauth_token").(*oauth2.Token); ok && token != nil {
359 friendlyExpiry := token.Expiry.Truncate(time.Minute).Format(time.Kitchen)
360 if time.Until(token.Expiry) > 0 {
361 logger.Debugf("Using access token (valid until %s)", friendlyExpiry)
362 api.SetAuth(token.TokenType, token.AccessToken)
363 return nil
364 }
365 logger.Warnf("Access token expired at %s", friendlyExpiry)
366 }
367 return errUnauthenticated.New()
368}
369
370var (
371 versionCommand = version.Print(Root)

Callers 1

optionalAuthFunction · 0.85

Calls 7

SetAuthFunction · 0.92
GetMethod · 0.65
DebugMethod · 0.65
FormatMethod · 0.65
DebugfMethod · 0.65
WarnfMethod · 0.65
NewMethod · 0.65

Tested by

no test coverage detected