Skip to content

Commit

Permalink
#61 cookies
Browse files Browse the repository at this point in the history
  • Loading branch information
picman committed Nov 22, 2024
1 parent 67e0d51 commit 39324e4
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 8 deletions.
15 changes: 8 additions & 7 deletions app/controllers/redmine_oauth_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,6 @@ def oauth_callback
# Try to log in
set_params
try_to_login email, user_info
set_oauth_login_cookie true, request
rescue StandardError => e
Rails.logger.error e.message
flash['error'] = e.message
Expand All @@ -168,25 +167,25 @@ def oauth_callback
redirect_to signin_path
end

def set_oauth_autologin_cookie(value, request)
def set_oauth_autologin_cookie
cookie_options = {
value: value,
value: '1',
expires: 1.year.from_now,
path: RedmineApp::Application.config.relative_url_root || '/',
same_site: :lax,
secure: request.ssl?,
secure: Setting.protocol == 'https',
httponly: true
}
cookies[:oauth_autologin] = cookie_options
end

def set_oauth_login_cookie(value, request)
def set_oauth_login_cookie
cookie_options = {
value: value,
value: '1',
expires: 1.year.from_now,
path: RedmineApp::Application.config.relative_url_root || '/',
same_site: :lax,
secure: request.ssl?,
secure: Setting.protocol == 'https',
httponly: true
}
cookies[:oauth_login] = cookie_options
Expand All @@ -201,6 +200,8 @@ def set_params
session.delete :autologin
params['oauth_autologin'] = session[:oauth_autologin]
session.delete :oauth_autologin
params['oauth_login'] = session[:oauth_autologin]
session.delete :oauth_login
end

def try_to_login(email, info)
Expand Down
2 changes: 1 addition & 1 deletion test/functional/account_controller_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ def test_logout

def test_logout_oauth
post '/login', params: { username: 'jsmith', password: 'jsmith' }
cookies[:oauth_login] = true
cookies[:oauth_login] = '1'
Setting.plugin_redmine_oauth[:oauth_logout] = '1'
site = 'https://login.microsoftonline.com'
Setting.plugin_redmine_oauth[:site] = site
Expand Down

0 comments on commit 39324e4

Please sign in to comment.