9 "github.com/oauth2-proxy/oauth2-proxy/v7/pkg/apis/sessions"
10 "github.com/oauth2-proxy/oauth2-proxy/v7/pkg/requests"
13// LinkedInProvider represents an LinkedIn based Identity Provider
14type LinkedInProvider struct {
18var _ Provider = (*LinkedInProvider)(nil)
21 linkedinProviderName = "LinkedIn"
22 linkedinDefaultScope = "r_emailaddress r_basicprofile"
26 // Default Login URL for LinkedIn.
27 // Pre-parsed URL of https://www.linkedin.com/uas/oauth2/authorization.
28 linkedinDefaultLoginURL = &url.URL{
30 Host: "www.linkedin.com",
31 Path: "/uas/oauth2/authorization",
34 // Default Redeem URL for LinkedIn.
35 // Pre-parsed URL of https://www.linkedin.com/uas/oauth2/accessToken.
36 linkedinDefaultRedeemURL = &url.URL{
38 Host: "www.linkedin.com",
39 Path: "/uas/oauth2/accessToken",
42 // Default Profile URL for LinkedIn.
43 // Pre-parsed URL of https://www.linkedin.com/v1/people/~/email-address.
44 linkedinDefaultProfileURL = &url.URL{
46 Host: "www.linkedin.com",
47 Path: "/v1/people/~/email-address",
51// NewLinkedInProvider initiates a new LinkedInProvider
52func NewLinkedInProvider(p *ProviderData) *LinkedInProvider {
53 p.setProviderDefaults(providerDefaults{
54 name: linkedinProviderName,
55 loginURL: linkedinDefaultLoginURL,
56 redeemURL: linkedinDefaultRedeemURL,
57 profileURL: linkedinDefaultProfileURL,
58 validateURL: linkedinDefaultProfileURL,
59 scope: linkedinDefaultScope,
61 return &LinkedInProvider{ProviderData: p}
64func makeLinkedInHeader(accessToken string) http.Header {
65 // extra headers required by the LinkedIn API when making authenticated requests
66 extraHeaders := map[string]string{
67 acceptHeader: acceptApplicationJSON,
68 "x-li-format": "json",
70 return makeAuthorizationHeader(tokenTypeBearer, accessToken, extraHeaders)
73// GetEmailAddress returns the Account email address
74func (p *LinkedInProvider) GetEmailAddress(ctx context.Context, s *sessions.SessionState) (string, error) {
75 if s.AccessToken == "" {
76 return "", errors.New("missing access token")
79 requestURL := p.ProfileURL.String() + "?format=json"
80 json, err := requests.New(requestURL).
82 WithHeaders(makeLinkedInHeader(s.AccessToken)).
89 email, err := json.String()
96// ValidateSessionState validates the AccessToken
97func (p *LinkedInProvider) ValidateSessionState(ctx context.Context, s *sessions.SessionState) bool {
98 return validateToken(ctx, p, s.AccessToken, makeLinkedInHeader(s.AccessToken))
keysesc to close
- j k
- move down, up
- enter
- open
- esc
- back, or up a level
- 1 2 3 4
- readme, files, commits, refs
- /
- filter
- y
- copy the clone command
- c
- compare the chosen commit with another (or shift-click both)
- ?
- show or hide this list