mirror of
https://github.com/jointakahe/takahe.git
synced 2024-11-22 15:21:01 +00:00
5d2ed9edfe
Removes django-ninja and replaces it with a new API framework, "hatchway". I plan to move hatchway into its own project very soon.
28 lines
773 B
Python
28 lines
773 B
Python
import secrets
|
|
|
|
from hatchway import Schema, api_view
|
|
|
|
from .. import schemas
|
|
from ..models import Application
|
|
|
|
|
|
class CreateApplicationSchema(Schema):
|
|
client_name: str
|
|
redirect_uris: str
|
|
scopes: None | str = None
|
|
website: None | str = None
|
|
|
|
|
|
@api_view.post
|
|
def add_app(request, details: CreateApplicationSchema) -> schemas.Application:
|
|
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 schemas.Application.from_orm(application)
|