* Fetch user info from GitHub * Used during OAuth completion to get user details
(token: string)
| 212 | * Used during OAuth completion to get user details |
| 213 | */ |
| 214 | async fetchUser(token: string): Promise<ProviderUser> { |
| 215 | const response = await net.fetch(`${this.config.apiUrl}/user`, { |
| 216 | headers: { |
| 217 | Authorization: `token ${token}`, |
| 218 | Accept: 'application/vnd.github.v3+json', |
| 219 | }, |
| 220 | }); |
| 221 | |
| 222 | if (!response.ok) { |
| 223 | throw new Error(`GitHub API error: ${response.statusText}`); |
| 224 | } |
| 225 | |
| 226 | const data = (await response.json()) as GitHubUserApiResponse; |
| 227 | |
| 228 | return { |
| 229 | id: String(data.id), |
| 230 | username: data.login, |
| 231 | name: data.name || data.login, |
| 232 | email: data.email || undefined, |
| 233 | avatarUrl: data.avatar_url, |
| 234 | }; |
| 235 | } |
| 236 | |
| 237 | /** |
| 238 | * Fetch user emails from GitHub with token |
no test coverage detected