2022-12-10 20:03:14 -08:00
|
|
|
import secrets
|
|
|
|
|
2023-02-07 11:07:15 -08:00
|
|
|
from hatchway import Schema, api_view
|
2022-12-10 20:03:14 -08:00
|
|
|
|
2022-12-10 23:25:48 -08:00
|
|
|
from .. import schemas
|
2022-12-10 20:03:14 -08:00
|
|
|
from ..models import Application
|
|
|
|
|
|
|
|
|
|
|
|
class CreateApplicationSchema(Schema):
|
|
|
|
client_name: str
|
|
|
|
redirect_uris: str
|
|
|
|
scopes: None | str = None
|
|
|
|
website: None | str = None
|
|
|
|
|
|
|
|
|
2023-02-07 11:07:15 -08:00
|
|
|
@api_view.post
|
|
|
|
def add_app(request, details: CreateApplicationSchema) -> schemas.Application:
|
2022-12-10 20:03:14 -08:00
|
|
|
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",
|
|
|
|
)
|
2023-02-07 11:07:15 -08:00
|
|
|
return schemas.Application.from_orm(application)
|