Authentication using Twitter

For social authentication using Twitter, add the following line to the AUTHENTICATION_BACKENDS setting in the settings.py file of your project:

'social_core.backends.twitter.TwitterOAuth',

You will need to create a new application in your Twitter account. Open https://apps.twitter.com/app/new in your browser. You will see the following form:

Enter the details of your application, including the following settings:

  • Website: http://mysite.com:8000/
  • Callback URL: http://mysite.com:8000/social-auth/complete/twitter/

Then, click on Create your Twitter application. You will see the application details. Click on Keys and Access Tokens. You should see the following information:

Copy the Consumer Key and Consumer Secret keys into the following settings in the settings.py file of your project:

SOCIAL_AUTH_TWITTER_KEY = 'XXX' # Twitter Consumer Key
SOCIAL_AUTH_TWITTER_SECRET = 'XXX' # Twitter Consumer Secret

Now, edit the registration/login.html template and add the following code to the <ul> element:

<li class="twitter"><a href="{% url "social:begin" "twitter" 
%}">Login with Twitter</a></li>

Open http://mysite.com:8000/account/login/ in your browser and click on the Login with Twitter link. You will be redirected to Twitter, and it will ask you to authorize the application as follows:

Click on Authorize app. You will be logged in and redirected to the dashboard page of your site.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset