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

Method getUser

providers/github.go:370–396  ·  view source on GitHub ↗

getUser updates the SessionState User

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

Source from the content-addressed store, hash-verified

368
369// getUser updates the SessionState User
370func (p *GitHubProvider) getUser(ctx context.Context, s *sessions.SessionState) error {
371 var user struct {
372 Login string `json:"login"`
373 Email string `json:"email"`
374 }
375
376 endpoint := p.makeGitHubAPIEndpoint("/user", nil)
377
378 err := requests.New(endpoint.String()).
379 WithContext(ctx).
380 WithHeaders(makeGitHubHeader(s.AccessToken)).
381 Do().
382 UnmarshalInto(&user)
383 if err != nil {
384 return err
385 }
386
387 // Now that we have the username we can check collaborator status
388 if !p.isVerifiedUser(user.Login) && p.Org == "" && p.Repo != "" && p.Token != "" {
389 if ok, err := p.isCollaborator(ctx, user.Login, p.Token); err != nil || !ok {
390 return err
391 }
392 }
393
394 s.User = user.Login
395 return nil
396}
397
398func (p *GitHubProvider) isVerifiedUser(username string) bool {
399 for _, u := range p.Users {

Calls 10

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