git.iko.soy/typeable/oauth2-proxy
on master help sign in
linkedidn: Update provider to v2 (#1315)

* linkedin: Update provider to v2 * changelog: Add change

commitfd5e23e1c55ec99f552321a317770015a4b788e1 authorDavid Emanuel Buchmann <david.buchmann@gmail.com> dateMon 4 Oct 2021, 16:58 (5 years ago) parent3957183
3 files changed+13−13
CHANGELOG.md+1 providers/linkedin.go+6−7 providers/linkedin_test.go+6−6
CHANGELOG.md+1
@@ -18,6 +18,7 @@
1818
1919## Changes since v7.1.3
2020
21+- [#1315](https://github.com/oauth2-proxy/oauth2-proxy/pull/1315) linkedin: Update provider to v2 (@wuurrd)
2122- [#1348](https://github.com/oauth2-proxy/oauth2-proxy/pull/1348) Using the native httputil proxy code for websockets rather than yhat/wsutil to properly handle HTTP-level failures (@thetrime)
2223- [#1379](https://github.com/oauth2-proxy/oauth2-proxy/pull/1379) Fix the manual sign in with --htpasswd-user-group switch (@janrotter)
2324- [#1337](https://github.com/oauth2-proxy/oauth2-proxy/pull/1337) Changing user field type to text when using htpasswd (@pburgisser)
providers/linkedin.go+6−7
@@ -19,7 +19,7 @@ var _ Provider = (*LinkedInProvider)(nil)
1919
2020const (
2121 linkedinProviderName = "LinkedIn"
22− linkedinDefaultScope = "r_emailaddress r_basicprofile"
22+ linkedinDefaultScope = "r_emailaddress r_liteprofile"
2323)
2424
2525var (
@@ -28,7 +28,7 @@ var (
2828 linkedinDefaultLoginURL = &url.URL{
2929 Scheme: "https",
3030 Host: "www.linkedin.com",
31− Path: "/uas/oauth2/authorization",
31+ Path: "/oauth/v2/authorization",
3232 }
3333
3434 // Default Redeem URL for LinkedIn.
@@ -43,8 +43,8 @@ var (
4343 // Pre-parsed URL of https://www.linkedin.com/v1/people/~/email-address.
4444 linkedinDefaultProfileURL = &url.URL{
4545 Scheme: "https",
46− Host: "www.linkedin.com",
47− Path: "/v1/people/~/email-address",
46+ Host: "api.linkedin.com",
47+ Path: "/v2/emailAddress",
4848 }
4949)
5050
@@ -76,7 +76,7 @@ func (p *LinkedInProvider) GetEmailAddress(ctx context.Context, s *sessions.Sess
7676 return "", errors.New("missing access token")
7777 }
7878
79− requestURL := p.ProfileURL.String() + "?format=json"
79+ requestURL := p.ProfileURL.String() + "?q=members&projection=(elements*(handle~))"
8080 json, err := requests.New(requestURL).
8181 WithContext(ctx).
8282 WithHeaders(makeLinkedInHeader(s.AccessToken)).
@@ -85,8 +85,7 @@ func (p *LinkedInProvider) GetEmailAddress(ctx context.Context, s *sessions.Sess
8585 if err != nil {
8686 return "", err
8787 }
88−
89− email, err := json.String()
88+ email, err := json.Get("elements").GetIndex(0).Get("handle~").Get("emailAddress").String()
9089 if err != nil {
9190 return "", err
9291 }
providers/linkedin_test.go+6−6
@@ -30,7 +30,7 @@ func testLinkedInProvider(hostname string) *LinkedInProvider {
3030}
3131
3232func testLinkedInBackend(payload string) *httptest.Server {
33− path := "/v1/people/~/email-address"
33+ path := "/v2/emailAddress"
3434
3535 return httptest.NewServer(http.HandlerFunc(
3636 func(w http.ResponseWriter, r *http.Request) {
@@ -51,11 +51,11 @@ func TestNewLinkedInProvider(t *testing.T) {
5151 // Test that defaults are set when calling for a new provider with nothing set
5252 providerData := NewLinkedInProvider(&ProviderData{}).Data()
5353 g.Expect(providerData.ProviderName).To(Equal("LinkedIn"))
54− g.Expect(providerData.LoginURL.String()).To(Equal("https://www.linkedin.com/uas/oauth2/authorization"))
54+ g.Expect(providerData.LoginURL.String()).To(Equal("https://www.linkedin.com/oauth/v2/authorization"))
5555 g.Expect(providerData.RedeemURL.String()).To(Equal("https://www.linkedin.com/uas/oauth2/accessToken"))
56− g.Expect(providerData.ProfileURL.String()).To(Equal("https://www.linkedin.com/v1/people/~/email-address"))
57− g.Expect(providerData.ValidateURL.String()).To(Equal("https://www.linkedin.com/v1/people/~/email-address"))
58− g.Expect(providerData.Scope).To(Equal("r_emailaddress r_basicprofile"))
56+ g.Expect(providerData.ProfileURL.String()).To(Equal("https://api.linkedin.com/v2/emailAddress"))
57+ g.Expect(providerData.ValidateURL.String()).To(Equal("https://api.linkedin.com/v2/emailAddress"))
58+ g.Expect(providerData.Scope).To(Equal("r_emailaddress r_liteprofile"))
5959}
6060
6161func TestLinkedInProviderOverrides(t *testing.T) {
@@ -92,7 +92,7 @@ func TestLinkedInProviderOverrides(t *testing.T) {
9292}
9393
9494func TestLinkedInProviderGetEmailAddress(t *testing.T) {
95− b := testLinkedInBackend(`"user@linkedin.com"`)
95+ b := testLinkedInBackend(`{"elements":[{"handle~":{"emailAddress": "user@linkedin.com"}}]}`)
9696 defer b.Close()
9797
9898 bURL, _ := url.Parse(b.URL)