mirror of
https://github.com/steveiliop56/tinyauth.git
synced 2025-10-29 05:05:42 +00:00
feat: add option to make cookie secure
This commit is contained in:
@@ -36,17 +36,28 @@ func Run(config types.Config, users types.UserList) {
|
|||||||
|
|
||||||
domain, domainErr := utils.GetRootURL(config.AppURL)
|
domain, domainErr := utils.GetRootURL(config.AppURL)
|
||||||
|
|
||||||
log.Info().Str("domain", domain).Msg("Using domain")
|
log.Info().Str("domain", domain).Msg("Using domain for cookies")
|
||||||
|
|
||||||
if domainErr != nil {
|
if domainErr != nil {
|
||||||
log.Fatal().Err(domainErr).Msg("Failed to get domain")
|
log.Fatal().Err(domainErr).Msg("Failed to get domain")
|
||||||
os.Exit(1)
|
os.Exit(1)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var isSecure bool
|
||||||
|
|
||||||
|
if config.CookieSecure {
|
||||||
|
isSecure = true
|
||||||
|
} else {
|
||||||
|
isSecure = false
|
||||||
|
}
|
||||||
|
|
||||||
store.Options(sessions.Options{
|
store.Options(sessions.Options{
|
||||||
Domain: fmt.Sprintf(".%s", domain),
|
Domain: fmt.Sprintf(".%s", domain),
|
||||||
Path: "/",
|
Path: "/",
|
||||||
|
HttpOnly: true,
|
||||||
|
Secure: isSecure,
|
||||||
})
|
})
|
||||||
|
|
||||||
router.Use(sessions.Sessions("tinyauth", store))
|
router.Use(sessions.Sessions("tinyauth", store))
|
||||||
|
|
||||||
router.Use(func(c *gin.Context) {
|
router.Use(func(c *gin.Context) {
|
||||||
|
|||||||
@@ -25,6 +25,7 @@ type Config struct {
|
|||||||
AppURL string `validate:"required,url" mapstructure:"app-url"`
|
AppURL string `validate:"required,url" mapstructure:"app-url"`
|
||||||
Users string `mapstructure:"users"`
|
Users string `mapstructure:"users"`
|
||||||
UsersFile string `mapstructure:"users-file"`
|
UsersFile string `mapstructure:"users-file"`
|
||||||
|
CookieSecure bool `mapstructure:"cookie-secure"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type UserContext struct {
|
type UserContext struct {
|
||||||
|
|||||||
Reference in New Issue
Block a user