initial packaging
This commit is contained in:
parent
c01f16ca75
commit
fa56033b9d
|
@ -1,3 +0,0 @@
|
|||
include requirements.txt
|
||||
include MANIFEST.in
|
||||
include VERSION
|
|
@ -1,27 +0,0 @@
|
|||
import sys
|
||||
|
||||
class AppSettings(object):
|
||||
__defaults = {
|
||||
'ADMIN_ROLE': None,
|
||||
}
|
||||
|
||||
def __init__(self, prefix):
|
||||
self.prefix = prefix
|
||||
|
||||
def __getattr__(self, name):
|
||||
if name in self.__defaults:
|
||||
return self._settings(name, self.__defaults[name])
|
||||
else:
|
||||
return self._settings(name)
|
||||
|
||||
def _settings(self, name, default=Ellipsis):
|
||||
from django.conf import settings
|
||||
if default is Ellipsis:
|
||||
return getattr(settings, self.prefix + name)
|
||||
else:
|
||||
return getattr(settings, self.prefix + name, default)
|
||||
|
||||
app_settings = AppSettings('ALLAUTH_A2_')
|
||||
app_settings.__name__ = __name__
|
||||
sys.modules[__name__] = app_settings
|
||||
|
|
@ -1 +0,0 @@
|
|||
# Create your models here.
|
|
@ -1,44 +0,0 @@
|
|||
from allauth.socialaccount import providers
|
||||
from allauth.socialaccount.providers.base import ProviderAccount
|
||||
from allauth.socialaccount.providers.oauth2.provider import OAuth2Provider
|
||||
from allauth.account.models import EmailAddress
|
||||
|
||||
from . import app_settings
|
||||
|
||||
class Authentic2Account(ProviderAccount):
|
||||
def to_str(self):
|
||||
return self.account.uid
|
||||
|
||||
|
||||
class Authentic2Provider(OAuth2Provider):
|
||||
id = 'authentic2'
|
||||
name = 'Authentic2'
|
||||
package = 'allauth_a2'
|
||||
account_class = Authentic2Account
|
||||
|
||||
def extract_uid(self, data):
|
||||
return str(data['username'])
|
||||
|
||||
def extract_common_fields(self, data):
|
||||
return dict(email=data.get('email'),
|
||||
username=data.get('username'),
|
||||
name=data.get('displayname'))
|
||||
|
||||
def extract_email_addresses(self, data):
|
||||
ret = [EmailAddress(email=data['email'],
|
||||
verified=True,
|
||||
primary=True)]
|
||||
return ret
|
||||
|
||||
def sociallogin_from_response(self, request, response):
|
||||
sociallogin = self(Authentic2Provider, self).sociallogin_from_response(
|
||||
request, response)
|
||||
if app_settings.ADMIN_ROLE in response.get('role', []):
|
||||
sociallogin.account.user.is_superuser = True
|
||||
sociallogin.account.user.is_staff = True
|
||||
return sociallogin
|
||||
|
||||
|
||||
|
||||
|
||||
providers.registry.register(Authentic2Provider)
|
|
@ -1,5 +0,0 @@
|
|||
from allauth.socialaccount.providers.oauth2.urls import default_urlpatterns
|
||||
from .provider import Authentic2Provider
|
||||
|
||||
urlpatterns = default_urlpatterns(Authentic2Provider)
|
||||
|
|
@ -1,43 +0,0 @@
|
|||
import urlparse
|
||||
import requests
|
||||
|
||||
from django.core.exceptions import ImproperlyConfigured
|
||||
|
||||
from allauth.socialaccount.providers.oauth2.views import (OAuth2Adapter,
|
||||
OAuth2LoginView,
|
||||
OAuth2CallbackView)
|
||||
from .provider import Authentic2Provider
|
||||
|
||||
|
||||
class Authentic2OAuth2Adapter(OAuth2Adapter):
|
||||
provider_id = Authentic2Provider.id
|
||||
|
||||
def get_url(self):
|
||||
provider = self.get_provider()
|
||||
try:
|
||||
return provider.get_settings()['URL']
|
||||
except IndexError:
|
||||
raise ImproperlyConfigured('The authentic2 provider needs an URL defined in settings')
|
||||
|
||||
@property
|
||||
def access_token_url(self):
|
||||
return urlparse.urljoin(self.get_url(), 'access_token')
|
||||
|
||||
@property
|
||||
def authorize_url(self):
|
||||
return urlparse.urljoin(self.get_url(), 'authorize')
|
||||
|
||||
@property
|
||||
def profile_url(self):
|
||||
return urlparse.urljoin(self.get_url(), 'user-info')
|
||||
|
||||
def complete_login(self, request, app, token, **kwargs):
|
||||
resp = requests.get(self.profile_url,
|
||||
headers={'authorization': 'Bearer %s' % token.token})
|
||||
extra_data = resp.json()
|
||||
return self.get_provider().sociallogin_from_response(request,
|
||||
extra_data)
|
||||
|
||||
|
||||
oauth2_login = OAuth2LoginView.adapter_view(Authentic2OAuth2Adapter)
|
||||
oauth2_callback = OAuth2CallbackView.adapter_view(Authentic2OAuth2Adapter)
|
|
@ -0,0 +1,5 @@
|
|||
allauth-a2 (0.1-1) unstable; urgency=low
|
||||
|
||||
* source package automatically created by stdeb 0.6.0+git
|
||||
|
||||
-- Serghei Mihai <info@entrouvert.com> Thu, 24 Apr 2014 11:46:25 +0200
|
|
@ -0,0 +1 @@
|
|||
7
|
|
@ -0,0 +1,15 @@
|
|||
Source: allauth-a2
|
||||
Maintainer: Benjamin Dauvergne <info@entrouvert.com>
|
||||
Section: python
|
||||
Priority: optional
|
||||
Build-Depends: python-setuptools (>= 0.6b3), python-all (>= 2.6.6-3), debhelper (>= 7),
|
||||
python-django (>= 1.5)
|
||||
Standards-Version: 3.9.1
|
||||
|
||||
Package: python-allauth-a2-provider
|
||||
Architecture: all
|
||||
Depends: ${misc:Depends}, ${python:Depends},
|
||||
python-django-allauth (>= 0.14),
|
||||
python-requests (>= 1.0.0)
|
||||
Description: Authentic2 OAuth2 provider
|
||||
|
|
@ -0,0 +1,9 @@
|
|||
#!/usr/bin/make -f
|
||||
|
||||
# This file was automatically generated by stdeb 0.6.0+git at
|
||||
# Thu, 24 Apr 2014 11:46:25 +0200
|
||||
|
||||
%:
|
||||
dh $@ --with python2 --buildsystem=python_distutils
|
||||
|
||||
|
|
@ -0,0 +1 @@
|
|||
3.0 (quilt)
|
|
@ -0,0 +1 @@
|
|||
extend-diff-ignore="\.egg-info"
|
|
@ -1,2 +0,0 @@
|
|||
django-allauth
|
||||
requests
|
130
setup.py
130
setup.py
|
@ -1,130 +0,0 @@
|
|||
#! /usr/bin/env python
|
||||
|
||||
''' Setup script
|
||||
'''
|
||||
|
||||
import glob
|
||||
import re
|
||||
import sys
|
||||
import os
|
||||
|
||||
from setuptools import setup, find_packages
|
||||
from setuptools.command.install_lib import install_lib as _install_lib
|
||||
from distutils.command.build import build as _build
|
||||
from distutils.command.sdist import sdist
|
||||
from distutils.cmd import Command
|
||||
|
||||
class compile_translations(Command):
|
||||
description = 'compile message catalogs to MO files via django compilemessages'
|
||||
user_options = []
|
||||
|
||||
def initialize_options(self):
|
||||
pass
|
||||
|
||||
def finalize_options(self):
|
||||
pass
|
||||
|
||||
def run(self):
|
||||
try:
|
||||
from django.core.management.commands.compilemessages import \
|
||||
compile_messages
|
||||
for path in ['allauth_a2']:
|
||||
if path.endswith('.py'):
|
||||
continue
|
||||
if not os.path.isdir(os.path.join(path, 'locale')):
|
||||
continue
|
||||
curdir = os.getcwd()
|
||||
os.chdir(os.path.realpath(path))
|
||||
compile_messages(sys.stderr)
|
||||
os.chdir(curdir)
|
||||
except ImportError:
|
||||
print
|
||||
sys.stderr.write('!!! Please install Django >= 1.4 to build translations')
|
||||
print
|
||||
print
|
||||
|
||||
class build(_build):
|
||||
sub_commands = [('compile_translations', None)] + _build.sub_commands
|
||||
|
||||
class install_lib(_install_lib):
|
||||
def run(self):
|
||||
self.run_command('compile_translations')
|
||||
_install_lib.run(self)
|
||||
|
||||
class eo_sdist(sdist):
|
||||
|
||||
def run(self):
|
||||
print "creating VERSION file"
|
||||
if os.path.exists('VERSION'):
|
||||
os.remove('VERSION')
|
||||
version = get_version()
|
||||
version_file = open('VERSION', 'w')
|
||||
version_file.write(version)
|
||||
version_file.close()
|
||||
sdist.run(self)
|
||||
print "removing VERSION file"
|
||||
if os.path.exists('VERSION'):
|
||||
os.remove('VERSION')
|
||||
|
||||
def get_version():
|
||||
|
||||
version = None
|
||||
if os.path.exists('VERSION'):
|
||||
version_file = open('VERSION', 'r')
|
||||
version = version_file.read()
|
||||
version_file.close()
|
||||
return version
|
||||
for d in glob.glob('*'):
|
||||
if not os.path.isdir(d):
|
||||
continue
|
||||
module_file = os.path.join(d, '__init__.py')
|
||||
if not os.path.exists(module_file):
|
||||
continue
|
||||
for v in re.findall("""__version__ *= *['"](.*)['"]""",
|
||||
open(module_file).read()):
|
||||
assert version is None
|
||||
version = v
|
||||
if version:
|
||||
break
|
||||
assert version is not None
|
||||
if os.path.exists('.git'):
|
||||
import subprocess
|
||||
p = subprocess.Popen(['git','describe','--dirty','--match=v*'],
|
||||
stdout=subprocess.PIPE)
|
||||
result = p.communicate()[0]
|
||||
assert p.returncode == 0, 'git returned non-zero'
|
||||
new_version = result.split()[0][1:]
|
||||
assert new_version.split('-')[0] == version, '__version__ must match the last git annotated tag'
|
||||
version = new_version.replace('-', '.')
|
||||
return version
|
||||
|
||||
|
||||
setup(name="allauth_a2",
|
||||
version=get_version(),
|
||||
license="AGPLv3 or later",
|
||||
description="Authentic2 OAuth2 provider",
|
||||
url="http://dev.entrouvert.org/",
|
||||
author="Entr'ouvert",
|
||||
author_email="info@entrouvert.org",
|
||||
maintainer="Benjamin Dauvergne",
|
||||
maintainer_email="info@entrouvert.com",
|
||||
include_package_data=True,
|
||||
packages=find_packages(),
|
||||
scripts=(),
|
||||
setup_requires=[
|
||||
'django>=1.5.5',
|
||||
],
|
||||
install_requires=[
|
||||
'requests>=2.1',
|
||||
'django-allauth',
|
||||
],
|
||||
dependency_links = [
|
||||
'git+git://repos.entrouvert.org/django_allauth_a2_provider',
|
||||
],
|
||||
cmdclass={
|
||||
'build': build,
|
||||
'install_lib': install_lib,
|
||||
'compile_translations': compile_translations,
|
||||
'sdist': eo_sdist
|
||||
},
|
||||
)
|
Reference in New Issue