Fix bug with auth config parsing
This commit is contained in:
@ -116,16 +116,17 @@ func railsCookieHandler(next http.HandlerFunc) http.HandlerFunc {
|
||||
if len(secret) == 0 {
|
||||
panic(errors.New("no auth.rails_cookie.secret_key_base defined"))
|
||||
}
|
||||
|
||||
return func(w http.ResponseWriter, r *http.Request) {
|
||||
ck, err := r.Cookie(cookie)
|
||||
if err != nil {
|
||||
logger.Error(err)
|
||||
next.ServeHTTP(w, r)
|
||||
return
|
||||
}
|
||||
|
||||
userID, err := railsAuth(ck.Value, secret)
|
||||
if err != nil {
|
||||
logger.Error(err)
|
||||
next.ServeHTTP(w, r)
|
||||
return
|
||||
}
|
||||
@ -138,11 +139,9 @@ func railsCookieHandler(next http.HandlerFunc) http.HandlerFunc {
|
||||
func railsAuth(cookie, secret string) (userID string, err error) {
|
||||
var dcookie []byte
|
||||
|
||||
if len(secret) != 0 {
|
||||
dcookie, err = session.DecryptSignedCookie(cookie, secret, salt, signSalt)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
dcookie, err = session.DecryptSignedCookie(cookie, secret, salt, signSalt)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
if dcookie[0] != '{' {
|
||||
|
@ -50,18 +50,18 @@ type config struct {
|
||||
|
||||
RailsCookie struct {
|
||||
SecretKeyBase string `mapstructure:"secret_key_base"`
|
||||
}
|
||||
} `mapstructure:"rails_cookie"`
|
||||
|
||||
RailsMemcache struct {
|
||||
Host string
|
||||
}
|
||||
} `mapstructure:"rails_memcache"`
|
||||
|
||||
RailsRedis struct {
|
||||
URL string
|
||||
Password string
|
||||
MaxIdle int `mapstructure:"max_idle"`
|
||||
MaxActive int `mapstructure:"max_active"`
|
||||
}
|
||||
} `mapstructure:"rails_redis"`
|
||||
|
||||
JWT struct {
|
||||
Provider string
|
||||
@ -120,7 +120,7 @@ func initConf() (*config, error) {
|
||||
vi.AutomaticEnv()
|
||||
|
||||
vi.AddConfigPath(*path)
|
||||
vi.AddConfigPath("./conf")
|
||||
vi.AddConfigPath("./config")
|
||||
vi.SetConfigName(getConfigName())
|
||||
|
||||
vi.SetDefault("host_port", "0.0.0.0:8080")
|
||||
|
Reference in New Issue
Block a user