MCPcopy
hub / github.com/oauth2-proxy/oauth2-proxy / getEmail

Method getEmail

providers/github.go:338–367  ·  view source on GitHub ↗

getEmail updates the SessionState Email

(ctx context.Context, s *sessions.SessionState)

Source from the content-addressed store, hash-verified

336
337// getEmail updates the SessionState Email
338func (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
370func (p *GitHubProvider) getUser(ctx context.Context, s *sessions.SessionState) error {

Calls 8

makeGitHubAPIEndpointMethod · 0.95
NewFunction · 0.92
makeGitHubHeaderFunction · 0.85
UnmarshalIntoMethod · 0.65
DoMethod · 0.65
WithHeadersMethod · 0.65
WithContextMethod · 0.65
StringMethod · 0.45