Many broken things

This commit is contained in:
Jens Langhammer
2018-11-16 09:10:35 +01:00
parent 79490984d1
commit fbaab4efaf
104 changed files with 3056 additions and 63 deletions

View File

@ -0,0 +1,3 @@
"""passbook oauth_provider Header"""
__version__ = '0.0.1-alpha'
default_app_config = 'passbook.oauth_provider.apps.PassbookOAuthProviderConfig'

View File

@ -0,0 +1,4 @@
"""passbook oauth provider Admin"""
from passbook.lib.admin import admin_autoregister
admin_autoregister('passbook_oauth_provider')

View File

@ -0,0 +1,10 @@
"""passbook auth oauth provider app config"""
from django.apps import AppConfig
class PassbookOAuthProviderConfig(AppConfig):
"""passbook auth oauth provider app config"""
name = 'passbook.oauth_provider'
label = 'passbook_oauth_provider'

View File

@ -0,0 +1,70 @@
# SOME DESCRIPTIVE TITLE.
# Copyright (C) YEAR THE PACKAGE'S COPYRIGHT HOLDER
# This file is distributed under the same license as the PACKAGE package.
# FIRST AUTHOR <EMAIL@ADDRESS>, YEAR.
#
#, fuzzy
msgid ""
msgstr ""
"Project-Id-Version: PACKAGE VERSION\n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2018-08-16 18:05+0000\n"
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
"Language-Team: LANGUAGE <LL@li.org>\n"
"Language: \n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: 8bit\n"
"Plural-Forms: nplurals=2; plural=(n != 1);\n"
#: templates/oauth2_provider/authorize.html:18
msgid "SSO - Authorize External Source"
msgstr ""
#: templates/oauth2_provider/authorize.html:29
#, python-format
msgid ""
"\n"
" You're about to sign into %(remote)s\n"
" "
msgstr ""
#: templates/oauth2_provider/authorize.html:33
msgid "Application requires following permissions"
msgstr ""
#: templates/oauth2_provider/authorize.html:42
#, python-format
msgid ""
"\n"
" You are logged in as %(user)s. Not you?\n"
" "
msgstr ""
#: templates/oauth2_provider/authorize.html:45
msgid "Logout"
msgstr ""
#: templates/oauth2_provider/authorize.html:49
msgid "Continue"
msgstr ""
#: templates/oauth2_provider/authorize.html:52
msgid "Cancel"
msgstr ""
#: templates/oauth2_provider/authorize.html:59
#, python-format
msgid "Error: %(err)s"
msgstr ""
#: views/oauth2.py:49
#, python-format
msgid "You authenticated %s (via OAuth) (skipped Authz)"
msgstr ""
#: views/oauth2.py:62
#, python-format
msgid "You authenticated %s (via OAuth)"
msgstr ""

View File

@ -0,0 +1,69 @@
# SOME DESCRIPTIVE TITLE.
# Copyright (C) YEAR THE PACKAGE'S COPYRIGHT HOLDER
# This file is distributed under the same license as the PACKAGE package.
# FIRST AUTHOR <EMAIL@ADDRESS>, YEAR.
#
#, fuzzy
msgid ""
msgstr ""
"Project-Id-Version: PACKAGE VERSION\n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2018-08-20 10:47+0000\n"
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
"Language-Team: LANGUAGE <LL@li.org>\n"
"Language: \n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: 8bit\n"
#: templates/oauth2_provider/authorize.html:18
msgid "SSO - Authorize External Source"
msgstr ""
#: templates/oauth2_provider/authorize.html:29
#, python-format
msgid ""
"\n"
" You're about to sign into %(remote)s\n"
" "
msgstr ""
#: templates/oauth2_provider/authorize.html:33
msgid "Application requires following permissions"
msgstr ""
#: templates/oauth2_provider/authorize.html:42
#, python-format
msgid ""
"\n"
" You are logged in as %(user)s. Not you?\n"
" "
msgstr ""
#: templates/oauth2_provider/authorize.html:45
msgid "Logout"
msgstr ""
#: templates/oauth2_provider/authorize.html:49
msgid "Continue"
msgstr ""
#: templates/oauth2_provider/authorize.html:52
msgid "Cancel"
msgstr ""
#: templates/oauth2_provider/authorize.html:59
#, python-format
msgid "Error: %(err)s"
msgstr ""
#: views/oauth2.py:49
#, python-format
msgid "You authenticated %s (via OAuth) (skipped Authz)"
msgstr ""
#: views/oauth2.py:62
#, python-format
msgid "You authenticated %s (via OAuth)"
msgstr ""

View File

@ -0,0 +1,70 @@
# SOME DESCRIPTIVE TITLE.
# Copyright (C) YEAR THE PACKAGE'S COPYRIGHT HOLDER
# This file is distributed under the same license as the PACKAGE package.
# FIRST AUTHOR <EMAIL@ADDRESS>, YEAR.
#
#, fuzzy
msgid ""
msgstr ""
"Project-Id-Version: PACKAGE VERSION\n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2018-08-16 18:05+0000\n"
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
"Language-Team: LANGUAGE <LL@li.org>\n"
"Language: \n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: 8bit\n"
"Plural-Forms: nplurals=2; plural=(n != 1);\n"
#: templates/oauth2_provider/authorize.html:18
msgid "SSO - Authorize External Source"
msgstr ""
#: templates/oauth2_provider/authorize.html:29
#, python-format
msgid ""
"\n"
" You're about to sign into %(remote)s\n"
" "
msgstr ""
#: templates/oauth2_provider/authorize.html:33
msgid "Application requires following permissions"
msgstr ""
#: templates/oauth2_provider/authorize.html:42
#, python-format
msgid ""
"\n"
" You are logged in as %(user)s. Not you?\n"
" "
msgstr ""
#: templates/oauth2_provider/authorize.html:45
msgid "Logout"
msgstr ""
#: templates/oauth2_provider/authorize.html:49
msgid "Continue"
msgstr ""
#: templates/oauth2_provider/authorize.html:52
msgid "Cancel"
msgstr ""
#: templates/oauth2_provider/authorize.html:59
#, python-format
msgid "Error: %(err)s"
msgstr ""
#: views/oauth2.py:49
#, python-format
msgid "You authenticated %s (via OAuth) (skipped Authz)"
msgstr ""
#: views/oauth2.py:62
#, python-format
msgid "You authenticated %s (via OAuth)"
msgstr ""

View File

@ -0,0 +1,70 @@
# SOME DESCRIPTIVE TITLE.
# Copyright (C) YEAR THE PACKAGE'S COPYRIGHT HOLDER
# This file is distributed under the same license as the PACKAGE package.
# FIRST AUTHOR <EMAIL@ADDRESS>, YEAR.
#
#, fuzzy
msgid ""
msgstr ""
"Project-Id-Version: PACKAGE VERSION\n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2018-08-16 18:05+0000\n"
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
"Language-Team: LANGUAGE <LL@li.org>\n"
"Language: \n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: 8bit\n"
"Plural-Forms: nplurals=2; plural=(n > 1);\n"
#: templates/oauth2_provider/authorize.html:18
msgid "SSO - Authorize External Source"
msgstr ""
#: templates/oauth2_provider/authorize.html:29
#, python-format
msgid ""
"\n"
" You're about to sign into %(remote)s\n"
" "
msgstr ""
#: templates/oauth2_provider/authorize.html:33
msgid "Application requires following permissions"
msgstr ""
#: templates/oauth2_provider/authorize.html:42
#, python-format
msgid ""
"\n"
" You are logged in as %(user)s. Not you?\n"
" "
msgstr ""
#: templates/oauth2_provider/authorize.html:45
msgid "Logout"
msgstr ""
#: templates/oauth2_provider/authorize.html:49
msgid "Continue"
msgstr ""
#: templates/oauth2_provider/authorize.html:52
msgid "Cancel"
msgstr ""
#: templates/oauth2_provider/authorize.html:59
#, python-format
msgid "Error: %(err)s"
msgstr ""
#: views/oauth2.py:49
#, python-format
msgid "You authenticated %s (via OAuth) (skipped Authz)"
msgstr ""
#: views/oauth2.py:62
#, python-format
msgid "You authenticated %s (via OAuth)"
msgstr ""

View File

@ -0,0 +1,29 @@
# Generated by Django 2.1.3 on 2018-11-14 18:35
import django.db.models.deletion
from django.conf import settings
from django.db import migrations, models
class Migration(migrations.Migration):
initial = True
dependencies = [
migrations.swappable_dependency(settings.OAUTH2_PROVIDER_APPLICATION_MODEL),
('passbook_core', '0001_initial'),
]
operations = [
migrations.CreateModel(
name='OAuth2Application',
fields=[
('application_ptr', models.OneToOneField(auto_created=True, on_delete=django.db.models.deletion.CASCADE, parent_link=True, primary_key=True, serialize=False, to='passbook_core.Application')),
('oauth2', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to=settings.OAUTH2_PROVIDER_APPLICATION_MODEL)),
],
options={
'abstract': False,
},
bases=('passbook_core.application',),
),
]

View File

@ -0,0 +1,12 @@
"""Oauth2 provider product extension"""
from django.db import models
from oauth2_provider.models import Application as _OAuth2Application
from passbook.core.models import Application
class OAuth2Application(Application):
"""Associate an OAuth2 Application with a Product"""
oauth2 = models.ForeignKey(_OAuth2Application, on_delete=models.CASCADE)

View File

@ -0,0 +1,2 @@
django-oauth-toolkit
django-cors-middleware

View File

@ -0,0 +1,16 @@
"""passbook OAuth_Provider"""
CORS_ORIGIN_ALLOW_ALL = True
REQUEST_APPROVAL_PROMPT = 'auto'
MIDDLEWARE = [
'oauth2_provider.middleware.OAuth2TokenMiddleware',
'corsheaders.middleware.CorsMiddleware',
]
INSTALLED_APPS = [
'oauth2_provider',
'corsheaders',
]
AUTHENTICATION_BACKENDS = [
'oauth2_provider.backends.OAuth2Backend',
]

View File

@ -0,0 +1,12 @@
"""passbook oauth_provider urls"""
from django.urls import include, path
from passbook.oauth_provider.views import oauth2
urlpatterns = [
# Custom OAuth 2 Authorize View
# path('authorize/', oauth2.PassbookAuthorizationView.as_view(), name="oauth2-authorize"),
# OAuth API
path('oauth2/', include('oauth2_provider.urls', namespace='oauth2_provider')),
]

View File

@ -0,0 +1,58 @@
"""passbook OAuth2 Views"""
from logging import getLogger
from django.contrib import messages
from django.http import Http404, HttpResponseRedirect
from django.utils.translation import ugettext as _
from oauth2_provider.models import get_application_model
from oauth2_provider.views.base import AuthorizationView
# from passbook.core.models import Event, UserAcquirableRelationship
LOGGER = getLogger(__name__)
class PassbookAuthorizationView(AuthorizationView):
"""Custom OAuth2 Authorization View which checks for invite_only products"""
def get(self, request, *args, **kwargs):
"""Check if request.user has a relationship with product"""
full_res = super().get(request, *args, **kwargs)
# If application cannot be found, oauth2_data is {}
if self.oauth2_data == {}:
return full_res
# self.oauth2_data['application'] should be set, if not an error occured
# if 'application' in self.oauth2_data:
# app = self.oauth2_data['application']
# if app.productextensionoauth2_set.exists() and \
# app.productextensionoauth2_set.first().product_set.exists():
# # Only check if there is a connection from OAuth2 Application to product
# product = app.productextensionoauth2_set.first().product_set.first()
# relationship = UserAcquirableRelationship.objects.filter(user=request.user,
# model=product)
# # Product is invite_only = True and no relation with user exists
# if product.invite_only and not relationship.exists():
# LOGGER.warning("User '%s' has no invitation to '%s'", request.user, product)
# messages.error(request, "You have no access to '%s'" % product.name)
# raise Http404
# if isinstance(full_res, HttpResponseRedirect):
# # Application has skip authorization on
# Event.create(
# user=request.user,
# message=_('You authenticated %s (via OAuth) (skipped Authz)' % app.name),
# request=request,
# current=False,
# hidden=True)
return full_res
def post(self, request, *args, **kwargs):
"""Add event on confirmation"""
app = get_application_model().objects.get(client_id=request.GET["client_id"])
# Event.create(
# user=request.user,
# message=_('You authenticated %s (via OAuth)' % app.name),
# request=request,
# current=False,
# hidden=True)
return super().post(request, *args, **kwargs)