@@ -51,17 +51,19 @@ func oauth2redirect(c *gin.Context) (*model.Oauth2LoginResponse, error) {
51
51
if ! has {
52
52
return nil , singleton .Localizer .ErrorT ("provider not found" )
53
53
}
54
- o2conf := o2confRaw .Setup (getRedirectURL (c ))
54
+ redirectURL := getRedirectURL (c )
55
+ o2conf := o2confRaw .Setup (redirectURL )
55
56
56
57
randomString , err := utils .GenerateRandomString (32 )
57
58
if err != nil {
58
59
return nil , err
59
60
}
60
61
state , stateKey := randomString [:16 ], randomString [16 :]
61
62
singleton .Cache .Set (fmt .Sprintf ("%s%s" , model .CacheKeyOauth2State , stateKey ), & model.Oauth2State {
62
- Action : model .Oauth2LoginType (rTypeInt ),
63
- Provider : provider ,
64
- State : state ,
63
+ Action : model .Oauth2LoginType (rTypeInt ),
64
+ Provider : provider ,
65
+ State : state ,
66
+ RedirectURL : redirectURL ,
65
67
}, cache .DefaultExpiration )
66
68
67
69
url := o2conf .AuthCodeURL (state , oauth2 .AccessTypeOnline )
@@ -138,7 +140,7 @@ func oauth2callback(jwtConfig *jwt.GinJWTMiddleware) func(c *gin.Context) (any,
138
140
return nil , singleton .Localizer .ErrorT ("code is required" )
139
141
}
140
142
141
- openId , err := exchangeOpenId (c , o2confRaw , callbackData )
143
+ openId , err := exchangeOpenId (c , o2confRaw , callbackData , state . RedirectURL )
142
144
if err != nil {
143
145
model .BlockIP (singleton .DB , realip , model .WAFBlockReasonTypeBruteForceOauth2 , model .BlockIDToken )
144
146
return nil , err
@@ -188,8 +190,9 @@ func oauth2callback(jwtConfig *jwt.GinJWTMiddleware) func(c *gin.Context) (any,
188
190
}
189
191
}
190
192
191
- func exchangeOpenId (c * gin.Context , o2confRaw * model.Oauth2Config , callbackData * model.Oauth2Callback ) (string , error ) {
192
- o2conf := o2confRaw .Setup (getRedirectURL (c ))
193
+ func exchangeOpenId (c * gin.Context , o2confRaw * model.Oauth2Config ,
194
+ callbackData * model.Oauth2Callback , redirectURL string ) (string , error ) {
195
+ o2conf := o2confRaw .Setup (redirectURL )
193
196
ctx := context .Background ()
194
197
195
198
otk , err := o2conf .Exchange (ctx , callbackData .Code )
0 commit comments