feat: def model for auth grant storage

wip-payments
Aravinth Manivannan 2022-06-06 01:15:59 +05:30
parent 3f02c4f03b
commit 493268c62b
Signed by: realaravinth
GPG Key ID: AD9F0F08E855ED88
15 changed files with 287 additions and 1 deletions

View File

@ -32,7 +32,7 @@ help: ## Prints help for targets with comments
lint: ## Run linter
@./venv/bin/black ./dashboard/*
@./venv/bin/black ./users/*
@./venv/bin/black ./oauth/*
migrate: ## Run migrations
$(call run_migrations)

View File

@ -41,6 +41,8 @@ INSTALLED_APPS = [
"django.contrib.sessions",
"django.contrib.messages",
"django.contrib.staticfiles",
"oauth",
"oauth.integrations",
]
MIDDLEWARE = [

0
oauth/__init__.py Normal file
View File

20
oauth/admin.py Normal file
View File

@ -0,0 +1,20 @@
# Copyright © 2022 Aravinth Manivannan <realaravinth@batsense.net>
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as
# published by the Free Software Foundation, either version 3 of the
# License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
from django.contrib import admin
from .models import AuthorizationGrant
admin.site.register(AuthorizationGrant)

6
oauth/apps.py Normal file
View File

@ -0,0 +1,6 @@
from django.apps import AppConfig
class OauthConfig(AppConfig):
default_auto_field = "django.db.models.BigAutoField"
name = "oauth"

View File

@ -0,0 +1,54 @@
# Generated by Django 4.0.3 on 2022-06-05 19:37
from django.conf import settings
from django.db import migrations, models
import django.db.models.deletion
class Migration(migrations.Migration):
initial = True
dependencies = [
("integrations", "0001_initial"),
migrations.swappable_dependency(settings.AUTH_USER_MODEL),
]
operations = [
migrations.CreateModel(
name="AuthorizationGrant",
fields=[
(
"code_text",
models.CharField(
blank=True,
default="GGw2HiQ1PaR9qXDkShgLHzx1zoi50tZD",
editable=False,
max_length=32,
primary_key=True,
serialize=False,
unique=True,
verbose_name="Authorization Code",
),
),
(
"issued_date",
models.DateTimeField(auto_now_add=True, verbose_name="date issued"),
),
(
"authorized_by",
models.ForeignKey(
on_delete=django.db.models.deletion.CASCADE,
to=settings.AUTH_USER_MODEL,
),
),
(
"issued_to",
models.ForeignKey(
on_delete=django.db.models.deletion.CASCADE,
to="integrations.oauthintegration",
),
),
],
),
]

View File

@ -0,0 +1,27 @@
# Generated by Django 4.0.3 on 2022-06-05 19:37
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
("oauth", "0001_initial"),
]
operations = [
migrations.AlterField(
model_name="authorizationgrant",
name="code_text",
field=models.CharField(
blank=True,
default="3lxQluG1v0yp73bNKYey0TEoDW3eXQxH",
editable=False,
max_length=32,
primary_key=True,
serialize=False,
unique=True,
verbose_name="Authorization Code",
),
),
]

View File

@ -0,0 +1,27 @@
# Generated by Django 4.0.3 on 2022-06-05 19:40
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
("oauth", "0002_alter_authorizationgrant_code_text"),
]
operations = [
migrations.AlterField(
model_name="authorizationgrant",
name="code_text",
field=models.CharField(
blank=True,
default="6Ciye3K1OWfDDy7BJJ50S5NE1Rev5fKA",
editable=False,
max_length=32,
primary_key=True,
serialize=False,
unique=True,
verbose_name="Authorization Code",
),
),
]

View File

@ -0,0 +1,27 @@
# Generated by Django 4.0.3 on 2022-06-05 19:42
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
("oauth", "0003_alter_authorizationgrant_code_text"),
]
operations = [
migrations.AlterField(
model_name="authorizationgrant",
name="code_text",
field=models.CharField(
blank=True,
default="RfvqA3tKdTDqwaSyicR3vQaUygseBanY",
editable=False,
max_length=32,
primary_key=True,
serialize=False,
unique=True,
verbose_name="Authorization Code",
),
),
]

View File

@ -0,0 +1,27 @@
# Generated by Django 4.0.3 on 2022-06-05 19:43
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
("oauth", "0004_alter_authorizationgrant_code_text"),
]
operations = [
migrations.AlterField(
model_name="authorizationgrant",
name="code_text",
field=models.CharField(
blank=True,
default="V1BWmLAqQfhYW9xmCWVRucWQNYE8Lnfp",
editable=False,
max_length=32,
primary_key=True,
serialize=False,
unique=True,
verbose_name="Authorization Code",
),
),
]

View File

37
oauth/models.py Normal file
View File

@ -0,0 +1,37 @@
# Copyright © 2022 Aravinth Manivannan <realaravinth@batsense.net>
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as
# published by the Free Software Foundation, either version 3 of the
# License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
from django.contrib.auth.models import User
from django.db import models
from django.utils.crypto import get_random_string
from .integrations.models import OauthIntegration
class AuthorizationGrant(models.Model):
authorized_by = models.ForeignKey(User, on_delete=models.CASCADE)
code_text = models.CharField(
"Authorization Code",
primary_key=True,
unique=True,
max_length=32,
default=get_random_string(32),
blank=True,
editable=False,
)
issued_date = models.DateTimeField("date issued", auto_now_add=True, blank=True)
issued_to = models.ForeignKey(OauthIntegration, on_delete=models.CASCADE)
def __str__(self):
return f"{self.authorized_by.username}: {self.issued_to.name_text} {self.issued_to.client_id_uuid}"

3
oauth/tests.py Normal file
View File

@ -0,0 +1,3 @@
from django.test import TestCase
# Create your tests here.

24
oauth/urls.py Normal file
View File

@ -0,0 +1,24 @@
# Copyright © 2022 Aravinth Manivannan <realaravinth@batsense.net>
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as
# published by the Free Software Foundation, either version 3 of the
# License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
from django.urls import path, include
from . import views
urlpatterns = [
path("apps/", include("oauth.integrations.urls")),
path("", views.index, name="index"),
]

32
oauth/views.py Normal file
View File

@ -0,0 +1,32 @@
# Copyright © 2022 Aravinth Manivannan <realaravinth@batsense.net>
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as
# published by the Free Software Foundation, either version 3 of the
# License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
from django.shortcuts import render
from django.http import HttpResponse
from django.contrib.auth import authenticate
# Create your views here.
def index(request):
return HttpResponse("Foo bar")
def create_app(request):
return HttpResponse("create app")
def delete_app(request):
return HttpResponse("delete app")