diff --git a/oauth/integrations/__init__.py b/oauth/integrations/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/oauth/integrations/admin.py b/oauth/integrations/admin.py new file mode 100644 index 0000000..737cf1e --- /dev/null +++ b/oauth/integrations/admin.py @@ -0,0 +1,19 @@ +# Copyright © 2022 Aravinth Manivannan +# +# 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 . +from django.contrib import admin + +from .models import OauthIntegration + +admin.site.register(OauthIntegration) diff --git a/oauth/integrations/apps.py b/oauth/integrations/apps.py new file mode 100644 index 0000000..6bac7aa --- /dev/null +++ b/oauth/integrations/apps.py @@ -0,0 +1,6 @@ +from django.apps import AppConfig + + +class IntegrationsConfig(AppConfig): + default_auto_field = "django.db.models.BigAutoField" + name = "oauth.integrations" diff --git a/oauth/integrations/migrations/0001_initial.py b/oauth/integrations/migrations/0001_initial.py new file mode 100644 index 0000000..dda89b7 --- /dev/null +++ b/oauth/integrations/migrations/0001_initial.py @@ -0,0 +1,70 @@ +# 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 +import uuid + + +class Migration(migrations.Migration): + + initial = True + + dependencies = [ + migrations.swappable_dependency(settings.AUTH_USER_MODEL), + ] + + operations = [ + migrations.CreateModel( + name="OauthIntegration", + fields=[ + ( + "name_text", + models.CharField( + max_length=100, verbose_name="name of the application" + ), + ), + ( + "client_id_uuid", + models.UUIDField( + default=uuid.uuid4, + editable=False, + primary_key=True, + serialize=False, + unique=True, + verbose_name="client UUID", + ), + ), + ( + "client_secret_text", + models.CharField( + blank=True, + default="7CM6lfbQ0j1NuWdYhd8HRLMkeWywQUtX", + editable=False, + max_length=32, + unique=True, + verbose_name="client secret", + ), + ), + ( + "privacy_policy_uri", + models.URLField( + default=None, verbose_name="privacy policy of the application" + ), + ), + ( + "redirect_uri", + models.URLField( + unique=True, verbose_name="uri where user is to be redirected" + ), + ), + ( + "owned_by", + models.ForeignKey( + on_delete=django.db.models.deletion.CASCADE, + to=settings.AUTH_USER_MODEL, + ), + ), + ], + ), + ] diff --git a/oauth/integrations/migrations/0002_alter_oauthintegration_client_secret_text.py b/oauth/integrations/migrations/0002_alter_oauthintegration_client_secret_text.py new file mode 100644 index 0000000..7a68278 --- /dev/null +++ b/oauth/integrations/migrations/0002_alter_oauthintegration_client_secret_text.py @@ -0,0 +1,25 @@ +# Generated by Django 4.0.3 on 2022-06-05 19:37 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ("integrations", "0001_initial"), + ] + + operations = [ + migrations.AlterField( + model_name="oauthintegration", + name="client_secret_text", + field=models.CharField( + blank=True, + default="9HBaBiYERc1ogWvwHGWAb9lUKKco8brN", + editable=False, + max_length=32, + unique=True, + verbose_name="client secret", + ), + ), + ] diff --git a/oauth/integrations/migrations/0003_alter_oauthintegration_client_secret_text_and_more.py b/oauth/integrations/migrations/0003_alter_oauthintegration_client_secret_text_and_more.py new file mode 100644 index 0000000..02dc62f --- /dev/null +++ b/oauth/integrations/migrations/0003_alter_oauthintegration_client_secret_text_and_more.py @@ -0,0 +1,34 @@ +# Generated by Django 4.0.3 on 2022-06-05 19:40 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ("integrations", "0002_alter_oauthintegration_client_secret_text"), + ] + + operations = [ + migrations.AlterField( + model_name="oauthintegration", + name="client_secret_text", + field=models.CharField( + blank=True, + default="xTHXiGYQ0yn1f3SbDOy8wh7YolrsySnu", + editable=False, + max_length=32, + unique=True, + verbose_name="client secret", + ), + ), + migrations.AlterField( + model_name="oauthintegration", + name="privacy_policy_uri", + field=models.URLField( + blank=True, + default=None, + verbose_name="privacy policy of the application", + ), + ), + ] diff --git a/oauth/integrations/migrations/0004_alter_oauthintegration_client_secret_text.py b/oauth/integrations/migrations/0004_alter_oauthintegration_client_secret_text.py new file mode 100644 index 0000000..67decf0 --- /dev/null +++ b/oauth/integrations/migrations/0004_alter_oauthintegration_client_secret_text.py @@ -0,0 +1,25 @@ +# Generated by Django 4.0.3 on 2022-06-05 19:42 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ("integrations", "0003_alter_oauthintegration_client_secret_text_and_more"), + ] + + operations = [ + migrations.AlterField( + model_name="oauthintegration", + name="client_secret_text", + field=models.CharField( + blank=True, + default="bUqiljhkmFh845B68APhXDoV9ui9iQwS", + editable=False, + max_length=32, + unique=True, + verbose_name="client secret", + ), + ), + ] diff --git a/oauth/integrations/migrations/0005_alter_oauthintegration_client_secret_text.py b/oauth/integrations/migrations/0005_alter_oauthintegration_client_secret_text.py new file mode 100644 index 0000000..9e82617 --- /dev/null +++ b/oauth/integrations/migrations/0005_alter_oauthintegration_client_secret_text.py @@ -0,0 +1,25 @@ +# Generated by Django 4.0.3 on 2022-06-05 19:43 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ("integrations", "0004_alter_oauthintegration_client_secret_text"), + ] + + operations = [ + migrations.AlterField( + model_name="oauthintegration", + name="client_secret_text", + field=models.CharField( + blank=True, + default="B4siYj3YEZjyF94IfLihJPHNuYOJWds6", + editable=False, + max_length=32, + unique=True, + verbose_name="client secret", + ), + ), + ] diff --git a/oauth/integrations/migrations/__init__.py b/oauth/integrations/migrations/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/oauth/integrations/models.py b/oauth/integrations/models.py new file mode 100644 index 0000000..2a509e4 --- /dev/null +++ b/oauth/integrations/models.py @@ -0,0 +1,45 @@ +# Copyright © 2022 Aravinth Manivannan +# +# 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 . + +import uuid + +from django.db import models +from django.contrib.auth.models import User +from django.utils.crypto import get_random_string + +# Create your models here. + + +class OauthIntegration(models.Model): + owned_by = models.ForeignKey(User, on_delete=models.CASCADE) + name_text = models.CharField("name of the application", max_length=100) + client_id_uuid = models.UUIDField( + "client UUID", default=uuid.uuid4, editable=False, unique=True, primary_key=True + ) + client_secret_text = models.CharField( + "client secret", + unique=True, + max_length=32, + default=get_random_string(32), + blank=True, + editable=False, + ) + privacy_policy_uri = models.URLField( + "privacy policy of the application", default=None, blank=True + ) + redirect_uri = models.URLField("uri where user is to be redirected", unique=True) + + def __str__(self): + return f"{self.name_text}: {self.client_id_uuid}" diff --git a/oauth/integrations/tests.py b/oauth/integrations/tests.py new file mode 100644 index 0000000..7ce503c --- /dev/null +++ b/oauth/integrations/tests.py @@ -0,0 +1,3 @@ +from django.test import TestCase + +# Create your tests here. diff --git a/oauth/integrations/urls.py b/oauth/integrations/urls.py new file mode 100644 index 0000000..315c128 --- /dev/null +++ b/oauth/integrations/urls.py @@ -0,0 +1,20 @@ +# Copyright © 2022 Aravinth Manivannan +# +# 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 . + +from django.urls import path, include + +from . import views + +urlpatterns = [path("", views.index, name="index")] diff --git a/oauth/integrations/views.py b/oauth/integrations/views.py new file mode 100644 index 0000000..86dba47 --- /dev/null +++ b/oauth/integrations/views.py @@ -0,0 +1,23 @@ +# Copyright © 2022 Aravinth Manivannan +# +# 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 . + +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("Integrations bar")