@@ -68,6 +68,7 @@ func oauth2URL(c *gin.Context) {
6868 redirect_uri = os .Getenv ("OAUTH2_AGENT_REDIRECT_URL" )
6969
7070 cacheDb .Set (clientId , state , 1 * time .Hour )
71+ cacheDb .Set (state , state , 1 * time .Hour )
7172 } else {
7273
7374 state , err = util .GenerateRandomString (32 )
@@ -89,6 +90,7 @@ func oauth2URL(c *gin.Context) {
8990 }
9091 // save clientId and state so we can retrieve for verification
9192 cacheDb .Set (clientId , state , 1 * time .Hour )
93+ cacheDb .Set (state , state , 1 * time .Hour )
9294 codeUrl = oauth2Client .CodeUrl (state )
9395 if referer != "" {
9496 codeUrl = codeUrl + "&referer=" + referer
@@ -136,6 +138,10 @@ func oauth2Exchange(c *gin.Context) {
136138 cacheDb := c .MustGet ("cache" ).(* cache.Cache )
137139 savedState , exists := cacheDb .Get (loginVals .ClientId )
138140
141+ if ! exists {
142+ savedState , exists = cacheDb .Get (loginVals .State )
143+ }
144+
139145 if loginVals .State != "basic_auth" {
140146 if ! exists || savedState != loginVals .State {
141147 log .WithFields (log.Fields {
@@ -198,6 +204,10 @@ func token(c *gin.Context) {
198204 cacheDb := c .MustGet ("cache" ).(* cache.Cache )
199205 savedState , exists := cacheDb .Get (loginVals .Code )
200206
207+ if ! exists {
208+ savedState , exists = cacheDb .Get (loginVals .State )
209+ }
210+
201211 if ! exists || savedState != loginVals .State {
202212 log .WithFields (log.Fields {
203213 "state" : loginVals .State ,
@@ -259,6 +269,10 @@ func login(c *gin.Context) {
259269 cacheDb := c .MustGet ("cache" ).(* cache.Cache )
260270 savedState , exists := cacheDb .Get (loginVals .ClientId )
261271
272+ if ! exists {
273+ savedState , exists = cacheDb .Get (loginVals .State )
274+ }
275+
262276 if loginVals .State != "basic_auth" {
263277 if ! exists || savedState != loginVals .State {
264278 log .WithFields (log.Fields {
@@ -296,13 +310,18 @@ func login(c *gin.Context) {
296310 user := parts [0 ]
297311 pass := parts [1 ]
298312
313+ x := strings .Split (user , "@" )
314+ if len (x ) > 0 {
315+ user = x [0 ]
316+ }
317+
299318 // validate the username and password
300319 err = shadow .ShadowAuthPlain (user , pass )
301320 if err != nil {
302321 log .WithFields (log.Fields {
303322 "err" : err ,
304- }).Error ("shadow: invalid username or password" )
305- c .AbortWithStatus (http .StatusBadRequest )
323+ }).Error ("invalid username or password" )
324+ c .JSON (http .StatusForbidden , gin. H { "error" : "invalid username or password" } )
306325 return
307326 }
308327
@@ -440,7 +459,7 @@ func logout(c *gin.Context) {
440459 return
441460 }
442461
443- cacheDb .Delete (c . Request . Header . Get ( util .AuthTokenHeaderName ))
462+ cacheDb .Delete (util .GetCleanAuthToken ( c ))
444463
445464 var logoutUrl string
446465
0 commit comments