This repository has been archived on 2023-09-24. You can view files and clone it, but cannot push or open issues or pull requests.
takahe/api/views/apps.py

30 lines
780 B
Python
Raw Normal View History

2022-12-11 05:03:14 +01:00
import secrets
2022-12-11 08:25:48 +01:00
from ninja import Schema
2022-12-11 05:03:14 +01:00
2022-12-11 08:25:48 +01:00
from .. import schemas
2022-12-11 05:03:14 +01:00
from ..models import Application
2022-12-11 19:22:06 +01:00
from .base import api_router
2022-12-11 05:03:14 +01:00
class CreateApplicationSchema(Schema):
client_name: str
redirect_uris: str
scopes: None | str = None
website: None | str = None
2022-12-11 19:22:06 +01:00
@api_router.post("/v1/apps", response=schemas.Application)
2022-12-11 05:03:14 +01:00
def add_app(request, details: CreateApplicationSchema):
client_id = "tk-" + secrets.token_urlsafe(16)
client_secret = secrets.token_urlsafe(40)
application = Application.objects.create(
name=details.client_name,
website=details.website,
client_id=client_id,
client_secret=client_secret,
redirect_uris=details.redirect_uris,
scopes=details.scopes or "read",
)
return application