Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Custom redirect_uri #6

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ To make plugin to work properly
* Login as administrator. In top menu select "Administration". Choose menu item Plugins. In plugins list choose "Redmine Omniauth Azure plugin". Press "Configure".
* Fill Сlient ID & Client Secret & Tenant ID by corresponding values, obtained by Azure.
* Put the check "Oauth authentification", to make it possible to login through Azure. Click Apply. Users can now to use apportunity to login via Azure.
* redirect_uri is optional , if you leave empty it will use redmine_url_root but if you fill this field the value introduced will be used as parameter in the calls.

Additionaly
* Setup value Autologin in Settings on tab Authentification
Expand Down
14 changes: 11 additions & 3 deletions app/controllers/redmine_oauth_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,11 @@ class RedmineOauthController < AccountController
def oauth_azure
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)
if Setting.plugin_redmine_omniauth_azure['redirect_uri'] && !Setting.plugin_redmine_omniauth_azure['redirect_uri'].empty?
redirect_to oauth_client.auth_code.authorize_url(:redirect_uri => Setting.plugin_redmine_omniauth_azure['redirect_uri'], :scope => scopes)
else
redirect_to oauth_client.auth_code.authorize_url(:redirect_uri => oauth_azure_callback_url, :scope => scopes)
end
else
password_authentication
end
Expand All @@ -19,8 +23,12 @@ def oauth_azure_callback
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")
user_info = JWT.decode(token.token, nil, false)
if Setting.plugin_redmine_omniauth_azure['redirect_uri'] && !Setting.plugin_redmine_omniauth_azure['redirect_uri'].empty?
token = oauth_client.auth_code.get_token(params['code'], :redirect_uri => Setting.plugin_redmine_omniauth_azure['redirect_uri'], :resource => "00000002-0000-0000-c000-000000000000")
else
token = oauth_client.auth_code.get_token(params['code'], :redirect_uri => oauth_azure_callback_url, :resource => "00000002-0000-0000-c000-000000000000")
end
user_info = JWT.decode(token.token, nil, false)
logger.error user_info

email = user_info.first['unique_name']
Expand Down
4 changes: 4 additions & 0 deletions app/views/settings/_azure_settings.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,10 @@
<label>Available domains</label>
<%= text_area_tag "settings[allowed_domains]", @settings['allowed_domains'], :rows => 5 %>
</p>
<p>
<label>Redirect uri</label>
<%= text_field_tag 'settings[redirect_uri]', @settings['redirect_uri'] %>
</p>
<p>
<label>Oauth authentication:</label>
<%= check_box_tag "settings[azure_oauth_authentication]", true, @settings['azure_oauth_authentication'] %>
Expand Down
3 changes: 2 additions & 1 deletion init.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
:client_id => "",
:client_secret => "",
:github_oauth_autentication => false,
:allowed_domains => ""
:allowed_domains => "",
:redirect_uri => ""
}, :partial => 'settings/azure_settings'
end