add option for debugging of auth

This commit is contained in:
Sam 2016-05-25 15:44:18 +10:00
parent 7584d84986
commit 870361be98
3 changed files with 10 additions and 0 deletions

View File

@ -12,4 +12,5 @@ en:
oauth2_json_email_path: "Path in the OAuth2 User JSON to the user's email: user.email.primary" 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_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_send_auth_header: "Send the token as an HTTP Authorization header"
oauth2_debug_auth: "Include rich debugging information in your logs"

View File

@ -13,6 +13,7 @@ login:
oauth2_json_email_path: '' oauth2_json_email_path: ''
oauth2_email_verified: false oauth2_email_verified: false
oauth2_send_auth_header: true oauth2_send_auth_header: true
oauth2_debug_auth: false
oauth2_button_title: oauth2_button_title:
default: 'with OAuth2' default: 'with OAuth2'
client: true client: true

View File

@ -48,10 +48,17 @@ class OAuth2BasicAuthenticator < ::Auth::OAuth2Authenticator
end end
end end
def debug(info)
Rails.logger.warn("OAuth2 Debugging: #{info}") if SiteSetting.oauth2_debug_auth
end
def fetch_user_details(token) def fetch_user_details(token)
user_json_url = SiteSetting.oauth2_user_json_url.sub(':token', 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) user_json = JSON.parse(open(user_json_url, 'Authorization' => "Bearer #{token}" ).read)
debug("user_json: #{user_json}")
result = {} result = {}
if user_json.present? if user_json.present?
json_walk(result, user_json, :user_id) json_walk(result, user_json, :user_id)
@ -64,6 +71,7 @@ class OAuth2BasicAuthenticator < ::Auth::OAuth2Authenticator
end end
def after_authenticate(auth) def after_authenticate(auth)
debug("auth response \n\n#{auth}")
result = Auth::Result.new result = Auth::Result.new
token = auth['credentials']['token'] token = auth['credentials']['token']
user_details = fetch_user_details(token) user_details = fetch_user_details(token)