@@ -1773,12 +1773,6 @@ func configureGithubOAuth2(instrument *promoauth.Factory, accessURL *url.URL, cl
1773
1773
Slug :parts [1 ],
1774
1774
})
1775
1775
}
1776
- createClient := func (client * http.Client ) (* github.Client ,error ) {
1777
- if enterpriseBaseURL != "" {
1778
- return github .NewEnterpriseClient (enterpriseBaseURL ,"" ,client )
1779
- }
1780
- return github .NewClient (client ),nil
1781
- }
1782
1776
1783
1777
endpoint := xgithub .Endpoint
1784
1778
if enterpriseBaseURL != "" {
@@ -1800,40 +1794,50 @@ func configureGithubOAuth2(instrument *promoauth.Factory, accessURL *url.URL, cl
1800
1794
}
1801
1795
}
1802
1796
1797
+ instrumentedOauth := instrument .NewGithub ("github-login" ,& oauth2.Config {
1798
+ ClientID :clientID ,
1799
+ ClientSecret :clientSecret ,
1800
+ Endpoint :endpoint ,
1801
+ RedirectURL :redirectURL .String (),
1802
+ Scopes : []string {
1803
+ "read:user" ,
1804
+ "read:org" ,
1805
+ "user:email" ,
1806
+ },
1807
+ })
1808
+
1809
+ createClient := func (client * http.Client ,source promoauth.Oauth2Source ) (* github.Client ,error ) {
1810
+ client = instrumentedOauth .InstrumentHTTPClient (client ,source )
1811
+ if enterpriseBaseURL != "" {
1812
+ return github .NewEnterpriseClient (enterpriseBaseURL ,"" ,client )
1813
+ }
1814
+ return github .NewClient (client ),nil
1815
+ }
1816
+
1803
1817
return & coderd.GithubOAuth2Config {
1804
- OAuth2Config :instrument .NewGithub ("github-login" ,& oauth2.Config {
1805
- ClientID :clientID ,
1806
- ClientSecret :clientSecret ,
1807
- Endpoint :endpoint ,
1808
- RedirectURL :redirectURL .String (),
1809
- Scopes : []string {
1810
- "read:user" ,
1811
- "read:org" ,
1812
- "user:email" ,
1813
- },
1814
- }),
1818
+ OAuth2Config :instrumentedOauth ,
1815
1819
AllowSignups :allowSignups ,
1816
1820
AllowEveryone :allowEveryone ,
1817
1821
AllowOrganizations :allowOrgs ,
1818
1822
AllowTeams :allowTeams ,
1819
1823
AuthenticatedUser :func (ctx context.Context ,client * http.Client ) (* github.User ,error ) {
1820
- api ,err := createClient (client )
1824
+ api ,err := createClient (client , promoauth . SourceGitAPIAuthUser )
1821
1825
if err != nil {
1822
1826
return nil ,err
1823
1827
}
1824
1828
user ,_ ,err := api .Users .Get (ctx ,"" )
1825
1829
return user ,err
1826
1830
},
1827
1831
ListEmails :func (ctx context.Context ,client * http.Client ) ([]* github.UserEmail ,error ) {
1828
- api ,err := createClient (client )
1832
+ api ,err := createClient (client , promoauth . SourceGitAPIListEmails )
1829
1833
if err != nil {
1830
1834
return nil ,err
1831
1835
}
1832
1836
emails ,_ ,err := api .Users .ListEmails (ctx ,& github.ListOptions {})
1833
1837
return emails ,err
1834
1838
},
1835
1839
ListOrganizationMemberships :func (ctx context.Context ,client * http.Client ) ([]* github.Membership ,error ) {
1836
- api ,err := createClient (client )
1840
+ api ,err := createClient (client , promoauth . SourceGitAPIOrgMemberships )
1837
1841
if err != nil {
1838
1842
return nil ,err
1839
1843
}
@@ -1846,7 +1850,7 @@ func configureGithubOAuth2(instrument *promoauth.Factory, accessURL *url.URL, cl
1846
1850
return memberships ,err
1847
1851
},
1848
1852
TeamMembership :func (ctx context.Context ,client * http.Client ,org ,teamSlug ,username string ) (* github.Membership ,error ) {
1849
- api ,err := createClient (client )
1853
+ api ,err := createClient (client , promoauth . SourceGitAPITeamMemberships )
1850
1854
if err != nil {
1851
1855
return nil ,err
1852
1856
}