aboutsummaryrefslogtreecommitdiffstats
path: root/docs/api-guide/authentication.md
diff options
context:
space:
mode:
authorStephan Groß2012-11-14 18:00:59 +0100
committerStephan Groß2012-11-14 18:00:59 +0100
commit1e83b60a43c26db921d6910092362feb3a76500d (patch)
tree243e2240df39d35f7200a2874ccac479d1b9bd25 /docs/api-guide/authentication.md
parent44e9749e36d31f811db7dc0998c7b8d1e35a784d (diff)
downloaddjango-rest-framework-1e83b60a43c26db921d6910092362feb3a76500d.tar.bz2
added description how to use the auth token
Diffstat (limited to 'docs/api-guide/authentication.md')
-rw-r--r--docs/api-guide/authentication.md15
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.