I am using python-social-auth to log in my own web application from LinkedIn. I successfully logged in and redirect to my home page. The next step is to utilize the extra data (i.e. UserSocialAuth.extra_data). Could anyone give a example about how to access the extra data in either Django templates or Django views?
This is the settings I had.
SOCIAL_AUTH_LOGIN_URL = ''
SOCIAL_AUTH_PIPELINE = (
'social.pipeline.social_auth.social_details',
'social.pipeline.social_auth.social_uid',
'social.pipeline.social_auth.auth_allowed',
'social.pipeline.social_auth.social_user',
'social.pipeline.user.get_username',
'social.pipeline.user.create_user',
'social.pipeline.social_auth.associate_user',
'social.pipeline.social_auth.load_extra_data',
'social.pipeline.user.user_details'
)
SOCIAL_AUTH_LINKEDIN_OAUTH2_SCOPE = ['r_basicprofile', 'r_emailaddress', 'rw_company_admin', 'w_share']
SOCIAL_AUTH_LINKEDIN_OAUTH2_FIELD_SELECTORS = ['first-name', 'last-name', 'email-address', 'headline']
SOCIAL_AUTH_LINKEDIN_OAUTH2_EXTRA_DATA = [('id', 'id'),
('first-name', 'first_name'),
('last-name', 'last_name'),
('email-address', 'email_address'),
('headline', 'headline'),
('industry', 'industry')]
What I am going to do is like:
<html><body>Here we go! {{ user.first_name }} {{ user.last_name }}
{{ user.email }}
{{ user.extra_data.headline }}</body></html>
Any comments will be highly appreciated!
You can access the data in your Django view like so:
if request.user.is_authenticated:
linkedin_user = request.user.social_auth.get(provider ='linkedin-oauth2')
extra_data = linkedin_user.extra_data
And you can then inject the data in your template to be displayed
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With