33 lines
716 B
Python
33 lines
716 B
Python
import os
|
|
from fastapi import APIRouter, Request
|
|
from fastapi.responses import RedirectResponse
|
|
from app import spotify
|
|
from app.config import settings
|
|
|
|
router = APIRouter(prefix="/auth", tags=["auth"])
|
|
|
|
|
|
@router.get("/login")
|
|
def spotify_login():
|
|
return RedirectResponse(url=spotify.get_auth_url())
|
|
|
|
|
|
@router.get("/callback")
|
|
def spotify_callback(code: str):
|
|
spotify.exchange_code(code)
|
|
return RedirectResponse(url="/")
|
|
|
|
|
|
@router.get("/logout")
|
|
def spotify_logout():
|
|
try:
|
|
os.remove(".spotify_cache")
|
|
except FileNotFoundError:
|
|
pass
|
|
return RedirectResponse(url="/auth/login")
|
|
|
|
|
|
@router.get("/status")
|
|
def auth_status():
|
|
return {"authenticated": spotify.is_authenticated()}
|