angularjs - Django Token based authentication using PyJWT , issue with verification of token -
i implementing token based authentication in python django , therefore following token based authentication steps, described here:
in token-based authentication, cookies , sessions not used. token used authenticating user each request server. let's redesign first scenario token-based authentication.
it use following flow of control:
- the user provides username , password in login form , clickslog in.
- after request made, validate user on backend querying in database. if request valid, create token using user information fetched database, , return information in response header can store token browser in local storage.
- provide token information in every request header accessing restricted endpoints in application.
- if token fetched request header information valid, let user access specified end point, , respond json or xml.
i done first 2 steps listed above. need proceed step 3 , step 4. therefore, writing django decorator task us.
however, after authentication step little bit stuck.
here angularjs code send teacher_id
, token
server:
get_teacher_profile : function(teacher_id,token) { $http.defaults.headers.common['authorization'] = 'token ' + token; return $http.get("http://127.0.0.1:8000/user_manager/teacher/" + teacher_id + '/' + token) .then(function(response) { if (typeof response.data === 'object') { return response.data; } else { return "error"; } }, function(error) { return null; }); },
as per django rest framework here router specified @ urls.py:
router.register(r'teacher', view.teacherviewset)
...and here teacherviewset
class:
class teacherviewset(viewsets.modelviewset): queryset = teacher.objects.all() serializer_class = teacher_serializer
now need verify token in teacherviewset
. have tried decorators i've not been able access token set in header in teacherviewset
. using pyjwt token based authentication. if has encountered before please let me know.
please check out:
http://getblimp.github.io/django-rest-framework-jwt/#rest-framework-jwt-auth
this take care of jwt support when dealing django-rest-framework.
Comments
Post a Comment