mirror of
https://github.com/fastapi-practices/fastapi-best-architecture.git
synced 2026-10-01 16:21:25 +00:00
20 lines
596 B
Python
20 lines
596 B
Python
#!/usr/bin/env python3
|
|
# -*- coding: utf-8 -*-
|
|
from typing import Dict
|
|
|
|
from starlette.testclient import TestClient
|
|
|
|
from backend.app.core.conf import settings
|
|
|
|
|
|
def get_token_headers(client: TestClient, username: str, password: str) -> Dict[str, str]:
|
|
data = {
|
|
'username': username,
|
|
'password': password,
|
|
}
|
|
response = client.post(f'{settings.API_V1_STR}/auth/swagger_login', data=data)
|
|
token_type = response.json()['token_type']
|
|
access_token = response.json()['access_token']
|
|
headers = {'Authorization': f'{token_type} {access_token}'}
|
|
return headers
|