Now that we have our update own profile permissions class we can go ahead and
configure our view set to use this permission open up the views dot py file
and at the top of the file we're going to add some imports and the first import
is we're going to import the token authentication from the rest framework
so type from rest framework dot authentication import token
authentication the token authentication is going to be the type of
authentication we use for users to authenticate themselves with our API it
works by generating a random token string when the user logs in and then
every request we make to their API that we need to authenticate we add this
token string to the request and that's effectively a password to check that
every request made is authenticated correctly we're going to configure this
on our view set and then I'll show you it in action in future videos when we
test it in the browser the next input we're going to add is the permissions
module that we created in the previous videos so from profiles underscore API
import permissions
Okay now we have the imports added let's head down to our
user profile view set and configure this to use the correct authentication and
permissions classes so we're going to add authentication underscore classes
equals token authentication and remember to add a comma after token
authentication so that this gets created as a tuple instead of just a single item
okay the token authentication as I mentioned is the type of authentication
we're going to be using you can configure one or more types of
authentication with a particular view set in the Django rest framework the way
it works is you just add all the authentication classes to this
authentication classes class variable
next we're going to add the permission
classes so the authentication class is set how the user will authenticate that
is the mechanism they will use and the permission classes is set how the user
gets permission to do certain things so you may have an authenticated user who
has permission to do certain things or use certain api's but not other
api's and you would control those fine-grained permissions by using
permission classes so let's create a new class variable here called permission
underscore classes equals and then we'll pass in permissions dot update own
profile and this will configure our user profile view set to use the token
authentication and then add the permission update own profile so every
request that gets made it gets passed through our permissions dot py file
and it checks this has object permissions function to see whether the
user has permissions to perform the action they're trying to perform ok so
make sure you save the views dot py file and that's how you configure a view set
to use authentication and permissions in the Django rest framework