Wednesday, November 1, 2017

Re: write custom decorators in django to authenticate the user



On Thursday, 2 November 2017 09:53:33 UTC+5:30, rohit.a...@gmail.com wrote:
def authenticated(f):
def wrap(request, *args, **kwargs):
token = request.META.get('HTTP_AUTHORIZATION')
entry = Person.objects.get(pk=kwargs['entry_id'])
payload = jwt.decode(token, SECRET)
user = Person.objects.get(
username=payload.get('username'),
pk=payload.get('id'))

wrap.__doc__=f.__doc__
wrap.__name__=f.__name__
return wrap

But the request object that I get is class object of the view and not the regular request object

e.g if I do print (request) output is

<login.views.Test object at 0x7ff106d82a50>

where am I going wrong.


I am using jwt tokens 

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscribe@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/b414181e-cbb4-453e-82cd-3d9e5968f91e%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

No comments:

Post a Comment