From c733b0c4f611919498573b55ad89dca854e43b3c Mon Sep 17 00:00:00 2001 From: larosamo Date: Thu, 24 Oct 2019 13:28:36 +0200 Subject: [PATCH] Custom redirect_uri --- README.md | 1 + app/controllers/redmine_oauth_controller.rb | 14 +++++++++++--- app/views/settings/_azure_settings.html.erb | 4 ++++ init.rb | 3 ++- 4 files changed, 18 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index f13170e..3d6d842 100644 --- a/README.md +++ b/README.md @@ -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 diff --git a/app/controllers/redmine_oauth_controller.rb b/app/controllers/redmine_oauth_controller.rb index df8509c..8290b00 100644 --- a/app/controllers/redmine_oauth_controller.rb +++ b/app/controllers/redmine_oauth_controller.rb @@ -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 @@ -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'] diff --git a/app/views/settings/_azure_settings.html.erb b/app/views/settings/_azure_settings.html.erb index ff0d635..b39ff9d 100644 --- a/app/views/settings/_azure_settings.html.erb +++ b/app/views/settings/_azure_settings.html.erb @@ -14,6 +14,10 @@ <%= text_area_tag "settings[allowed_domains]", @settings['allowed_domains'], :rows => 5 %>

+

+ + <%= text_field_tag 'settings[redirect_uri]', @settings['redirect_uri'] %> +

<%= check_box_tag "settings[azure_oauth_authentication]", true, @settings['azure_oauth_authentication'] %> diff --git a/init.rb b/init.rb index 92dc3f3..d892914 100644 --- a/init.rb +++ b/init.rb @@ -13,6 +13,7 @@ :client_id => "", :client_secret => "", :github_oauth_autentication => false, - :allowed_domains => "" + :allowed_domains => "", + :redirect_uri => "" }, :partial => 'settings/azure_settings' end