diff --git a/api-guide/authentication/index.html b/api-guide/authentication/index.html index 760e9ec35..c5cc62dd3 100644 --- a/api-guide/authentication/index.html +++ b/api-guide/authentication/index.html @@ -467,6 +467,10 @@ +
  • + django-rest-knox +
  • +
  • Django OAuth Toolkit
  • @@ -496,11 +500,7 @@
  • - django-rest-framework-social-oauth2 -
  • - -
  • - django-rest-knox + drf-social-oauth2
  • @@ -621,6 +621,10 @@ WSGIPassAuthorization On

    Note: If you use BasicAuthentication in production you must ensure that your API is only available over https. You should also ensure that your API clients will always re-request the username and password at login, and will never store those details to persistent storage.

    TokenAuthentication

    +
    +

    Note: The token authentication provided by Django REST framework is a fairly simple implementation.

    +

    For an implementation which allows more than one token per user, has some tighter security implementation details, and supports token expiry, please see the Django REST Knox third party package.

    +

    This authentication scheme uses a simple token-based HTTP Authentication scheme. Token authentication is appropriate for client-server setups, such as native desktop and mobile clients.

    To use the TokenAuthentication scheme you'll need to configure the authentication classes to include TokenAuthentication, and additionally include rest_framework.authtoken in your INSTALLED_APPS setting:

    INSTALLED_APPS = [
    @@ -628,9 +632,8 @@ WSGIPassAuthorization On
         'rest_framework.authtoken'
     ]
     
    -
    -

    Note: Make sure to run manage.py migrate after changing your settings. The rest_framework.authtoken app provides Django database migrations.

    -
    +

    Make sure to run manage.py migrate after changing your settings.

    +

    The rest_framework.authtoken app provides Django database migrations.

    You'll also need to create tokens for your users.

    from rest_framework.authtoken.models import Token
     
    @@ -640,7 +643,7 @@ print(token.key)
     

    For clients to authenticate, the token key should be included in the Authorization HTTP header. The key should be prefixed by the string literal "Token", with whitespace separating the two strings. For example:

    Authorization: Token 9944b09199c62bcf9418ad846dd0e4bbdfc6ee4b
     
    -

    Note: If you want to use a different keyword in the header, such as Bearer, simply subclass TokenAuthentication and set the keyword class variable.

    +

    If you want to use a different keyword in the header, such as Bearer, simply subclass TokenAuthentication and set the keyword class variable.

    If successfully authenticated, TokenAuthentication provides the following credentials.

    • request.user will be a Django User instance.
    • @@ -795,6 +798,8 @@ class ExampleAuthentication(authentication.BaseAuthentication):

      Third party packages

      The following third-party packages are also available.

      +

      django-rest-knox

      +

      Django-rest-knox library provides models and views to handle token-based authentication in a more secure and extensible way than the built-in TokenAuthentication scheme - with Single Page Applications and Mobile clients in mind. It provides per-client tokens, and views to generate them when provided some other authentication (usually basic authentication), to delete the token (providing a server enforced logout) and to delete all tokens (logs out all clients that a user is logged into).

      Django OAuth Toolkit

      The Django OAuth Toolkit package provides OAuth 2.0 support and works with Python 3.4+. The package is maintained by jazzband and uses the excellent OAuthLib. The package is well documented, and well supported and is currently our recommended package for OAuth 2.0 support.

      Installation & configuration

      @@ -837,10 +842,8 @@ REST_FRAMEWORK = {
    • Django-rest-auth is the original project, but is not currently receiving updates.
    • Dj-rest-auth is a newer fork of the project.
    -

    django-rest-framework-social-oauth2

    -

    Django-rest-framework-social-oauth2 library provides an easy way to integrate social plugins (facebook, twitter, google, etc.) to your authentication system and an easy oauth2 setup. With this library, you will be able to authenticate users based on external tokens (e.g. facebook access token), convert these tokens to "in-house" oauth2 tokens and use and generate oauth2 tokens to authenticate your users.

    -

    django-rest-knox

    -

    Django-rest-knox library provides models and views to handle token-based authentication in a more secure and extensible way than the built-in TokenAuthentication scheme - with Single Page Applications and Mobile clients in mind. It provides per-client tokens, and views to generate them when provided some other authentication (usually basic authentication), to delete the token (providing a server enforced logout) and to delete all tokens (logs out all clients that a user is logged into).

    +

    drf-social-oauth2

    +

    Drf-social-oauth2 is a framework that helps you authenticate with major social oauth2 vendors, such as Facebook, Google, Twitter, Orcid, etc. It generates tokens in a JWTed way with an easy setup.

    drfpasswordless

    drfpasswordless adds (Medium, Square Cash inspired) passwordless support to Django REST Framework's TokenAuthentication scheme. Users log in and sign up with a token sent to a contact point like an email address or a mobile number.

    django-rest-authemail

    diff --git a/api-guide/fields/index.html b/api-guide/fields/index.html index c886d2b42..1de323753 100644 --- a/api-guide/fields/index.html +++ b/api-guide/fields/index.html @@ -664,7 +664,7 @@

    Normally an error will be raised if a field is not supplied during deserialization. Set to false if this field is not required to be present during deserialization.

    Setting this to False also allows the object attribute or dictionary key to be omitted from output when serializing the instance. If the key is not present it will simply not be included in the output representation.

    -

    Defaults to True.

    +

    Defaults to True. If you're using Model Serializer default value will be False if you have specified blank=True or default or null=True at your field in your Model.

    default

    If set, this gives the default value that will be used for the field if no input value is supplied. If not set the default behaviour is to not populate the attribute at all.

    The default is not applied during partial update operations. In the partial update case only fields that are provided in the incoming data will have a validated value returned.

    diff --git a/api-guide/relations/index.html b/api-guide/relations/index.html index 3e4c2176e..c6cfe73f6 100644 --- a/api-guide/relations/index.html +++ b/api-guide/relations/index.html @@ -552,7 +552,7 @@

    Note: The relational fields are declared in relations.py, but by convention you should import them from the serializers module, using from rest_framework import serializers and refer to fields as serializers.<FieldName>.



    -

    Note: REST Framework does not attempt to automatically optimize querysets passed to serializers in terms of select_related and prefetch_related since it would be too much magic. A serializer with a field spanning an orm relation through its source attribute could require an additional database hit to fetch related object from the database. It is the programmer's responsibility to optimize queries to avoid additional database hits which could occur while using such a serializer.

    +

    Note: REST Framework does not attempt to automatically optimize querysets passed to serializers in terms of select_related and prefetch_related since it would be too much magic. A serializer with a field spanning an orm relation through its source attribute could require an additional database hit to fetch related objects from the database. It is the programmer's responsibility to optimize queries to avoid additional database hits which could occur while using such a serializer.

    For example, the following serializer would lead to a database hit each time evaluating the tracks field if it is not prefetched:

    class AlbumSerializer(serializers.ModelSerializer):
         tracks = serializers.SlugRelatedField(
    diff --git a/api-guide/testing/index.html b/api-guide/testing/index.html
    index f926d8a86..a7d97f957 100644
    --- a/api-guide/testing/index.html
    +++ b/api-guide/testing/index.html
    @@ -614,7 +614,7 @@ request = factory.get('/accounts/django-superstars/')
     force_authenticate(request, user=user, token=user.auth_token)
     

    -

    Note: force_authenticate directly sets request.user to the in-memory user instance. If you are re-using the same user instance across multiple tests that update the saved user state, you may need to call refresh_from_db() between tests.

    +

    Note: force_authenticate directly sets request.user to the in-memory user instance. If you are re-using the same user instance across multiple tests that update the saved user state, you may need to call refresh_from_db() between tests.


    Note: When using APIRequestFactory, the object that is returned is Django's standard HttpRequest, and not REST framework's Request object, which is only generated once the view is called.

    This means that setting attributes directly on the request object may not always have the effect you expect. For example, setting .token directly will have no effect, and setting .user directly will only work if session authentication is being used.

    @@ -770,7 +770,7 @@ client.session.headers.update({'x-test': 'true'})

    API Test cases

    -

    REST framework includes the following test case classes, that mirror the existing Django test case classes, but use APIClient instead of Django's default Client.

    +

    REST framework includes the following test case classes, that mirror the existing Django's test case classes, but use APIClient instead of Django's default Client.