66 lines
2.1 KiB
Python
66 lines
2.1 KiB
Python
from django.db import models
|
|
|
|
from apps.common.models import BaseModel
|
|
from apps.common.utils import generate_client_id
|
|
|
|
|
|
class ApplicationStatus(models.TextChoices):
|
|
ACTIVE = "active", "Active"
|
|
INACTIVE = "inactive", "Inactive"
|
|
PENDING = "pending", "Pending"
|
|
|
|
|
|
class GrantType(models.TextChoices):
|
|
AUTHORIZATION_CODE = "authorization_code", "Authorization Code"
|
|
REFRESH_TOKEN = "refresh_token", "Refresh Token"
|
|
CLIENT_CREDENTIALS = "client_credentials", "Client Credentials"
|
|
|
|
|
|
class Application(BaseModel):
|
|
client_id = models.CharField(
|
|
max_length=64,
|
|
unique=True,
|
|
default=generate_client_id,
|
|
editable=False,
|
|
)
|
|
client_secret_hash = models.CharField(max_length=128, blank=True, default="")
|
|
product_key = models.SlugField(max_length=64, unique=True)
|
|
name = models.CharField(max_length=200)
|
|
description = models.TextField(blank=True, default="")
|
|
website_url = models.URLField(max_length=500, blank=True, default="")
|
|
logo_url = models.URLField(max_length=500, blank=True, default="")
|
|
redirect_uris = models.JSONField(default=list, blank=True)
|
|
allowed_origins = models.JSONField(default=list, blank=True)
|
|
grant_types = models.JSONField(
|
|
default=list,
|
|
blank=True,
|
|
)
|
|
response_types = models.JSONField(default=list, blank=True)
|
|
scopes = models.ManyToManyField("oauth.OAuthScope", related_name="applications", blank=True)
|
|
token_endpoint_auth_method = models.CharField(
|
|
max_length=32,
|
|
default="client_secret_post",
|
|
)
|
|
status = models.CharField(
|
|
max_length=16,
|
|
choices=ApplicationStatus.choices,
|
|
default=ApplicationStatus.ACTIVE,
|
|
)
|
|
created_by = models.ForeignKey(
|
|
"identity.User",
|
|
on_delete=models.SET_NULL,
|
|
null=True,
|
|
blank=True,
|
|
related_name="applications",
|
|
)
|
|
|
|
class Meta:
|
|
ordering = ["-created_at"]
|
|
indexes = [
|
|
models.Index(fields=["client_id"]),
|
|
models.Index(fields=["product_key"]),
|
|
models.Index(fields=["status"]),
|
|
]
|
|
|
|
def __str__(self):
|
|
return self.name |