aboutsummaryrefslogtreecommitdiffstats
path: root/docs/api-guide/authentication.md
diff options
context:
space:
mode:
authorTom Christie2012-11-19 13:30:49 -0800
committerTom Christie2012-11-19 13:30:49 -0800
commitb9e5c9484ae34b6675ea940854d58e2561bcc7f9 (patch)
tree8de7b921b7bc8b7cf9275cf07c8f26c3bf276d14 /docs/api-guide/authentication.md
parent25f024575bc36ea6ed386160a31b70abb5ac3e6e (diff)
parentf5f1ac49ec9d9cb180a00c791f2701c3f5a2d65b (diff)
downloaddjango-rest-framework-b9e5c9484ae34b6675ea940854d58e2561bcc7f9.tar.bz2
Merge pull request #399 from robromano/master
Added login view for users of TokenAuthentication
Diffstat (limited to 'docs/api-guide/authentication.md')
-rw-r--r--docs/api-guide/authentication.md12
1 files changed, 12 insertions, 0 deletions
diff --git a/docs/api-guide/authentication.md b/docs/api-guide/authentication.md
index cb1e2645..a30bd22c 100644
--- a/docs/api-guide/authentication.md
+++ b/docs/api-guide/authentication.md
@@ -112,6 +112,18 @@ If you've already created some User`'s, you can run a script like this.
for user in User.objects.all():
Token.objects.get_or_create(user=user)
+When using TokenAuthentication, it may be useful to add a login view for clients to retrieve the token.
+
+REST framework provides a built-in login view for clients to retrieve the token called `rest_framework.authtoken.obtain_auth_token`. To use it, add a pattern to include the token login view for clients as follows:
+
+ urlpatterns += patterns('',
+ url(r'^api-token-auth/', 'rest_framework.authtoken.obtain_auth_token')
+ )
+
+The `r'^api-token-auth/'` part of pattern can actually be whatever URL you want to use. The authtoken login view will render a JSON response when a valid `username` and `password` fields are POST'ed to the view using forms or JSON:
+
+ { 'token' : '9944b09199c62bcf9418ad846dd0e4bbdfc6ee4b' }
+
## 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.