How to extend the Django Oauth Toolkit?

I am relatively new to Django and am currently using the Django Oauth Toolkit for implicit Oauth. It processes tokens and redirects users to the correct URL without any problems. I didn’t even need to touch my login page code, except that you passed the redirect correctly.

My urls.py, of course, has:

url(r'^oauth2/', include('oauth2_provider.urls', namespace='oauth2_provider')),

Until now, I did not need to do anything custom, because it works fine out of the box. However, now I need to save additional information about OAuth AccessTokens, for example, the OS from which the token came from. I created this model for this:

class AccessTokenDetail(models.Model):
    access_token = models.OneToOneField(AccessToken, primary_key=True)
    os_name = models.CharField(max_length=100)

So, my plan is: after the library creates the token, it will write the parameter in the request and create the object AccessTokenDetail. I see that I could use mixins , but since I don’t touch the third-party library at all, I'm a little confused about which class to include them.

How to add this functionality?

+4
source share

Source: https://habr.com/ru/post/1608508/


All Articles