@@ -147,30 +147,29 @@ def log(info)
147
147
end
148
148
149
149
def fetch_user_details ( token , id )
150
- user_json_url = SiteSetting . oauth2_user_json_url . sub ( ":token" , token . to_s ) . sub ( ":id" , id . to_s )
151
- user_json_method = SiteSetting . oauth2_user_json_url_method . downcase . to_sym
152
-
150
+ user_json_url = "https://api.github.com/user"
151
+ user_emails_url = "https://api.github.com/user/emails"
152
+ user_json_method = :get
153
+
153
154
bearer_token = "Bearer #{ token } "
154
155
connection = Faraday . new { |f | f . adapter FinalDestination ::FaradayAdapter }
155
156
headers = { "Authorization" => bearer_token , "Accept" => "application/json" }
157
+
158
+ # Fetch user details
156
159
user_json_response = connection . run_request ( user_json_method , user_json_url , nil , headers )
157
-
160
+
158
161
log <<-LOG
159
162
user_json request: #{ user_json_method } #{ user_json_url }
160
-
161
163
request headers: #{ headers }
162
-
163
164
response status: #{ user_json_response . status }
164
-
165
165
response body:
166
166
#{ user_json_response . body }
167
167
LOG
168
-
168
+
169
169
if user_json_response . status == 200
170
170
user_json = JSON . parse ( user_json_response . body )
171
-
172
171
log ( "user_json:\n #{ user_json . to_yaml } " )
173
-
172
+
174
173
result = { }
175
174
if user_json . present?
176
175
json_walk ( result , user_json , :user_id )
@@ -180,21 +179,22 @@ def fetch_user_details(token, id)
180
179
json_walk ( result , user_json , :email_verified )
181
180
json_walk ( result , user_json , :avatar )
182
181
end
182
+
183
183
# Fetch user emails
184
184
user_emails_response = connection . run_request ( user_json_method , user_emails_url , nil , headers )
185
-
185
+
186
186
log <<-LOG
187
187
user_emails request: #{ user_json_method } #{ user_emails_url }
188
188
request headers: #{ headers }
189
189
response status: #{ user_emails_response . status }
190
190
response body:
191
191
#{ user_emails_response . body }
192
192
LOG
193
-
193
+
194
194
if user_emails_response . status == 200
195
195
user_emails = JSON . parse ( user_emails_response . body )
196
196
log ( "user_emails:\n #{ user_emails . to_yaml } " )
197
-
197
+
198
198
primary_email = user_emails . find { |email | email [ "primary" ] && email [ "verified" ] }
199
199
if primary_email
200
200
result [ :email ] = primary_email [ "email" ]
@@ -206,12 +206,13 @@ def fetch_user_details(token, id)
206
206
# Handle error fetching emails
207
207
result [ :email ] = nil
208
208
end
209
-
209
+
210
210
result
211
211
else
212
212
nil
213
213
end
214
214
end
215
+
215
216
216
217
def primary_email_verified? ( auth )
217
218
return true if SiteSetting . oauth2_email_verified
0 commit comments