@@ -71,25 +71,19 @@ def check_token_expiry!
71
71
# delete the cookie
72
72
#
73
73
def handle_user_cache_cookie!
74
- if cookies [ :_radius_user_cache_key ]
75
- if cookies [ :_radius_user_cache_key ] == "none"
76
- # Sign out current user
77
- session . delete :user_id
78
-
79
- # Clear that user's cache key
80
- session . delete :user_cache_key
81
-
82
- elsif session [ :user_cache_key ] != cookies [ :_radius_user_cache_key ]
83
- # Delete the cookie to prevent redirect loops
84
- cookies . delete :_radius_user_cache_key
85
-
86
- # Redirect to the account app
87
- redirect_to_sign_in
74
+ if SESSION_REDIS
75
+ handle_user_cache_cookie_with_redis
76
+ else
77
+ if cookies [ :_radius_user_cache_key ]
78
+ if cookies [ :_radius_user_cache_key ] == "none"
79
+ delete_session_data
80
+ elsif session [ :user_cache_key ] != cookies [ :_radius_user_cache_key ]
81
+ clear_cache_cookie_and_sign_out
82
+ end
88
83
end
89
84
end
90
85
end
91
86
92
-
93
87
def current_user = ( u )
94
88
@current_user = u
95
89
end
@@ -124,6 +118,38 @@ def user_signed_in?
124
118
125
119
private
126
120
121
+ def handle_user_cache_cookie_with_redis
122
+ # If the user passes us a cache key cookie:
123
+ if cookies [ :_radius_user_cache_key ]
124
+ expected_val = SESSION_REDIS . get ( cookies [ :_radius_user_cache_key ] )
125
+
126
+ # And we do not have that cookie in Redis
127
+ if !expected_val
128
+ delete_session_data
129
+ # Or we have it in Redis, but it may be somebody else's
130
+ # - it's not what we expect from their session
131
+ elsif expected_val && expected_val != session [ :user_cache_key ]
132
+ clear_cache_cookie_and_sign_out
133
+ end
134
+ end
135
+ end
136
+
137
+ def delete_session_data
138
+ # Sign out current user
139
+ session . delete :user_id
140
+
141
+ # Clear that user's cache key
142
+ session . delete :user_cache_key
143
+ end
144
+
145
+ def clear_cache_cookie_and_sign_out
146
+ # Delete the cookie to prevent redirect loops
147
+ cookies . delete :_radius_user_cache_key
148
+
149
+ # Redirect to the account app
150
+ redirect_to_sign_in
151
+ end
152
+
127
153
def user_class
128
154
Kracken . config . user_class
129
155
end
0 commit comments