Skip to content

Commit

Permalink
Merge pull request #44 from fcinqmars/feat-cookie-options
Browse files Browse the repository at this point in the history
add extra cookie options
  • Loading branch information
wiltonsr authored Jul 29, 2023
2 parents 09175bf + 645e309 commit c6f6066
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 4 deletions.
9 changes: 8 additions & 1 deletion ldapauth.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@ type Config struct {
Port uint16 `json:"port,omitempty" yaml:"port,omitempty"`
CacheTimeout uint32 `json:"cacheTimeout,omitempty" yaml:"cacheTimeout,omitempty"`
CacheCookieName string `json:"cacheCookieName,omitempty" yaml:"cacheCookieName,omitempty"`
CacheCookiePath string `json:"cacheCookiePath,omitempty" yaml:"cacheCookiePath,omitempty"`
CacheCookieSecure bool `json:"cacheCookieSecure,omitempty" yaml:"cacheCookieSecure,omitempty"`
CacheKey string `json:"cacheKey,omitempty" yaml:"cacheKey,omitempty"`
UseTLS bool `json:"useTls,omitempty" yaml:"useTls,omitempty"`
StartTLS bool `json:"startTls,omitempty" yaml:"startTls,omitempty"`
Expand Down Expand Up @@ -73,6 +75,8 @@ func CreateConfig() *Config {
Port: 389, // Usually 389 or 636
CacheTimeout: 300, // In seconds, default to 5m
CacheCookieName: "ldapAuth_session_token",
CacheCookiePath: "",
CacheCookieSecure: false,
CacheKey: "super-secret-key",
UseTLS: false,
StartTLS: false,
Expand Down Expand Up @@ -113,7 +117,10 @@ func New(ctx context.Context, next http.Handler, config *Config, name string) (h
// Create new session with CacheKey and CacheTimeout.
store = sessions.NewCookieStore([]byte(config.CacheKey))
store.Options = &sessions.Options{
MaxAge: int(config.CacheTimeout),
HttpOnly: true,
MaxAge: int(config.CacheTimeout),
Path: config.CacheCookiePath,
Secure: config.CacheCookieSecure,
}

return &LdapAuth{
Expand Down
17 changes: 14 additions & 3 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -138,18 +138,29 @@ LDAP server port where queries will be performed.
##### `cacheTimeout`
_Optional, Default: `300`_

Indicates the number of `seconds` until the cookie session expires. A zero or negative number will expire the cookie immediately.
Indicates the number of `seconds` until the session cookie expires. A zero or negative number will expire the cookie immediately.

##### `cacheCookieName`
_Optional, Default: `ldapAuth_session_token`_

The cookie session name.
The session cookie name.

##### `cacheCookiePath`
_Optional, Default: `""`_

The session cookie path. By default, the cookie path will be set to the request path.

##### `cacheCookieSecure`
_Optional, Default: `false`_

Set to true if the session cookie should have the secure flag. The cookie will only be transmitted over an HTTPS connection.

##### `cacheKey`
Needs `traefik` >= [`v2.8.5`](https://github.com/traefik/traefik/releases/tag/v2.8.5)

_Optional, Default: `super-secret-key`_

The key used to cryptography cookie session information. You `must` use a strong value here.
The key used to encrypt session cookie information. You `must` use a strong value here.

##### `useTLS`
_Optional, Default: `false`_
Expand Down

0 comments on commit c6f6066

Please sign in to comment.