Search code examples
djangodjango-rest-frameworkdjango-rest-auth

Where I can take access_token and token_secret for twitter


Maybe my question is very stupid.

But I couldn't find the answer neither in the official documentation of rest-auth nor there in questions.

I want to use authentication through Twitter.

I created the app in Twitter, put all the data into the model Social application According to the documentation I made view:

from allauth.socialaccount.providers.twitter.views import TwitterOAuthAdapter
from rest_auth.views import LoginView
from rest_auth.social_serializers import TwitterLoginSerializer
from rest_framework.permissions import AllowAny


class TwitterLogin(LoginView):
    serializer_class = TwitterLoginSerializer
    adapter_class = TwitterOAuthAdapter
    permission_classes = (AllowAny,)

Added url:

from django.urls import path

from .views import TwitterLogin


urlpatterns = [
    path('rest-auth/twitter/', TwitterLogin.as_view(), name='twitter_login')
]

Then went to the link: /rest-auth/twitter/ And got the request:

{
    "access_token": "",
    "token_secret": ""
}

I.e. these data must be transfer from front-end to the API endpoint.

The question is: how front-end will take acces_token and token_secret?

I don't understend this moment of authentication.

If somewhere there is a detailed description of this issue, or on this resource is already someone gave the answer to this question - I will be grateful for the link.


Solution

  • In your Twitter application you need to make sure the "Allow this application to be used to Sign in with Twitter?" option is enabled.

    Then you can follow these instructions in order to obtain the token and token secret https://dev.twitter.com/web/sign-in/implementing.

    Relevant section in allauth docs: https://django-allauth.readthedocs.io/en/latest/providers.html#id2