@@ -9,14 +9,22 @@ import (
99 "github.com/sirupsen/logrus"
1010
1111 jwt "github.com/dgrijalva/jwt-go"
12- "github.com/gin-gonic/contrib/sessions"
12+ "github.com/gin-contrib/sessions"
13+ "github.com/gin-contrib/sessions/cookie"
14+ "github.com/gin-contrib/sessions/redis"
1315 "github.com/gin-gonic/gin"
1416 "github.com/pkg/errors"
1517)
1618
1719func (h * Handler ) initOAuth () {
18- h .engine .Use (sessions .Sessions ("backend" , sessions .NewCookieStore (util .GetPrivateKey ())))
19-
20+ switch backend := util .GetConfig ().Backend ; backend {
21+ // use redis as the session store if it is configured
22+ case "redis" :
23+ store , _ := redis .NewStoreWithDB (10 , "tcp" , util .GetConfig ().Redis .Host , util .GetConfig ().Redis .Password , util .GetConfig ().Redis .SessionDB , util .GetPrivateKey ())
24+ h .engine .Use (sessions .Sessions ("backend" , store ))
25+ default :
26+ h .engine .Use (sessions .Sessions ("backend" , cookie .NewStore (util .GetPrivateKey ())))
27+ }
2028 h .providers = []string {}
2129 google := util .GetConfig ().Google
2230 if google .Enabled () {
@@ -39,7 +47,14 @@ func (h *Handler) initOAuth() {
3947
4048// initProxyAuth intializes data structures for proxy authentication mode
4149func (h * Handler ) initProxyAuth () {
42- h .engine .Use (sessions .Sessions ("backend" , sessions .NewCookieStore (util .GetPrivateKey ())))
50+ switch backend := util .GetConfig ().Backend ; backend {
51+ // use redis as the session store if it is configured
52+ case "redis" :
53+ store , _ := redis .NewStoreWithDB (10 , "tcp" , util .GetConfig ().Redis .Host , util .GetConfig ().Redis .Password , util .GetConfig ().Redis .SessionDB , util .GetPrivateKey ())
54+ h .engine .Use (sessions .Sessions ("backend" , store ))
55+ default :
56+ h .engine .Use (sessions .Sessions ("backend" , cookie .NewStore (util .GetPrivateKey ())))
57+ }
4358 h .providers = []string {}
4459 h .providers = append (h .providers , "proxy" )
4560 h .engine .POST ("/api/v1/auth/check" , h .handleAuthCheck )
0 commit comments