How can I return user ID with token in Django?

后端 未结 4 922
广开言路
广开言路 2020-12-21 00:34

I generate tokens using default view in Django:

url(r\'^login/\', rest_auth_views.obtain_auth_token),

I have a problem because my front-end

4条回答
  •  庸人自扰
    2020-12-21 01:15

    if you need to get user information on a webpage, you need to pass user information in a response of Login API or other API.

    While using Token based authentication, after login, access token and refresh token are generated which are shall be given to client in login API response. This access token shall be passed in header as:

    Authorization : Bearer 
    

    You need to put authentication_classes = [OAuth2Authentication] in your view.

    This will validate the if user is logged in also you will get to access logged in user's information by user=request.user.

提交回复
热议问题