From 870361be98e23eabd23901937c1025aba3579016 Mon Sep 17 00:00:00 2001 From: Sam Date: Wed, 25 May 2016 15:44:18 +1000 Subject: [PATCH] add option for debugging of auth --- config/locales/server.en.yml | 1 + config/settings.yml | 1 + plugin.rb | 8 ++++++++ 3 files changed, 10 insertions(+) diff --git a/config/locales/server.en.yml b/config/locales/server.en.yml index 3c69600..8d41da0 100644 --- a/config/locales/server.en.yml +++ b/config/locales/server.en.yml @@ -12,4 +12,5 @@ en: oauth2_json_email_path: "Path in the OAuth2 User JSON to the user's email: user.email.primary" oauth2_email_verified: "Check this if the OAuth2 site has verified the email" oauth2_send_auth_header: "Send the token as an HTTP Authorization header" + oauth2_debug_auth: "Include rich debugging information in your logs" diff --git a/config/settings.yml b/config/settings.yml index 31bb8f1..57f801c 100644 --- a/config/settings.yml +++ b/config/settings.yml @@ -13,6 +13,7 @@ login: oauth2_json_email_path: '' oauth2_email_verified: false oauth2_send_auth_header: true + oauth2_debug_auth: false oauth2_button_title: default: 'with OAuth2' client: true diff --git a/plugin.rb b/plugin.rb index 2eca4db..faa83ee 100644 --- a/plugin.rb +++ b/plugin.rb @@ -48,10 +48,17 @@ class OAuth2BasicAuthenticator < ::Auth::OAuth2Authenticator end end + def debug(info) + Rails.logger.warn("OAuth2 Debugging: #{info}") if SiteSetting.oauth2_debug_auth + end + def fetch_user_details(token) user_json_url = SiteSetting.oauth2_user_json_url.sub(':token', token) + debug("user_json_url: #{user_json_url}") user_json = JSON.parse(open(user_json_url, 'Authorization' => "Bearer #{token}" ).read) + debug("user_json: #{user_json}") + result = {} if user_json.present? json_walk(result, user_json, :user_id) @@ -64,6 +71,7 @@ class OAuth2BasicAuthenticator < ::Auth::OAuth2Authenticator end def after_authenticate(auth) + debug("auth response \n\n#{auth}") result = Auth::Result.new token = auth['credentials']['token'] user_details = fetch_user_details(token)