Skip to content

Commit 10bef0c

Browse files
committed
OAuth logout #61
1 parent e20edc0 commit 10bef0c

File tree

2 files changed

+25
-1
lines changed

2 files changed

+25
-1
lines changed

app/controllers/redmine_oauth_controller.rb

+14
Original file line numberDiff line numberDiff line change
@@ -159,10 +159,12 @@ def oauth_callback
159159
# Try to log in
160160
set_params
161161
try_to_login email, user_info
162+
set_oauth_login_cookie true, request
162163
rescue StandardError => e
163164
Rails.logger.error e.message
164165
flash['error'] = e.message
165166
cookies.delete :oauth_autologin
167+
cookies.delete :oauth_login
166168
redirect_to signin_path
167169
end
168170

@@ -178,6 +180,18 @@ def set_oauth_autologin_cookie(value, request)
178180
cookies[:oauth_autologin] = cookie_options
179181
end
180182

183+
def set_oauth_login_cookie(value, request)
184+
cookie_options = {
185+
value: value,
186+
expires: 1.year.from_now,
187+
path: RedmineApp::Application.config.relative_url_root || '/',
188+
same_site: :lax,
189+
secure: request.ssl?,
190+
httponly: true
191+
}
192+
cookies[:oauth_login] = cookie_options
193+
end
194+
181195
private
182196

183197
def set_params

lib/redmine_oauth/patches/account_controller_patch.rb

+11-1
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,10 @@ def login
3333

3434
def logout
3535
delete_oauth_autologin_cookie
36-
return super if User.current.anonymous? || !request.post? || Setting.plugin_redmine_oauth[:oauth_logout].blank?
36+
return super if User.current.anonymous? || !request.post? ||
37+
Setting.plugin_redmine_oauth[:oauth_logout].blank? || oauth_login_cookie.blank?
3738

39+
delete_oauth_login_cookie
3840
site = Setting.plugin_redmine_oauth[:site]&.chomp('/')
3941
id = Setting.plugin_redmine_oauth[:client_id]
4042
url = signout_url
@@ -72,9 +74,17 @@ def delete_oauth_autologin_cookie
7274
cookies.delete :oauth_autologin
7375
end
7476

77+
def delete_oauth_login_cookie
78+
cookies.delete :oauth_login
79+
end
80+
7581
def oauth_autologin_cookie
7682
cookies[:oauth_autologin]
7783
end
84+
85+
def oauth_login_cookie
86+
cookies[:oauth_login]
87+
end
7888
end
7989
end
8090
end

0 commit comments

Comments
 (0)