1
0
mirror of https://github.com/MarkParker5/STARK.git synced 2024-11-29 08:22:03 +02:00

save tokens endpoint

This commit is contained in:
MarkParker5 2022-04-27 00:16:04 +02:00
parent 76b06c7344
commit fae0310445
No known key found for this signature in database
GPG Key ID: C87FA4BD47B5A169
3 changed files with 15 additions and 1 deletions

View File

@ -38,3 +38,9 @@ class HubManager:
def wifi(self, ssid: str, password: str):
WiFi.save_and_connect(ssid, password)
def set_tokens(tokens_pair: schemas.TokensPair):
with open(f'{path}/{resources}/access_token.txt', 'w') as f:
f.write(tokens_pair.access_token)
with open(f'{path}/{resources}/refresh_token.txt', 'w') as f:
f.write(tokens_pair.refresh_token)

View File

@ -2,7 +2,7 @@ from uuid import UUID
from fastapi import APIRouter, Depends
import Controls.API.exceptions
from .HubManager import HubManager
from .schemas import Hub, PatchHub
from .schemas import Hub, PatchHub, TokensPair
router = APIRouter(
@ -25,3 +25,7 @@ async def hub_patch(hub: PatchHub, manager: HubManager = Depends()):
@router.post('/wifi')
async def hub_wifi(ssid: str, password: str, manager: HubManager = Depends()):
manager.wifi(ssid, password)
@router.post('set_tokens')
async def set_tokens(tokens: TokensPair):
manager.save_tokens(tokens)

View File

@ -12,3 +12,7 @@ class Hub(BaseModel):
class Config:
orm_mode = True
class TokensPair(BaseModel):
access_token: str
refresh_token: str