summaryrefslogtreecommitdiffstats
path: root/api/models
diff options
context:
space:
mode:
authorAndrew Godwin2022-12-10 21:03:14 -0700
committerAndrew Godwin2022-12-12 11:56:49 -0700
commit1017c71ba1d80a1690e357a938ad46f246a456ae (patch)
treeffe6172f5f38bb1c8aac3c42ada272bba40348e7 /api/models
parenta8d1450763bea6f8d5388633b62a92c7d89913b6 (diff)
downloadtakahe-1017c71ba1d80a1690e357a938ad46f246a456ae.tar.gz
takahe-1017c71ba1d80a1690e357a938ad46f246a456ae.tar.bz2
takahe-1017c71ba1d80a1690e357a938ad46f246a456ae.zip
Working start of an OAuth flow
Diffstat (limited to 'api/models')
-rw-r--r--api/models/__init__.py2
-rw-r--r--api/models/application.py19
-rw-r--r--api/models/token.py39
3 files changed, 60 insertions, 0 deletions
diff --git a/api/models/__init__.py b/api/models/__init__.py
new file mode 100644
index 0000000..663cd7e
--- /dev/null
+++ b/api/models/__init__.py
@@ -0,0 +1,2 @@
+from .application import Application # noqa
+from .token import Token # noqa
diff --git a/api/models/application.py b/api/models/application.py
new file mode 100644
index 0000000..89bea5f
--- /dev/null
+++ b/api/models/application.py
@@ -0,0 +1,19 @@
+from django.db import models
+
+
+class Application(models.Model):
+ """
+ OAuth applications
+ """
+
+ client_id = models.CharField(max_length=500)
+ client_secret = models.CharField(max_length=500)
+
+ redirect_uris = models.TextField()
+ scopes = models.TextField()
+
+ name = models.CharField(max_length=500)
+ website = models.CharField(max_length=500, blank=True, null=True)
+
+ created = models.DateTimeField(auto_now_add=True)
+ updated = models.DateTimeField(auto_now=True)
diff --git a/api/models/token.py b/api/models/token.py
new file mode 100644
index 0000000..dc57cec
--- /dev/null
+++ b/api/models/token.py
@@ -0,0 +1,39 @@
+from django.db import models
+
+
+class Token(models.Model):
+ """
+ An (access) token to call the API with.
+
+ Can be either tied to a user, or app-level only.
+ """
+
+ application = models.ForeignKey(
+ "api.Application",
+ on_delete=models.CASCADE,
+ related_name="tokens",
+ )
+
+ user = models.ForeignKey(
+ "users.User",
+ blank=True,
+ null=True,
+ on_delete=models.CASCADE,
+ related_name="tokens",
+ )
+
+ identity = models.ForeignKey(
+ "users.Identity",
+ blank=True,
+ null=True,
+ on_delete=models.CASCADE,
+ related_name="tokens",
+ )
+
+ token = models.CharField(max_length=500)
+ code = models.CharField(max_length=100, blank=True, null=True)
+
+ scopes = models.JSONField()
+
+ created = models.DateTimeField(auto_now_add=True)
+ updated = models.DateTimeField(auto_now=True)