From 1017c71ba1d80a1690e357a938ad46f246a456ae Mon Sep 17 00:00:00 2001 From: Andrew Godwin Date: Sat, 10 Dec 2022 21:03:14 -0700 Subject: Working start of an OAuth flow --- api/models/__init__.py | 2 ++ api/models/application.py | 19 +++++++++++++++++++ api/models/token.py | 39 +++++++++++++++++++++++++++++++++++++++ 3 files changed, 60 insertions(+) create mode 100644 api/models/__init__.py create mode 100644 api/models/application.py create mode 100644 api/models/token.py (limited to 'api/models') 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) -- cgit v1.2.3