getEmail updates the SessionState Email
(ctx context.Context, s *sessions.SessionState)
| 336 | |
| 337 | // getEmail updates the SessionState Email |
| 338 | func (p *GitHubProvider) getEmail(ctx context.Context, s *sessions.SessionState) error { |
| 339 | |
| 340 | var emails []struct { |
| 341 | Email string `json:"email"` |
| 342 | Primary bool `json:"primary"` |
| 343 | Verified bool `json:"verified"` |
| 344 | } |
| 345 | |
| 346 | endpoint := p.makeGitHubAPIEndpoint("/user/emails", nil) |
| 347 | |
| 348 | err := requests.New(endpoint.String()). |
| 349 | WithContext(ctx). |
| 350 | WithHeaders(makeGitHubHeader(s.AccessToken)). |
| 351 | Do(). |
| 352 | UnmarshalInto(&emails) |
| 353 | if err != nil { |
| 354 | return err |
| 355 | } |
| 356 | |
| 357 | for _, email := range emails { |
| 358 | if email.Verified { |
| 359 | if email.Primary { |
| 360 | s.Email = email.Email |
| 361 | return nil |
| 362 | } |
| 363 | } |
| 364 | } |
| 365 | |
| 366 | return nil |
| 367 | } |
| 368 | |
| 369 | // getUser updates the SessionState User |
| 370 | func (p *GitHubProvider) getUser(ctx context.Context, s *sessions.SessionState) error { |