code: func (s *DefaultService) Auth(ctx context.Context, authConfig *types.AuthConfig, userAgent string) (status, token string, err error) {
  	// TODO Use ctx when searching for repositories
  	serverAddress := authConfig.ServerAddress
  	if serverAddress == "" {
  		serverAddress = IndexServer
  	}
  	if !strings.HasPrefix(serverAddress, "https://") && !strings.HasPrefix(serverAddress, "http://") {
  		serverAddress = "https://" + serverAddress
  	}
  	u, err := url.Parse(serverAddress)
  	if err != nil {
  		return "", "", errdefs.InvalidParameter(errors.Errorf("unable to parse server address: %v", err))
  	}
  
  	endpoints, err := s.LookupPushEndpoints(u.Host)
  	if err != nil {
  		return "", "", errdefs.InvalidParameter(err)
  	}
  
  	for _, endpoint := range endpoints {
  		login := loginV2
  		if endpoint.Version == APIVersion1 {
  			login = loginV1
  		}
  
  		status, token, err = login(authConfig, endpoint, userAgent)
  		if err == nil {
  			return
  		}
  		if fErr, ok := err.(fallbackError); ok {
  			err = fErr.err
  			logrus.Infof("Error logging in to %s endpoint, trying next endpoint: %v", endpoint.Version, err)
  			continue
  		}
  
  		return "", "", err
  	}
  
  	return "", "", err
  }
docs: // Auth contacts the public registry with the provided credentials,
  // and returns OK if authentication was successful.
  // It can be used to verify the validity of a client's credentials.