Skip to content

Commit 21f434c

Browse files
committed
handel github emial fetched
1 parent f8f051f commit 21f434c

File tree

1 file changed

+20
-1
lines changed

1 file changed

+20
-1
lines changed

lib/oauth2_basic_authenticator.rb

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -171,12 +171,31 @@ def fetch_user_details(token, id)
171171

172172
log("user_json:\n#{user_json.to_yaml}")
173173

174+
# Fetch email separately
175+
email_json_url = "https://api.github.com/user/emails"
176+
email_json_response = connection.run_request(:get, email_json_url, nil, headers)
177+
178+
log <<-LOG
179+
email_json request: GET #{email_json_url}
180+
181+
request headers: #{headers}
182+
183+
response status: #{email_json_response.status}
184+
185+
response body:
186+
#{email_json_response.body}
187+
LOG
188+
189+
if email_json_response.status == 200
190+
email_json = JSON.parse(email_json_response.body)
191+
primary_email = email_json.find { |e| e["primary"] }&.dig("email")
192+
end
174193
result = {}
175194
if user_json.present?
176195
json_walk(result, user_json, :user_id)
177196
json_walk(result, user_json, :username)
178197
json_walk(result, user_json, :name)
179-
json_walk(result, user_json, :email)
198+
result[:email] = primary_email if primary_email.present?
180199
json_walk(result, user_json, :email_verified)
181200
json_walk(result, user_json, :avatar)
182201

0 commit comments

Comments
 (0)