@ -9,14 +9,22 @@ import (
"github.com/sirupsen/logrus"
"github.com/sirupsen/logrus"
jwt "github.com/dgrijalva/jwt-go"
jwt "github.com/dgrijalva/jwt-go"
"github.com/gin-gonic/contrib/sessions"
"github.com/gin-contrib/sessions"
"github.com/gin-contrib/sessions/cookie"
"github.com/gin-contrib/sessions/redis"
"github.com/gin-gonic/gin"
"github.com/gin-gonic/gin"
"github.com/pkg/errors"
"github.com/pkg/errors"
)
)
func ( h * Handler ) initOAuth ( ) {
func ( h * Handler ) initOAuth ( ) {
h . engine . Use ( sessions . Sessions ( "backend" , sessions . NewCookieStore ( util . GetPrivateKey ( ) ) ) )
switch backend := util . GetConfig ( ) . Backend ; backend {
// use redis as the session store if it is configured
case "redis" :
store , _ := redis . NewStoreWithDB ( 10 , "tcp" , util . GetConfig ( ) . Redis . Host , util . GetConfig ( ) . Redis . Password , util . GetConfig ( ) . Redis . SessionDB , util . GetPrivateKey ( ) )
h . engine . Use ( sessions . Sessions ( "backend" , store ) )
default :
h . engine . Use ( sessions . Sessions ( "backend" , cookie . NewStore ( util . GetPrivateKey ( ) ) ) )
}
h . providers = [ ] string { }
h . providers = [ ] string { }
google := util . GetConfig ( ) . Google
google := util . GetConfig ( ) . Google
if google . Enabled ( ) {
if google . Enabled ( ) {
@ -39,7 +47,14 @@ func (h *Handler) initOAuth() {
// initProxyAuth intializes data structures for proxy authentication mode
// initProxyAuth intializes data structures for proxy authentication mode
func ( h * Handler ) initProxyAuth ( ) {
func ( h * Handler ) initProxyAuth ( ) {
h . engine . Use ( sessions . Sessions ( "backend" , sessions . NewCookieStore ( util . GetPrivateKey ( ) ) ) )
switch backend := util . GetConfig ( ) . Backend ; backend {
// use redis as the session store if it is configured
case "redis" :
store , _ := redis . NewStoreWithDB ( 10 , "tcp" , util . GetConfig ( ) . Redis . Host , util . GetConfig ( ) . Redis . Password , util . GetConfig ( ) . Redis . SessionDB , util . GetPrivateKey ( ) )
h . engine . Use ( sessions . Sessions ( "backend" , store ) )
default :
h . engine . Use ( sessions . Sessions ( "backend" , cookie . NewStore ( util . GetPrivateKey ( ) ) ) )
}
h . providers = [ ] string { }
h . providers = [ ] string { }
h . providers = append ( h . providers , "proxy" )
h . providers = append ( h . providers , "proxy" )
h . engine . POST ( "/api/v1/auth/check" , h . handleAuthCheck )
h . engine . POST ( "/api/v1/auth/check" , h . handleAuthCheck )