From a9ad67c4c6f414e9128eddc5545ab4ac5125e29a Mon Sep 17 00:00:00 2001 From: David Taylor Date: Wed, 10 Mar 2021 12:29:58 +0000 Subject: [PATCH] FEATURE: Allow using a different authorize_url for signup (#34) If specified, the oauth2_authorize_signup_url will be used when the user starts the auth flow via the 'sign up' buttons in the UI. If not specified, the regular authorize_url continues to be used. --- config/locales/server.en.yml | 1 + config/settings.yml | 1 + plugin.rb | 5 +++++ 3 files changed, 7 insertions(+) diff --git a/config/locales/server.en.yml b/config/locales/server.en.yml index b92b1f8..dbfbfb1 100644 --- a/config/locales/server.en.yml +++ b/config/locales/server.en.yml @@ -7,6 +7,7 @@ en: oauth2_client_id: 'Client ID for custom OAuth2' oauth2_client_secret: 'Client Secret for custom OAuth2' oauth2_authorize_url: 'Authorization URL for OAuth2' + oauth2_authorize_signup_url: '(optional) Alternative authorization URL used when the "Sign Up" button is used' oauth2_token_url: 'Token URL for OAuth2' oauth2_token_url_method: 'Method used to fetch the Token URL' oauth2_callback_user_id_path: 'Path in the token response to the user id. eg: params.info.uuid' diff --git a/config/settings.yml b/config/settings.yml index 8185e30..7903986 100644 --- a/config/settings.yml +++ b/config/settings.yml @@ -5,6 +5,7 @@ login: oauth2_client_id: '' oauth2_client_secret: '' oauth2_authorize_url: '' + oauth2_authorize_signup_url: '' oauth2_token_url: '' oauth2_token_url_method: default: 'POST' diff --git a/plugin.rb b/plugin.rb index a89f50e..40a4218 100644 --- a/plugin.rb +++ b/plugin.rb @@ -101,6 +101,11 @@ class ::OAuth2BasicAuthenticator < Auth::ManagedAuthenticator } opts[:authorize_options] = SiteSetting.oauth2_authorize_options.split("|").map(&:to_sym) + if SiteSetting.oauth2_authorize_signup_url.present? && + ActionDispatch::Request.new(env).params["signup"].present? + opts[:client_options][:authorize_url] = SiteSetting.oauth2_authorize_signup_url + end + if SiteSetting.oauth2_send_auth_header? && SiteSetting.oauth2_send_auth_body? # For maximum compatibility we include both header and body auth by default # This is a little unusual, and utilising multiple authentication methods