Commit 61f42d7d authored by Andre Bianchi's avatar Andre Bianchi

New upstream version 2.1.0

parents
# Change Log
All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](http://keepachangelog.com/)
and this project adheres to [Semantic Versioning](http://semver.org/).
## [Unreleased](https://github.com/python-social-auth/social-app-django/commits/master)
## [2.1.0](https://github.com/python-social-auth/social-app-django/releases/tag/2.1.0) - 2017-12-22
### Changed
- Use Django `urlquote` since it handles unicode
- Remove version check in favor of import error catch
- Remove call to deprecated method `_get_val_from_obj()`
## [2.0.0](https://github.com/python-social-auth/social-app-django/releases/tag/2.0.0) - 2017-10-28
### Changed
- Better default when checking if the middleware should raise the exception
- Update `JSONField` default value to `dict` callable
- Updated `authenticate()` parameters cleanup to avoid double arguments errors
- Fix imports to bring Django 2.0 support
- Admin friendly label
- Old Django versions (1.8 and below) compatibility dropped
- Python 3.6 and Django 2.0 tests
- Management command to clean stale data (partial sessions and codes)
### Added
- Added `JSONField` support PostgreSQL builtin option if configured
- Added strategy / models / views tests
- Added timestamps to Partial and Code models
## [1.2.0](https://github.com/python-social-auth/social-app-django/releases/tag/1.2.0) - 2017-05-06
### Added
- Check for a `MAX_SESSION_LENGTH` setting when logging in and setting session expiry.
### Changed
- Addded `on_cascade` clauses to migrations.
- Restrict association URL to just integer ids
## [1.1.0](https://github.com/python-social-auth/social-app-django/releases/tag/1.1.0) - 2017-02-10
### Added
- Authenticate cleanup method override to discard request parameter
getting passed starting from Django 1.11
## [1.0.1](https://github.com/python-social-auth/social-app-django/releases/tag/1.0.1) - 2017-01-29
### Changed
- Remove migration replacement to nonexistent reference
- Ensure atomic transaction if active
## [1.0.0](https://github.com/python-social-auth/social-app-django/releases/tag/1.0.0) - 2017-01-22
### Added
- Partial pipeline DB storage implementation
- Explicit app_label definition in model classes
### Changed
- Monkey patch BaseAuth to load the current strategy to workaround django load_backend() call
- Remove usage of set/get current strategy methods
- Remove usage of `social_auth` related name since it should be consider a simple helper.
## [0.1.0](https://github.com/python-social-auth/social-app-django/releases/tag/0.1.0) - 2016-12-28
### Added
- Let Django resolve URL when getting from settings (port of [#905](https://github.com/omab/python-social-auth/pull/905)
by webjunkie)
- Add setting to fine-tune admin search fields (port of [#1035](https://github.com/omab/python-social-auth/pull/1035)
by atugushev)
### Changed
- Fixed `REDIRECT_URL_VALUE` value to be quoted by default.
Refs [#875](https://github.com/omab/python-social-auth/issues/875)
- Django strategy should respect X-Forwarded-Port (port of [#841](https://github.com/omab/python-social-auth/pull/841)
by omarkhan)
- Fixed use of old private API (port of [#822](https://github.com/omab/python-social-auth/pull/822)
by eranmarom)
- Add ON DELETE CASCADE for user fk (port of [#1015](https://github.com/omab/python-social-auth/pull/1015)
by artofhuman)
- Avoid usage of SubfieldBase on 1.8 and 1.9 versions (port of [#1008](https://github.com/omab/python-social-auth/pull/1008)
by tom-dalton-fanduel)
## [0.0.1](https://github.com/python-social-auth/social-app-django/releases/tag/0.0.1) - 2016-11-27
### Changed
- Split from the monolitic [python-social-auth](https://github.com/omab/python-social-auth)
codebase
Copyright (c) 2012-2016, Matías Aguirre
All rights reserved.
Redistribution and use in source and binary forms, with or without modification,
are permitted provided that the following conditions are met:
1. Redistributions of source code must retain the above copyright notice,
this list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution.
3. Neither the name of this project nor the names of its contributors may be
used to endorse or promote products derived from this software without
specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
global-include *.py
include *.txt CHANGELOG.md LICENSE README.md
recursive-exclude social_django *.pyc
Metadata-Version: 1.1
Name: social-auth-app-django
Version: 2.1.0
Summary: Python Social Authentication, Django integration.
Home-page: https://github.com/python-social-auth/social-app-django
Author: Matias Aguirre
Author-email: matiasaguirre@gmail.com
License: BSD
Description-Content-Type: UNKNOWN
Description: # Python Social Auth - Django
[![Build Status](https://travis-ci.org/python-social-auth/social-app-django.svg?branch=master)](https://travis-ci.org/python-social-auth/social-app-django)
[![Donate](https://img.shields.io/badge/Donate-PayPal-orange.svg)](https://www.paypal.com/cgi-bin/webscr?cmd=_donations&business=matiasaguirre%40gmail%2ecom&lc=US&item_name=Python%20Social%20Auth&no_note=0&currency_code=USD&bn=PP%2dDonationsBF%3abtn_donate_SM%2egif%3aNonHostedGuest)
Python Social Auth is an easy to setup social authentication/registration
mechanism with support for several frameworks and auth providers.
## Description
This is the [Django](https://www.djangoproject.com/) component of the
[python-social-auth ecosystem](https://github.com/python-social-auth/social-core),
it implements the needed functionality to integrate
[social-auth-core](https://github.com/python-social-auth/social-core)
in a Django based project.
## Django version
This project will focus on the currently supported Django releases as
stated on the [Django Project Supported Versions table](https://www.djangoproject.com/download/#supported-versions).
Backward compatibility with unsupported versions won't be enforced.
## Documentation
Project documentation is available at http://python-social-auth.readthedocs.org/.
## Setup
```shell
$ pip install social-auth-app-django
```
## Contributing
See the [CONTRIBUTING.md](CONTRIBUTING.md) document for details.
## Versioning
This project follows [Semantic Versioning 2.0.0](http://semver.org/spec/v2.0.0.html).
## License
This project follows the BSD license. See the [LICENSE](LICENSE) for details.
## Donations
This project is maintened on my spare time, consider donating to keep
it improving.
[![Donate](https://img.shields.io/badge/Donate-PayPal-orange.svg)](https://www.paypal.com/cgi-bin/webscr?cmd=_donations&business=matiasaguirre%40gmail%2ecom&lc=US&item_name=Python%20Social%20Auth&no_note=0&currency_code=USD&bn=PP%2dDonationsBF%3abtn_donate_SM%2egif%3aNonHostedGuest)
Keywords: django,social auth
Platform: UNKNOWN
Classifier: Development Status :: 4 - Beta
Classifier: Topic :: Internet
Classifier: License :: OSI Approved :: BSD License
Classifier: Intended Audience :: Developers
Classifier: Environment :: Web Environment
Classifier: Programming Language :: Python
Classifier: Programming Language :: Python :: 2.7
Classifier: Programming Language :: Python :: 3
# Python Social Auth - Django
[![Build Status](https://travis-ci.org/python-social-auth/social-app-django.svg?branch=master)](https://travis-ci.org/python-social-auth/social-app-django)
[![Donate](https://img.shields.io/badge/Donate-PayPal-orange.svg)](https://www.paypal.com/cgi-bin/webscr?cmd=_donations&business=matiasaguirre%40gmail%2ecom&lc=US&item_name=Python%20Social%20Auth&no_note=0&currency_code=USD&bn=PP%2dDonationsBF%3abtn_donate_SM%2egif%3aNonHostedGuest)
Python Social Auth is an easy to setup social authentication/registration
mechanism with support for several frameworks and auth providers.
## Description
This is the [Django](https://www.djangoproject.com/) component of the
[python-social-auth ecosystem](https://github.com/python-social-auth/social-core),
it implements the needed functionality to integrate
[social-auth-core](https://github.com/python-social-auth/social-core)
in a Django based project.
## Django version
This project will focus on the currently supported Django releases as
stated on the [Django Project Supported Versions table](https://www.djangoproject.com/download/#supported-versions).
Backward compatibility with unsupported versions won't be enforced.
## Documentation
Project documentation is available at http://python-social-auth.readthedocs.org/.
## Setup
```shell
$ pip install social-auth-app-django
```
## Contributing
See the [CONTRIBUTING.md](CONTRIBUTING.md) document for details.
## Versioning
This project follows [Semantic Versioning 2.0.0](http://semver.org/spec/v2.0.0.html).
## License
This project follows the BSD license. See the [LICENSE](LICENSE) for details.
## Donations
This project is maintened on my spare time, consider donating to keep
it improving.
[![Donate](https://img.shields.io/badge/Donate-PayPal-orange.svg)](https://www.paypal.com/cgi-bin/webscr?cmd=_donations&business=matiasaguirre%40gmail%2ecom&lc=US&item_name=Python%20Social%20Auth&no_note=0&currency_code=USD&bn=PP%2dDonationsBF%3abtn_donate_SM%2egif%3aNonHostedGuest)
mock==2.0.0
codecov==2.0.7
tox==2.7.0
-r requirements.txt
#!/usr/bin/env python
# -*- coding: utf-8 -*-
from __future__ import unicode_literals, absolute_import
import os
import sys
if __name__ == "__main__":
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "tests.settings")
from django.core.management import execute_from_command_line
execute_from_command_line(sys.argv)
[flake8]
max-line-length = 119
exclude = .venv,.tox,dist,doc,build,*.egg,db/env.py,db/versions/*.py,site
[nosetests]
verbosity = 2
with-coverage = 1
cover-erase = 1
cover-package = social
rednose = 1
[egg_info]
tag_build =
tag_date = 0
# -*- coding: utf-8 -*-
"""Setup file for easy installation"""
import re
from os.path import join, dirname
from setuptools import setup
VERSION_RE = re.compile('__version__ = \'([\d\.]+)\'')
def read_version():
with open('social_django/__init__.py') as file:
version_line = [line for line in file.readlines()
if line.startswith('__version__')][0]
return VERSION_RE.match(version_line).groups()[0]
def long_description():
return open(join(dirname(__file__), 'README.md')).read()
def load_requirements():
return open(join(dirname(__file__), 'requirements.txt')).readlines()
setup(
name='social-auth-app-django',
version=read_version(),
author='Matias Aguirre',
author_email='matiasaguirre@gmail.com',
description='Python Social Authentication, Django integration.',
license='BSD',
keywords='django, social auth',
url='https://github.com/python-social-auth/social-app-django',
packages=[
'social_django',
'social_django.migrations'
],
long_description=long_description(),
install_requires=load_requirements(),
classifiers=[
'Development Status :: 4 - Beta',
'Topic :: Internet',
'License :: OSI Approved :: BSD License',
'Intended Audience :: Developers',
'Environment :: Web Environment',
'Programming Language :: Python',
'Programming Language :: Python :: 2.7',
'Programming Language :: Python :: 3'
],
zip_safe=False
)
Metadata-Version: 1.1
Name: social-auth-app-django
Version: 2.1.0
Summary: Python Social Authentication, Django integration.
Home-page: https://github.com/python-social-auth/social-app-django
Author: Matias Aguirre
Author-email: matiasaguirre@gmail.com
License: BSD
Description-Content-Type: UNKNOWN
Description: # Python Social Auth - Django
[![Build Status](https://travis-ci.org/python-social-auth/social-app-django.svg?branch=master)](https://travis-ci.org/python-social-auth/social-app-django)
[![Donate](https://img.shields.io/badge/Donate-PayPal-orange.svg)](https://www.paypal.com/cgi-bin/webscr?cmd=_donations&business=matiasaguirre%40gmail%2ecom&lc=US&item_name=Python%20Social%20Auth&no_note=0&currency_code=USD&bn=PP%2dDonationsBF%3abtn_donate_SM%2egif%3aNonHostedGuest)
Python Social Auth is an easy to setup social authentication/registration
mechanism with support for several frameworks and auth providers.
## Description
This is the [Django](https://www.djangoproject.com/) component of the
[python-social-auth ecosystem](https://github.com/python-social-auth/social-core),
it implements the needed functionality to integrate
[social-auth-core](https://github.com/python-social-auth/social-core)
in a Django based project.
## Django version
This project will focus on the currently supported Django releases as
stated on the [Django Project Supported Versions table](https://www.djangoproject.com/download/#supported-versions).
Backward compatibility with unsupported versions won't be enforced.
## Documentation
Project documentation is available at http://python-social-auth.readthedocs.org/.
## Setup
```shell
$ pip install social-auth-app-django
```
## Contributing
See the [CONTRIBUTING.md](CONTRIBUTING.md) document for details.
## Versioning
This project follows [Semantic Versioning 2.0.0](http://semver.org/spec/v2.0.0.html).
## License
This project follows the BSD license. See the [LICENSE](LICENSE) for details.
## Donations
This project is maintened on my spare time, consider donating to keep
it improving.
[![Donate](https://img.shields.io/badge/Donate-PayPal-orange.svg)](https://www.paypal.com/cgi-bin/webscr?cmd=_donations&business=matiasaguirre%40gmail%2ecom&lc=US&item_name=Python%20Social%20Auth&no_note=0&currency_code=USD&bn=PP%2dDonationsBF%3abtn_donate_SM%2egif%3aNonHostedGuest)
Keywords: django,social auth
Platform: UNKNOWN
Classifier: Development Status :: 4 - Beta
Classifier: Topic :: Internet
Classifier: License :: OSI Approved :: BSD License
Classifier: Intended Audience :: Developers
Classifier: Environment :: Web Environment
Classifier: Programming Language :: Python
Classifier: Programming Language :: Python :: 2.7
Classifier: Programming Language :: Python :: 3
CHANGELOG.md
LICENSE
MANIFEST.in
README.md
dev-requirements.txt
manage.py
requirements.txt
setup.cfg
setup.py
social_auth_app_django.egg-info/PKG-INFO
social_auth_app_django.egg-info/SOURCES.txt
social_auth_app_django.egg-info/dependency_links.txt
social_auth_app_django.egg-info/not-zip-safe
social_auth_app_django.egg-info/requires.txt
social_auth_app_django.egg-info/top_level.txt
social_django/__init__.py
social_django/admin.py
social_django/compat.py
social_django/config.py
social_django/context_processors.py
social_django/fields.py
social_django/managers.py
social_django/middleware.py
social_django/models.py
social_django/storage.py
social_django/strategy.py
social_django/urls.py
social_django/utils.py
social_django/views.py
social_django/management/__init__.py
social_django/management/commands/__init__.py
social_django/management/commands/clearsocial.py
social_django/migrations/0001_initial.py
social_django/migrations/0002_add_related_name.py
social_django/migrations/0003_alter_email_max_length.py
social_django/migrations/0004_auto_20160423_0400.py
social_django/migrations/0005_auto_20160727_2333.py
social_django/migrations/0006_partial.py
social_django/migrations/0007_code_timestamp.py
social_django/migrations/0008_partial_timestamp.py
social_django/migrations/__init__.py
tests/__init__.py
tests/compat.py
tests/settings.py
tests/test_admin.py
tests/test_context_processors.py
tests/test_middleware.py
tests/test_models.py
tests/test_strategy.py
tests/test_views.py
tests/urls.py
\ No newline at end of file
__version__ = '2.1.0'
from social_core.backends.base import BaseAuth
# django.contrib.auth.load_backend() will import and instanciate the
# authentication backend ignoring the possibility that it might
# require more arguments. Here we set a monkey patch to
# BaseAuth.__init__ to ignore the mandatory strategy argument and load
# it.
def baseauth_init_workaround(original_init):
def fake_init(self, strategy=None, *args, **kwargs):
from .utils import load_strategy
original_init(self, strategy or load_strategy(), *args, **kwargs)
return fake_init
if not getattr(BaseAuth, '__init_patched', False):
BaseAuth.__init__ = baseauth_init_workaround(BaseAuth.__init__)
BaseAuth.__init_patched = True
default_app_config = 'social_django.config.PythonSocialAuthConfig'
"""Admin settings"""
from itertools import chain
from django.conf import settings
from django.contrib import admin
from social_core.utils import setting_name
from .models import UserSocialAuth, Nonce, Association
class UserSocialAuthOption(admin.ModelAdmin):
"""Social Auth user options"""
list_display = ('user', 'id', 'provider', 'uid')
list_filter = ('provider',)
raw_id_fields = ('user',)
list_select_related = True
def get_search_fields(self, request=None):
search_fields = getattr(
settings, setting_name('ADMIN_USER_SEARCH_FIELDS'), None
)
if search_fields is None:
_User = UserSocialAuth.user_model()
username = getattr(_User, 'USERNAME_FIELD', None) or \
hasattr(_User, 'username') and 'username' or \
None
fieldnames = ('first_name', 'last_name', 'email', username)
all_names = self._get_all_field_names(_User._meta)
search_fields = [name for name in fieldnames
if name and name in all_names]
return ['user__' + name for name in search_fields] + \
getattr(settings, setting_name('ADMIN_SEARCH_FIELDS'), [])
@staticmethod
def _get_all_field_names(model):
names = chain.from_iterable(
(field.name, field.attname)
if hasattr(field, 'attname') else (field.name,)
for field in model.get_fields()
# For complete backwards compatibility, you may want to exclude
# GenericForeignKey from the results.
if not (field.many_to_one and field.related_model is None)
)
return list(set(names))
class NonceOption(admin.ModelAdmin):
"""Nonce options"""
list_display = ('id', 'server_url', 'timestamp', 'salt')
search_fields = ('server_url',)
class AssociationOption(admin.ModelAdmin):
"""Association options"""
list_display = ('id', 'server_url', 'assoc_type')
list_filter = ('assoc_type',)
search_fields = ('server_url',)
admin.site.register(UserSocialAuth, UserSocialAuthOption)
admin.site.register(Nonce, NonceOption)
admin.site.register(Association, AssociationOption)
# coding=utf-8
import six
import django
from django.db import models
try:
from django.urls import reverse
except ImportError:
from django.core.urlresolvers import reverse
try:
from django.utils.deprecation import MiddlewareMixin
except ImportError:
MiddlewareMixin = object
def get_rel_model(field):
if django.VERSION >= (2, 0):
return field.remote_field.model
user_model = field.rel.to
if isinstance(user_model, six.string_types):
app_label, model_name = user_model.split('.')
user_model = models.get_model(app_label, model_name)
return user_model
def get_request_port(request):
if django.VERSION >= (1, 9):
return request.get_port()
host_parts = request.get_host().partition(':')
return host_parts[2] or request.META['SERVER_PORT']
from django.apps import AppConfig
class PythonSocialAuthConfig(AppConfig):
# Full Python path to the application eg. 'django.contrib.admin'.
name = 'social_django'
# Last component of the Python path to the application eg. 'admin'.
label = 'social_django'
# Human-readable name for the application eg. "Admin".
verbose_name = 'Python Social Auth'
from django.contrib.auth import REDIRECT_FIELD_NAME
from django.utils.functional import SimpleLazyObject
from django.utils.http import urlquote
try:
from django.utils.functional import empty as _empty
empty = _empty
except ImportError: # django < 1.4
empty = None
from social_core.backends.utils import user_backends_data
from .utils import Storage, BACKENDS
class LazyDict(SimpleLazyObject):
"""Lazy dict initialization."""
def __getitem__(self, name):
if self._wrapped is empty:
self._setup()
return self._wrapped[name]
def __setitem__(self, name, value):
if self._wrapped is empty:
self._setup()
self._wrapped[name] = value
def backends(request):
"""Load Social Auth current user data to context under the key 'backends'.
Will return the output of social_core.backends.utils.user_backends_data."""
return {'backends': LazyDict(lambda: user_backends_data(request.user,
BACKENDS,
Storage))}
def login_redirect(request):
"""Load current redirect to context."""
value = request.method == 'POST' and \
request.POST.get(REDIRECT_FIELD_NAME) or \
request.GET.get(REDIRECT_FIELD_NAME)
if value:
value = urlquote(value)
querystring = REDIRECT_FIELD_NAME + '=' + value
else:
querystring = ''
return {
'REDIRECT_FIELD_NAME': REDIRECT_FIELD_NAME,
'REDIRECT_FIELD_VALUE': value,
'REDIRECT_QUERYSTRING': querystring
}
import json
import six
import functools
import django
from django.core.exceptions import ValidationError
from django.conf import settings
from django.db import models
from social_core.utils import setting_name
try:
from django.utils.encoding import smart_unicode as smart_text
smart_text # placate pyflakes
except ImportError:
from django.utils.encoding import smart_text
# SubfieldBase causes RemovedInDjango110Warning in 1.8 and 1.9, and
# will not work in 1.10 or later
if django.VERSION[:2] >= (1, 8):
field_metaclass = type
else:
from django.db.models import SubfieldBase
field_metaclass = SubfieldBase
field_class = functools.partial(six.with_metaclass, field_metaclass)
if getattr(settings, setting_name('POSTGRES_JSONFIELD'), False):
from django.contrib.postgres.fields import JSONField as JSONFieldBase
else:
JSONFieldBase = field_class(models.TextField)
class JSONField(JSONFieldBase):
"""Simple JSON field that stores python structures as JSON strings
on database.
"""
def __init__(self, *args, **kwargs):
kwargs.setdefault('default', dict)
super(JSONField, self).__init__(*args, **kwargs)
def from_db_value(self, value, expression, connection, context):
return self.to_python(value)
def to_python(self, value):
"""
Convert the input JSON value into python structures, raises
django.core.exceptions.ValidationError if the data can't be converted.
"""
if self.blank and not value:
return {}
value = value or '{}'
if isinstance(value, six.binary_type):
value = six.text_type(value, 'utf-8')
if isinstance(value, six.string_types):
try:
# with django 1.6 i have '"{}"' as default value here
if value[0] == value[-1] == '"':
value = value[1:-1]
return json.loads(value)
except Exception as err:
raise ValidationError(str(err))
else:
return value
def validate(self, value, model_instance):
"""Check value is a valid JSON string, raise ValidationError on