Skip to content

Commit 0e8f872

Browse files
committed
#105 undefine method custom_profile_endpont
1 parent 62b7227 commit 0e8f872

2 files changed

Lines changed: 36 additions & 11 deletions

File tree

app/controllers/redmine_oauth_controller.rb

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -176,7 +176,7 @@ def oauth_callback
176176
redirect_uri: oauth_callback_url,
177177
code_verifier: code_verifier)
178178
userinfo_response = token.get(
179-
"/oauth2/#{RedmineOauth.tenant_id}/v1/userinfo",
179+
"/oauth2/#{oauth_provider.tenant_id}/v1/userinfo",
180180
headers: { 'Accept' => 'application/json' }
181181
)
182182
user_info = JSON.parse(userinfo_response.body)
@@ -187,17 +187,17 @@ def oauth_callback
187187
token = RedmineOauth::OauthClient.client(oauth_provider).auth_code.get_token(params['code'],
188188
redirect_uri: oauth_callback_url,
189189
code_verifier: code_verifier)
190-
if RedmineOauth.custom_profile_endpoint.empty?
190+
if oauth_provider.custom_profile_endpoint.empty?
191191
user_info = JWT.decode(token.token, nil, false).first
192192
else
193193
userinfo_response = token.get(
194-
RedmineOauth.custom_profile_endpoint,
194+
oauth_provider.custom_profile_endpoint,
195195
headers: { 'Accept' => 'application/json' }
196196
)
197197
user_info = JSON.parse(userinfo_response.body)
198198
end
199-
user_info['login'] = user_info[RedmineOauth.custom_uid_field]
200-
email = user_info[RedmineOauth.custom_email_field]
199+
user_info['login'] = user_info[oauth_provider.custom_uid_field]
200+
email = user_info[oauth_provider.custom_email_field]
201201
else
202202
raise StandardError, l(:oauth_invalid_provider)
203203
end
@@ -229,7 +229,7 @@ def oauth_callback
229229

230230
# Try to log in
231231
set_params
232-
try_to_login email, user_info, non_default_roles
232+
try_to_login email, user_info, non_default_roles, oauth_provider
233233
session[:oauth_login] = oauth_provider.id
234234
rescue StandardError => e
235235
Rails.logger.error e.message
@@ -269,13 +269,13 @@ def set_params
269269
session.delete :oauth_autologin
270270
end
271271

272-
def try_to_login(email, info, role_names)
272+
def try_to_login(email, info, role_names, oauth_provider)
273273
# Login name
274274
login = info['login']
275275
login ||= info['unique_name']
276276
login ||= info['preferred_username']
277277
# Find the user
278-
user = case RedmineOauth.identify_user_by
278+
user = case oauth_provider.identify_user_by
279279
when 'login'
280280
User.where('LOWER(login) = ?', login.downcase).first
281281
else
@@ -302,8 +302,8 @@ def try_to_login(email, info, role_names)
302302
# Create on the fly
303303
user = User.new
304304
user.mail = email
305-
user.firstname = info[RedmineOauth.custom_firstname_field]
306-
user.lastname = info[RedmineOauth.custom_lastname_field]
305+
user.firstname = info[oauth_provider.custom_firstname_field]
306+
user.lastname = info[oauth_provider.custom_lastname_field]
307307
first_name, last_name = info['name'].split if info['name'].present?
308308
user.firstname ||= first_name
309309
user.lastname ||= last_name
@@ -332,7 +332,7 @@ def try_to_login(email, info, role_names)
332332
raise StandardError, l(:notice_account_invalid_credentials)
333333
end
334334

335-
if RedmineOauth.enable_group_roles?
335+
if oauth_provider.enable_group_roles?
336336
desired_groups = Group.where(lastname: role_names)
337337
user.group_ids = desired_groups.ids
338338
end
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
# frozen_string_literal: true
2+
3+
# Redmine plugin OAuth
4+
#
5+
# Karel Pičman <karel.picman@kontron.com>
6+
#
7+
# This file is part of Redmine OAuth plugin.
8+
#
9+
# Redmine OAuth plugin is free software: you can redistribute it and/or modify it under the terms of the GNU General
10+
# Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any
11+
# later version.
12+
#
13+
# Redmine OAuth plugin is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even
14+
# the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
15+
# more details.
16+
#
17+
# You should have received a copy of the GNU General Public License along with Redmine OAuth plugin. If not, see
18+
# <https://www.gnu.org/licenses/>.
19+
20+
# OauthProviders DB migration
21+
class EnableGroupRoles < ActiveRecord::Migration[7.2]
22+
def up
23+
add_column :oauth_providers, :enable_group_roles, :boolean, null: false, default: false
24+
end
25+
end

0 commit comments

Comments
 (0)