Skip to content

Commit

Permalink
Update plugin to work with Redmine 3.4.x
Browse files Browse the repository at this point in the history
  • Loading branch information
ricemery committed Mar 20, 2018
1 parent 3924e03 commit cf3dce4
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 19 deletions.
22 changes: 11 additions & 11 deletions app/controllers/redmine_oauth_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,20 +6,20 @@ class RedmineOauthController < AccountController
include Helpers::MailHelper
include Helpers::Checker
def oauth_azure
if Setting.plugin_redmine_omniauth_azure[:azure_oauth_authentication]
session[:back_url] = params[:back_url]
if Setting.plugin_redmine_omniauth_azure['azure_oauth_authentication']
session['back_url'] = params['back_url']
redirect_to oauth_client.auth_code.authorize_url(:redirect_uri => oauth_azure_callback_url, :scope => scopes)
else
password_authentication
end
end

def oauth_azure_callback
if params[:error]
flash[:error] = l(:notice_access_denied)
if params['error']
flash['error'] = l(:notice_access_denied)
redirect_to signin_path
else
token = oauth_client.auth_code.get_token(params[:code], :redirect_uri => oauth_azure_callback_url, :resource => "00000002-0000-0000-c000-000000000000")
token = oauth_client.auth_code.get_token(params['code'], :redirect_uri => oauth_azure_callback_url, :resource => "00000002-0000-0000-c000-000000000000")
user_info = JWT.decode(token.token, nil, false)
logger.error user_info

Expand All @@ -28,7 +28,7 @@ def oauth_azure_callback
if email
checked_try_to_login email, user_info.first
else
flash[:error] = l(:notice_no_verified_email_we_could_use)
flash['error'] = l(:notice_no_verified_email_we_could_use)
redirect_to signin_path
end
end
Expand All @@ -38,13 +38,13 @@ def checked_try_to_login(email, user)
if allowed_domain_for?(email)
try_to_login email, user
else
flash[:error] = l(:notice_domain_not_allowed, :domain => parse_email(email)[:domain])
flash['error'] = l(:notice_domain_not_allowed, :domain => parse_email(email)['domain'])
redirect_to signin_path
end
end

def try_to_login email, info
params[:back_url] = session[:back_url]
params['back_url'] = session['back_url']
session.delete(:back_url)

user = User.joins(:email_addresses)
Expand Down Expand Up @@ -88,10 +88,10 @@ def try_to_login email, info
end

def oauth_client
@client ||= OAuth2::Client.new(settings[:client_id], settings[:client_secret],
@client ||= OAuth2::Client.new(settings['client_id'], settings['client_secret'],
:site => 'https://login.windows.net',
:authorize_url => '/' + settings[:tenant_id] + '/oauth2/authorize',
:token_url => '/' + settings[:tenant_id] + '/oauth2/token')
:authorize_url => '/' + settings['tenant_id'] + '/oauth2/authorize',
:token_url => '/' + settings['tenant_id'] + '/oauth2/token')
end

def settings
Expand Down
2 changes: 1 addition & 1 deletion app/views/hooks/_view_account_login_bottom.html.erb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<%= stylesheet_link_tag 'buttons', :plugin => 'redmine_omniauth_azure' %>

<% if Setting.plugin_redmine_omniauth_azure[:azure_oauth_authentication] %>
<% if Setting.plugin_redmine_omniauth_azure['azure_oauth_authentication'] %>
<%= link_to oauth_azure_path(:back_url => back_url) do %>
<%= button_tag :class => 'button-login' do %>
<%= image_tag('/plugin_assets/redmine_omniauth_azure/images/azure_login_icon.png', :class => 'button-login-icon', :alt => l(:login_via_azure)) %>
Expand Down
10 changes: 5 additions & 5 deletions app/views/settings/_azure_settings.html.erb
Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@
<p>
<label>Client ID:</label>
<%= text_field_tag 'settings[client_id]', @settings[:client_id] %>
<%= text_field_tag 'settings[client_id]', @settings['client_id'] %>
</p>
<p>
<label>Client Secret:</label>
<%= text_field_tag 'settings[client_secret]', @settings[:client_secret] %>
<%= text_field_tag 'settings[client_secret]', @settings['client_secret'] %>
</p>
<p>
<label>Tenant ID:</label>
<%= text_field_tag 'settings[tenant_id]', @settings[:tenant_id] %>
<%= text_field_tag 'settings[tenant_id]', @settings['tenant_id'] %>
</p>
<p>
<label>Available domains</label>
<%= text_area_tag "settings[allowed_domains]", @settings[:allowed_domains], :rows => 5 %>
<%= text_area_tag "settings[allowed_domains]", @settings['allowed_domains'], :rows => 5 %>
</p>
<p>
<label>Oauth authentication:</label>
<%= check_box_tag "settings[azure_oauth_authentication]", true, @settings[:azure_oauth_authentication] %>
<%= check_box_tag "settings[azure_oauth_authentication]", true, @settings['azure_oauth_authentication'] %>
</p>
4 changes: 2 additions & 2 deletions lib/helpers/checker.rb
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
module Helpers
module Checker
def allowed_domain_for? email
allowed_domains = Setting.plugin_redmine_omniauth_azure[:allowed_domains]
allowed_domains = Setting.plugin_redmine_omniauth_azure['allowed_domains']
return unless allowed_domains
allowed_domains = allowed_domains.split
return true if allowed_domains.empty?
allowed_domains.index(parse_email(email)[:domain])
allowed_domains.index(parse_email(email)['domain'])
end
end
end

0 comments on commit cf3dce4

Please sign in to comment.