예제 #1
0
파일: options.go 프로젝트: joao-parana/csfw
// WithPasswordFromConfig retrieves the password from the configuration with path
// as defined in constant PathJWTPassword
func WithPasswordFromConfig(cr config.Getter) Option {
	pw, err := cr.String(config.Path(PathJWTPassword))
	if config.NotKeyNotFoundError(err) {
		pw = string(uuid.NewRandom())
	}
	return WithPassword([]byte(pw))
}
예제 #2
0
// IsSecure checks if a request has been sent over a TLS connection. Also checks
// if the app runs behind a proxy server and therefore checks the off loader header.
func IsSecure(cr config.Getter, r *http.Request) bool {
	// due to import cycle this function must be in this package
	if r.TLS != nil {
		return true
	}

	oh, err := cr.String(config.Path(PathOffloaderHeader), config.ScopeDefault())
	if err != nil {
		if PkgLog.IsDebug() {
			PkgLog.Debug("net.httputil.IsSecure.FromContextReader.String", "err", err, "path", PathOffloaderHeader)
		}
		return false
	}

	h := r.Header.Get(oh)
	hh := r.Header.Get("HTTP_" + oh)

	var isHTTPS bool
	switch "https" {
	case h, hh:
		isHTTPS = true
	}
	return isHTTPS
}