Commit 75bce4e1 authored by Michael Fladischer's avatar Michael Fladischer

Imported Upstream version 0.4.0

parent 4b0bc7c6
Metadata-Version: 1.1
Name: djoser
Version: 0.3.2
Version: 0.4.0
Summary: REST version of Django authentication system.
Home-page: https://github.com/sunscrapers/djoser
Author: SUNSCRAPERS
......@@ -23,18 +23,20 @@ Description: djoser
App <http://en.wikipedia.org/wiki/Single-page_application>`__
architecture.
We use **token based authentication**. The concept is simple - first of
all, users obtain a token by providing their credentials (e.g. username,
password) during logging in. Once the token is obtained users can offer
it in order to retrieve a specific resource. Django REST framework
supports `token based
authentication <http://www.django-rest-framework.org/api-guide/authentication#tokenauthentication>`__
but you might be interested in other authentication mechanisms like
OAuth or session-based authentication.
Developed by `SUNSCRAPERS <http://sunscrapers.com/>`__ with passion &
patience.
Features
--------
Here is a list of supported authentication backends:
- `HTTP Basic
Auth <http://www.django-rest-framework.org/api-guide/authentication/#basicauthentication>`__
(Default)
- `Token based authentication from Django Rest
Framework <http://www.django-rest-framework.org/api-guide/authentication#tokenauthentication>`__
Available endpoints:
- ``/me/``
......@@ -62,9 +64,11 @@ Description: djoser
Supported Django Rest Framework versions:
- Django Rest Framework 2.4
- Django Rest Framework 3.x
For Django Rest Framework 2.4 support check `djoser
0.3.2 <https://github.com/sunscrapers/djoser/tree/0.3.2>`__.
Installation
------------
......@@ -74,8 +78,8 @@ Description: djoser
$ pip install djoser
Usage
-----
Quick Start
-----------
Configure ``INSTALLED_APPS``:
......@@ -85,7 +89,6 @@ Description: djoser
'django.contrib.auth',
(...),
'rest_framework',
'rest_framework.authtoken',
'djoser',
(...),
)
......@@ -99,7 +102,54 @@ Description: djoser
url(r'^auth/', include('djoser.urls')),
)
Use ``TokenAuthentication`` as default Django Rest Framework
HTTP Basic Auth strategy is assumed by default as Django Rest Framework
does it. However you may want to set it explicitly:
.. code:: python
REST_FRAMEWORK = {
'DEFAULT_AUTHENTICATION_CLASSES': (
'rest_framework.authentication.BasicAuthentication',
),
}
Run migrations (if you are using Django 1.7+ or South) - this step will
create tables for ``auth`` app:
::
$ ./manage.py migrate
Customizing authentication backend
----------------------------------
Token Based Authentication
~~~~~~~~~~~~~~~~~~~~~~~~~~
Add ``'rest_framework.authtoken'`` to ``INSTALLED_APPS``:
.. code:: python
INSTALLED_APPS = (
'django.contrib.auth',
(...),
'rest_framework',
'rest_framework.authtoken',
'djoser',
(...),
)
Configure ``urls.py``. Pay attention to ``djoser.url.authtoken`` module
path.
.. code:: python
urlpatterns = patterns('',
(...),
url(r'^auth/', include('djoser.urls.authtoken')),
)
Set ``TokenAuthentication`` as default Django Rest Framework
authentication strategy:
.. code:: python
......@@ -117,6 +167,9 @@ Description: djoser
$ ./manage.py migrate
Settings
--------
Optionally add ``DJOSER`` settings:
.. code:: python
......@@ -126,7 +179,6 @@ Description: djoser
'SITE_NAME': 'Frontend',
'PASSWORD_RESET_CONFIRM_URL': '#/password/reset/confirm/{uid}/{token}',
'ACTIVATION_URL': '#/activate/{uid}/{token}',
'LOGIN_AFTER_ACTIVATION': True,
'SEND_ACTIVATION_EMAIL': True,
}
......@@ -196,9 +248,6 @@ Description: djoser
`REQUIRED\_FIELDS <https://docs.djangoproject.com/en/dev/topics/auth/customizing/#django.contrib.auth.models.CustomUser.REQUIRED_FIELDS>`__
fields.
If ``LOGIN_AFTER_REGISTRATION`` is ``True``, you will receive
authentication token within response.
``POST``
^^^^^^^^
......@@ -226,8 +275,6 @@ Description: djoser
``{{ User.REQUIRED_FIELDS }}``
``auth_token`` (if ``LOGIN_AFTER_REGISTRATION`` is ``True``)
Login
~~~~~
......@@ -272,9 +319,9 @@ Description: djoser
Activate
~~~~~~~~
Use this endpoint to activate user account. This enpoint is not a URL
Use this endpoint to activate user account. This endpoint is not a URL
which will be directly exposed to your users - you should provide site
in your frontend application (cofigured by ``ACTIVATION_URL``) which
in your frontend application (configured by ``ACTIVATION_URL``) which
will send ``POST`` request to activate endpoint.
``POST``
......@@ -294,10 +341,6 @@ Description: djoser
- status: ``HTTP_200_OK`` (success)
- data:
``auth_token`` (if ``LOGIN_AFTER_ACTIVATION`` is ``True``)
Set username
~~~~~~~~~~~~
......@@ -371,10 +414,10 @@ Description: djoser
Reset password confirmation
~~~~~~~~~~~~~~~~~~~~~~~~~~~
Use this endpoint to finish reset password process. This enpoint is not
Use this endpoint to finish reset password process. This endpoint is not
a URL which will be directly exposed to your users - you should provide
site in your frontend application (cofigured by
``PASSWORD_RESET_CONFIRM_URL_URL``) which will send ``POST`` request to
site in your frontend application (configured by
``PASSWORD_RESET_CONFIRM_URL``) which will send ``POST`` request to
reset password confirmation endpoint.
``POST``
......@@ -402,14 +445,6 @@ Description: djoser
Settings
--------
LOGIN\_AFTER\_REGISTRATION
~~~~~~~~~~~~~~~~~~~~~~~~~~
If ``True``, register endpoint will return ``auth_token`` within
response.
**Default**: ``False``
DOMAIN
~~~~~~
......@@ -452,14 +487,6 @@ Description: djoser
**Required**: ``True``
LOGIN\_AFTER\_ACTIVATION
~~~~~~~~~~~~~~~~~~~~~~~~
If ``True``, activate endpoint will return ``auth_token`` within
response.
**Default**: ``False``
SET\_USERNAME\_RETYPE
~~~~~~~~~~~~~~~~~~~~~
......
......@@ -12,14 +12,15 @@ Instead of reusing Django code (e.g. `PasswordResetForm`), we reimplemented
few things to fit better into [Single Page App](http://en.wikipedia.org/wiki/Single-page_application)
architecture.
We use **token based authentication**. The concept is simple - first of all, users obtain a token by
providing their credentials (e.g. username, password) during logging in. Once the token is obtained
users can offer it in order to retrieve a specific resource. Django REST framework
supports [token based authentication](http://www.django-rest-framework.org/api-guide/authentication#tokenauthentication)
but you might be interested in other authentication mechanisms like OAuth or session-based authentication.
Developed by [SUNSCRAPERS](http://sunscrapers.com/) with passion & patience.
## Features
Here is a list of supported authentication backends:
* [HTTP Basic Auth](http://www.django-rest-framework.org/api-guide/authentication/#basicauthentication) (Default)
* [Token based authentication from Django Rest Framework](http://www.django-rest-framework.org/api-guide/authentication#tokenauthentication)
Available endpoints:
* `/me/`
......@@ -47,8 +48,9 @@ Supported Django versions:
Supported Django Rest Framework versions:
* Django Rest Framework 2.4
* Django Rest Framework 3.x
For Django Rest Framework 2.4 support check [djoser 0.3.2](https://github.com/sunscrapers/djoser/tree/0.3.2).
## Installation
......@@ -56,7 +58,7 @@ Use `pip`:
$ pip install djoser
## Usage
## Quick Start
Configure `INSTALLED_APPS`:
......@@ -65,7 +67,6 @@ INSTALLED_APPS = (
'django.contrib.auth',
(...),
'rest_framework',
'rest_framework.authtoken',
'djoser',
(...),
)
......@@ -80,8 +81,48 @@ urlpatterns = patterns('',
)
```
Use `TokenAuthentication` as default Django Rest Framework authentication
strategy:
HTTP Basic Auth strategy is assumed by default as Django Rest Framework does it. However you may want to set it
explicitly:
```python
REST_FRAMEWORK = {
'DEFAULT_AUTHENTICATION_CLASSES': (
'rest_framework.authentication.BasicAuthentication',
),
}
```
Run migrations (if you are using Django 1.7+ or South) - this step will create tables for `auth` app:
$ ./manage.py migrate
## Customizing authentication backend
### Token Based Authentication
Add `'rest_framework.authtoken'` to `INSTALLED_APPS`:
```python
INSTALLED_APPS = (
'django.contrib.auth',
(...),
'rest_framework',
'rest_framework.authtoken',
'djoser',
(...),
)
```
Configure `urls.py`. Pay attention to `djoser.url.authtoken` module path.
```python
urlpatterns = patterns('',
(...),
url(r'^auth/', include('djoser.urls.authtoken')),
)
```
Set `TokenAuthentication` as default Django Rest Framework authentication strategy:
```python
REST_FRAMEWORK = {
......@@ -95,6 +136,8 @@ Run migrations (if you are using Django 1.7+ or South) - this step will create t
$ ./manage.py migrate
## Settings
Optionally add `DJOSER` settings:
```python
......@@ -103,7 +146,6 @@ DJOSER = {
'SITE_NAME': 'Frontend',
'PASSWORD_RESET_CONFIRM_URL': '#/password/reset/confirm/{uid}/{token}',
'ACTIVATION_URL': '#/activate/{uid}/{token}',
'LOGIN_AFTER_ACTIVATION': True,
'SEND_ACTIVATION_EMAIL': True,
}
```
......@@ -166,9 +208,6 @@ method and have [USERNAME_FIELD](https://docs.djangoproject.com/en/dev/topics/au
and [REQUIRED_FIELDS](https://docs.djangoproject.com/en/dev/topics/auth/customizing/#django.contrib.auth.models.CustomUser.REQUIRED_FIELDS)
fields.
If `LOGIN_AFTER_REGISTRATION` is `True`, you will receive authentication token
within response.
#### `POST`
URL: `/register/`
......@@ -195,8 +234,6 @@ URL: `/register/`
`{{ User.REQUIRED_FIELDS }}`
`auth_token` (if `LOGIN_AFTER_REGISTRATION` is `True`)
### Login
Use this endpoint to obtain user [authentication token](http://www.django-rest-framework.org/api-guide/authentication#tokenauthentication).
......@@ -235,9 +272,9 @@ URL: `/logout/`
### Activate
Use this endpoint to activate user account. This enpoint is not a URL which
Use this endpoint to activate user account. This endpoint is not a URL which
will be directly exposed to your users - you should provide site in your
frontend application (cofigured by `ACTIVATION_URL`) which will send `POST`
frontend application (configured by `ACTIVATION_URL`) which will send `POST`
request to activate endpoint.
#### `POST`
......@@ -256,10 +293,6 @@ URL: `/activate/`
* status: `HTTP_200_OK` (success)
* data:
`auth_token` (if `LOGIN_AFTER_ACTIVATION` is `True`)
### Set username
Use this endpoint to change user username (`USERNAME_FIELD`).
......@@ -325,9 +358,9 @@ URL: `/password/reset/`
### Reset password confirmation
Use this endpoint to finish reset password process. This enpoint is not a URL
Use this endpoint to finish reset password process. This endpoint is not a URL
which will be directly exposed to your users - you should provide site in your
frontend application (cofigured by `PASSWORD_RESET_CONFIRM_URL_URL`) which
frontend application (configured by `PASSWORD_RESET_CONFIRM_URL`) which
will send `POST` request to reset password confirmation endpoint.
#### `POST`
......@@ -352,12 +385,6 @@ URL: `/password/reset/confirm/`
## Settings
### LOGIN_AFTER_REGISTRATION
If `True`, register endpoint will return `auth_token` within response.
**Default**: `False`
### DOMAIN
Domain of your frontend app. If not provided, domain of current site will be
......@@ -394,12 +421,6 @@ placeholders, e.g. `#/activate/{uid}/{token}`. You should pass `uid` and
**Required**: `True`
### LOGIN_AFTER_ACTIVATION
If `True`, activate endpoint will return `auth_token` within response.
**Default**: `False`
### SET_USERNAME_RETYPE
If `True`, you need to pass `re_new_{{ User.USERNAME_FIELD }}` to
......
Metadata-Version: 1.1
Name: djoser
Version: 0.3.2
Version: 0.4.0
Summary: REST version of Django authentication system.
Home-page: https://github.com/sunscrapers/djoser
Author: SUNSCRAPERS
......@@ -23,18 +23,20 @@ Description: djoser
App <http://en.wikipedia.org/wiki/Single-page_application>`__
architecture.
We use **token based authentication**. The concept is simple - first of
all, users obtain a token by providing their credentials (e.g. username,
password) during logging in. Once the token is obtained users can offer
it in order to retrieve a specific resource. Django REST framework
supports `token based
authentication <http://www.django-rest-framework.org/api-guide/authentication#tokenauthentication>`__
but you might be interested in other authentication mechanisms like
OAuth or session-based authentication.
Developed by `SUNSCRAPERS <http://sunscrapers.com/>`__ with passion &
patience.
Features
--------
Here is a list of supported authentication backends:
- `HTTP Basic
Auth <http://www.django-rest-framework.org/api-guide/authentication/#basicauthentication>`__
(Default)
- `Token based authentication from Django Rest
Framework <http://www.django-rest-framework.org/api-guide/authentication#tokenauthentication>`__
Available endpoints:
- ``/me/``
......@@ -62,9 +64,11 @@ Description: djoser
Supported Django Rest Framework versions:
- Django Rest Framework 2.4
- Django Rest Framework 3.x
For Django Rest Framework 2.4 support check `djoser
0.3.2 <https://github.com/sunscrapers/djoser/tree/0.3.2>`__.
Installation
------------
......@@ -74,8 +78,8 @@ Description: djoser
$ pip install djoser
Usage
-----
Quick Start
-----------
Configure ``INSTALLED_APPS``:
......@@ -85,7 +89,6 @@ Description: djoser
'django.contrib.auth',
(...),
'rest_framework',
'rest_framework.authtoken',
'djoser',
(...),
)
......@@ -99,7 +102,54 @@ Description: djoser
url(r'^auth/', include('djoser.urls')),
)
Use ``TokenAuthentication`` as default Django Rest Framework
HTTP Basic Auth strategy is assumed by default as Django Rest Framework
does it. However you may want to set it explicitly:
.. code:: python
REST_FRAMEWORK = {
'DEFAULT_AUTHENTICATION_CLASSES': (
'rest_framework.authentication.BasicAuthentication',
),
}
Run migrations (if you are using Django 1.7+ or South) - this step will
create tables for ``auth`` app:
::
$ ./manage.py migrate
Customizing authentication backend
----------------------------------
Token Based Authentication
~~~~~~~~~~~~~~~~~~~~~~~~~~
Add ``'rest_framework.authtoken'`` to ``INSTALLED_APPS``:
.. code:: python
INSTALLED_APPS = (
'django.contrib.auth',
(...),
'rest_framework',
'rest_framework.authtoken',
'djoser',
(...),
)
Configure ``urls.py``. Pay attention to ``djoser.url.authtoken`` module
path.
.. code:: python
urlpatterns = patterns('',
(...),
url(r'^auth/', include('djoser.urls.authtoken')),
)
Set ``TokenAuthentication`` as default Django Rest Framework
authentication strategy:
.. code:: python
......@@ -117,6 +167,9 @@ Description: djoser
$ ./manage.py migrate
Settings
--------
Optionally add ``DJOSER`` settings:
.. code:: python
......@@ -126,7 +179,6 @@ Description: djoser
'SITE_NAME': 'Frontend',
'PASSWORD_RESET_CONFIRM_URL': '#/password/reset/confirm/{uid}/{token}',
'ACTIVATION_URL': '#/activate/{uid}/{token}',
'LOGIN_AFTER_ACTIVATION': True,
'SEND_ACTIVATION_EMAIL': True,
}
......@@ -196,9 +248,6 @@ Description: djoser
`REQUIRED\_FIELDS <https://docs.djangoproject.com/en/dev/topics/auth/customizing/#django.contrib.auth.models.CustomUser.REQUIRED_FIELDS>`__
fields.
If ``LOGIN_AFTER_REGISTRATION`` is ``True``, you will receive
authentication token within response.
``POST``
^^^^^^^^
......@@ -226,8 +275,6 @@ Description: djoser
``{{ User.REQUIRED_FIELDS }}``
``auth_token`` (if ``LOGIN_AFTER_REGISTRATION`` is ``True``)
Login
~~~~~
......@@ -272,9 +319,9 @@ Description: djoser
Activate
~~~~~~~~
Use this endpoint to activate user account. This enpoint is not a URL
Use this endpoint to activate user account. This endpoint is not a URL
which will be directly exposed to your users - you should provide site
in your frontend application (cofigured by ``ACTIVATION_URL``) which
in your frontend application (configured by ``ACTIVATION_URL``) which
will send ``POST`` request to activate endpoint.
``POST``
......@@ -294,10 +341,6 @@ Description: djoser
- status: ``HTTP_200_OK`` (success)
- data:
``auth_token`` (if ``LOGIN_AFTER_ACTIVATION`` is ``True``)
Set username
~~~~~~~~~~~~
......@@ -371,10 +414,10 @@ Description: djoser
Reset password confirmation
~~~~~~~~~~~~~~~~~~~~~~~~~~~
Use this endpoint to finish reset password process. This enpoint is not
Use this endpoint to finish reset password process. This endpoint is not
a URL which will be directly exposed to your users - you should provide
site in your frontend application (cofigured by
``PASSWORD_RESET_CONFIRM_URL_URL``) which will send ``POST`` request to
site in your frontend application (configured by
``PASSWORD_RESET_CONFIRM_URL``) which will send ``POST`` request to
reset password confirmation endpoint.
``POST``
......@@ -402,14 +445,6 @@ Description: djoser
Settings
--------
LOGIN\_AFTER\_REGISTRATION
~~~~~~~~~~~~~~~~~~~~~~~~~~
If ``True``, register endpoint will return ``auth_token`` within
response.
**Default**: ``False``
DOMAIN
~~~~~~
......@@ -452,14 +487,6 @@ Description: djoser
**Required**: ``True``
LOGIN\_AFTER\_ACTIVATION
~~~~~~~~~~~~~~~~~~~~~~~~
If ``True``, activate endpoint will return ``auth_token`` within
response.
**Default**: ``False``
SET\_USERNAME\_RETYPE
~~~~~~~~~~~~~~~~~~~~~
......
......@@ -7,7 +7,6 @@ djoser/constants.py
djoser/serializers.py
djoser/settings.py
djoser/signals.py
djoser/urls.py
djoser/utils.py
djoser/views.py
djoser.egg-info/PKG-INFO
......@@ -18,4 +17,7 @@ djoser.egg-info/top_level.txt
djoser/templates/activation_email_body.txt
djoser/templates/activation_email_subject.txt
djoser/templates/password_reset_email_body.txt
djoser/templates/password_reset_email_subject.txt
\ No newline at end of file
djoser/templates/password_reset_email_subject.txt
djoser/urls/__init__.py
djoser/urls/authtoken.py
djoser/urls/base.py
\ No newline at end of file
Django>=1.5
djangorestframework>=2.4.0
djangorestframework>=3.0.0
from distutils import version
from django.contrib.auth import authenticate, get_user_model
from rest_framework import serializers
import rest_framework
from rest_framework.authtoken.models import Token
from . import constants, utils
User = get_user_model()
def create_username_field():
username_field = User._meta.get_field(User.USERNAME_FIELD)
if hasattr(serializers.ModelSerializer, 'field_mapping'): # DRF 2.x
mapping_dict = serializers.ModelSerializer.field_mapping
elif hasattr(serializers.ModelSerializer, '_field_mapping'): # DRF 3.0
mapping_dict = serializers.ModelSerializer._field_mapping.mapping
elif hasattr(serializers.ModelSerializer, 'serializer_field_mapping'): # DRF 3.1
mapping_dict = serializers.ModelSerializer.serializer_field_mapping
else:
raise AttributeError(
'serializers.ModelSerializer doesn\'t have any of these attributes: '
'field_mapping, _field_mapping, serializer_field_mapping '
)
field_class = mapping_dict[username_field.__class__]
return field_class()
class UserSerializer(serializers.ModelSerializer):
class Meta:
......@@ -38,7 +19,8 @@ class UserSerializer(serializers.ModelSerializer):
)
class AbstractUserRegistrationSerializer(serializers.ModelSerializer):
class UserRegistrationSerializer(serializers.ModelSerializer):
password = serializers.CharField(style={'input_type': 'password'}, write_only=True)
class Meta:
model = User
......@@ -47,46 +29,13 @@ class AbstractUserRegistrationSerializer(serializers.ModelSerializer):
User._meta.pk.name,
'password',
)
write_only_fields = (
'password',
)
if version.StrictVersion(rest_framework.VERSION) >= version.StrictVersion('3.0.0'):
class UserRegistrationSerializer(AbstractUserRegistrationSerializer):
def create(self, validated_data):
return User.objects.create_user(**validated_data)
else:
class UserRegistrationSerializer(AbstractUserRegistrationSerializer):
def restore_object(self, attrs, instance=None):
try:
return User.objects.get(**{User.USERNAME_FIELD: attrs[User.USERNAME_FIELD]})
except User.DoesNotExist:
return User.objects.create_user(**attrs)
def save_object(self, obj, **kwargs):
return obj
class UserRegistrationWithAuthTokenSerializer(UserRegistrationSerializer):
auth_token = serializers.SerializerMethodField(method_name='get_user_auth_token')
class Meta(UserRegistrationSerializer.Meta):
model = User
fields = UserRegistrationSerializer.Meta.fields + (
'auth_token',
)
def get_user_auth_token(self, obj):
return obj.auth_token.key
def create(self, validated_data):
return User.objects.create_user(**validated_data)
class LoginSerializer(serializers.Serializer):
password = serializers.CharField(required=False)
password = serializers.CharField(required=False, style={'input_type': 'password'})
default_error_messages = {
'inactive_account': constants.INACTIVE_ACCOUNT_ERROR,
......@@ -99,7 +48,7 @@ class LoginSerializer(serializers.Serializer):
self.fields[User.USERNAME_FIELD] = serializers.CharField(required=False)
def validate(self, attrs):
self.user = authenticate(username=attrs[User.USERNAME_FIELD], password=attrs['password'])
self.user = authenticate(username=attrs.get(User.USERNAME_FIELD), password=attrs.get('password'))
if self.user:
if not self.user.is_active:
raise serializers.ValidationError(self.error_messages['inactive_account'])
......@@ -120,14 +69,13 @@ class UidAndTokenSerializer(serializers.Serializer):
'invalid_token': constants.INVALID_TOKEN_ERROR
}