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

Method GetEmailAddress

providers/bitbucket.go:95–190  ·  view source on GitHub ↗

GetEmailAddress returns the email of the authenticated user

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

Source from the content-addressed store, hash-verified

93
94// GetEmailAddress returns the email of the authenticated user
95func (p *BitbucketProvider) GetEmailAddress(ctx context.Context, s *sessions.SessionState) (string, error) {
96
97 var emails struct {
98 Values []struct {
99 Email string `json:"email"`
100 Primary bool `json:"is_primary"`
101 }
102 }
103 var teams struct {
104 Values []struct {
105 Name string `json:"username"`
106 }
107 }
108 var repositories struct {
109 Values []struct {
110 FullName string `json:"full_name"`
111 }
112 }
113
114 requestURL := p.ValidateURL.String() + "?access_token=" + s.AccessToken
115 err := requests.New(requestURL).
116 WithContext(ctx).
117 Do().
118 UnmarshalInto(&emails)
119 if err != nil {
120 logger.Errorf("failed making request: %v", err)
121 return "", err
122 }
123
124 if p.Team != "" {
125 teamURL := &url.URL{}
126 *teamURL = *p.ValidateURL
127 teamURL.Path = "/2.0/teams"
128
129 requestURL := teamURL.String() + "?role=member&access_token=" + s.AccessToken
130
131 err := requests.New(requestURL).
132 WithContext(ctx).
133 Do().
134 UnmarshalInto(&teams)
135 if err != nil {
136 logger.Errorf("failed requesting teams membership: %v", err)
137 return "", err
138 }
139 var found = false
140 for _, team := range teams.Values {
141 if p.Team == team.Name {
142 found = true
143 break
144 }
145 }
146 if !found {
147 logger.Error("team membership test failed, access denied")
148 return "", nil
149 }
150 }
151
152 if p.Repository != "" {

Callers

nothing calls this directly

Calls 7

NewFunction · 0.92
ErrorfFunction · 0.92
ErrorFunction · 0.92
UnmarshalIntoMethod · 0.65
DoMethod · 0.65
WithContextMethod · 0.65
StringMethod · 0.45

Tested by

no test coverage detected