code: func (a *Authenticator) doLoginIfRequired(requiresAuth bool) (useAuth bool, err error) {
  	err = a.CheckLoginRequired() // also initializes guts for effectiveLoginMode()
  	effectiveMode := a.effectiveLoginMode()
  	if requiresAuth && effectiveMode == OptionalLogin {
  		effectiveMode = SilentLogin
  	}
  	switch {
  	case err == nil:
  		return true, nil // have a valid cached base token
  	case err == ErrInsufficientAccess && effectiveMode == OptionalLogin:
  		return false, nil // have the base token, but it doesn't have enough scopes
  	case err != ErrLoginRequired:
  		return false, err // some error we can't handle (we handle only ErrLoginRequired)
  	case effectiveMode == SilentLogin:
  		return false, ErrLoginRequired // can't run Login in SilentLogin mode
  	case effectiveMode == OptionalLogin:
  		return false, nil // we can skip auth in OptionalLogin if we have no token
  	case effectiveMode != InteractiveLogin:
  		return false, fmt.Errorf("invalid mode argument: %s", effectiveMode)
  	}
  	if err := a.Login(); err != nil {
  		return false, err
  	}
  	return true, nil
  }
docs: // doLoginIfRequired optionally performs an interactive login.
  //
  // This is the main place where LoginMode handling is performed. Used by various
  // factories (Transport, PerRPCCredentials, TokenSource, ...).
  //
  // If requiresAuth is false, we respect OptionalLogin mode. If true - we treat
  // OptionalLogin mode as SilentLogin: some authentication mechanisms (like
  // oauth2.TokenSource) require valid tokens no matter what. The corresponding
  // factories set requiresAuth to true.
  //
  // Returns:
  //   (true, nil) if successfully initialized the authenticator with some token.
  //   (false, nil) to disable authentication (for OptionalLogin mode).
  //   (false, err) on errors.