diff options
| author | Tom Christie | 2012-11-14 10:41:15 -0800 |
|---|---|---|
| committer | Tom Christie | 2012-11-14 10:41:15 -0800 |
| commit | a83eb748c1515f9b4c363c9c7de1782d9da4dfe9 (patch) | |
| tree | df7fd3f6473e212d7fd648659b2bed66fdc8d4df | |
| parent | 9e1f82c35ffdb1e056a464ae10e075a52865cc9b (diff) | |
| parent | 1e83b60a43c26db921d6910092362feb3a76500d (diff) | |
| download | django-rest-framework-a83eb748c1515f9b4c363c9c7de1782d9da4dfe9.tar.bz2 | |
Merge pull request #413 from minddust/auth_token_documentation
added description how to use the auth token
| -rw-r--r-- | docs/api-guide/authentication.md | 15 |
1 files changed, 15 insertions, 0 deletions
diff --git a/docs/api-guide/authentication.md b/docs/api-guide/authentication.md index 3137b9d4..cb1e2645 100644 --- a/docs/api-guide/authentication.md +++ b/docs/api-guide/authentication.md @@ -97,6 +97,21 @@ If successfully authenticated, `TokenAuthentication` provides the following cred **Note:** If you use `TokenAuthentication` in production you must ensure that your API is only available over `https` only. +If you want every user to have an automatically generated Token, you can simply catch the User's `post_save` signal. + + @receiver(post_save, sender=User) + def create_auth_token(sender, instance=None, created=False, **kwargs): + if created: + Token.objects.create(user=instance) + +If you've already created some User`'s, you can run a script like this. + + from django.contrib.auth.models import User + from rest_framework.authtoken.models import Token + + for user in User.objects.all(): + Token.objects.get_or_create(user=user) + ## OAuthAuthentication This policy uses the [OAuth 2.0][oauth] protocol to authenticate requests. OAuth is appropriate for server-server setups, such as when you want to allow a third-party service to access your API on a user's behalf. |
