Smarter LinkedIn oAuth Library
LinkedIn OpenID Connect and OAuth2 backends for python-social-auth.
They adapt the backends that python-social-auth documents at https://python-social-auth.readthedocs.io/en/latest/backends/linkedin.html to LinkedIn’s current api.
- class smarter.lib.social_core.backends.linkedin.LinkedinMobileOAuth2(strategy=None, redirect_uri=None)[source]
Bases:
LinkedinOAuth2LinkedIn backend for the mobile SDK, which adds the
x-li-src: msdkheader.- name = 'linkedin-mobile-oauth2'
- class smarter.lib.social_core.backends.linkedin.LinkedinOAuth2(strategy=None, redirect_uri=None)[source]
Bases:
BaseOAuth2Python-social-auth backend for signing in with LinkedIn, by OAuth2 with the OpenID Connect scopes.
- ACCESS_TOKEN_URL = 'https://www.linkedin.com/oauth/v2/accessToken'
- AUTHORIZATION_URL = 'https://www.linkedin.com/oauth/v2/authorization'
- EXTRA_DATA: list[str | tuple[str, str] | tuple[str, str, bool]] | None = [('id', 'id'), ('expires_in', 'expires'), ('firstName', 'first_name'), ('lastName', 'last_name'), ('refresh_token', 'refresh_token'), ('refresh_token_expires_in', 'refresh_expires_in')]
- REDIRECT_STATE = False
- USER_DETAILS_URL = 'https://api.linkedin.com/v2/userinfo?projection=({projection})'
- USER_EMAILS_URL = 'https://api.linkedin.com/v2/emailAddress?q=members&projection=(elements*(handle~))'
- email_data(access_token, *args, **kwargs)[source]
Fetch the user’s email addresses from LinkedIn.
- Parameters:
access_token – The OAuth2 access token.
args – Unused.
kwargs – Unused.
- Returns:
The non-empty email addresses.
- get_user_details(response)[source]
Return the user’s details from their LinkedIn profile.
A profile without both a first and a last name gets
unknownnames, and one without an email address getsunknown@mail.com.- Parameters:
response (
dict) – The profile, fromuser_data().- Return type:
- Returns:
A dict of
username,fullname,first_name,last_nameandemail.
- name = 'linkedin-oauth2'
- request_access_token(*args, **kwargs)[source]
Request the access token, sending the form data as query parameters, as LinkedIn expects.
- Parameters:
args – Passed to the base class.
kwargs – Passed to the base class;
datais moved toparams.
- Returns:
The token response.
- user_data(access_token, *args, **kwargs)[source]
Fetch the user’s profile from LinkedIn, adding the first email address if
FIELD_SELECTORSasks for it.- Parameters:
access_token – The OAuth2 access token.
args – Passed to
email_data().kwargs – Passed to
email_data().
- Returns:
The profile dict.
- user_data_headers(access_token)[source]
Return the headers of LinkedIn api requests: the bearer token, and
Accept-LanguageifFORCE_PROFILE_LANGUAGEis set.A
FORCE_PROFILE_LANGUAGEof True means the strategy’s current language.
- class smarter.lib.social_core.backends.linkedin.LinkedinOpenIdConnect(strategy=None, redirect_uri=None)[source]
Bases:
OpenIdConnectAuthLinkedin OpenID Connect backend.
Oauth2 has been deprecated as of August 1, 2023. https://learn.microsoft.com/en-us/linkedin/consumer/integrations/self-serve/sign-in-with-linkedin-v2?context=linkedin/consumer/context
- TOKEN_ENDPOINT_AUTH_METHOD = 'client_secret_post'
- name = 'linkedin-openidconnect'