add option for debugging of auth
This commit is contained in:
parent
7584d84986
commit
870361be98
|
@ -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"
|
||||
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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)
|
||||
|
|
Loading…
Reference in New Issue