mirror of
https://github.com/revanced/revanced-releases-api.git
synced 2025-04-30 06:24:27 +02:00
breaking: change authentication methods
This commit is contained in:
parent
196264d96b
commit
0a9c2bae63
@ -1,7 +1,10 @@
|
|||||||
import os
|
import os
|
||||||
|
import toml
|
||||||
from pydantic import BaseModel
|
from pydantic import BaseModel
|
||||||
|
|
||||||
|
config: dict = toml.load("config.toml")
|
||||||
|
|
||||||
class PasetoSettings(BaseModel):
|
class PasetoSettings(BaseModel):
|
||||||
authpaseto_secret_key: str = os.environ['SECRET_KEY']
|
authpaseto_secret_key: str = os.environ['SECRET_KEY']
|
||||||
authpaseto_access_token_expires: int = 86400
|
authpaseto_access_token_expires: int | bool = config['auth']['access_token_expires']
|
||||||
|
|
@ -68,7 +68,6 @@ class ClientAuthTokenResponse(BaseModel):
|
|||||||
"""
|
"""
|
||||||
|
|
||||||
access_token: str
|
access_token: str
|
||||||
refresh_token: str
|
|
||||||
|
|
||||||
class ClientTokenRefreshResponse(BaseModel):
|
class ClientTokenRefreshResponse(BaseModel):
|
||||||
"""Implements the response fields for client token refresh.
|
"""Implements the response fields for client token refresh.
|
||||||
|
@ -6,20 +6,16 @@ import app.models.ClientModels as ClientModels
|
|||||||
import app.models.GeneralErrors as GeneralErrors
|
import app.models.GeneralErrors as GeneralErrors
|
||||||
import app.models.ResponseModels as ResponseModels
|
import app.models.ResponseModels as ResponseModels
|
||||||
|
|
||||||
router = APIRouter(
|
router = APIRouter()
|
||||||
prefix="/auth",
|
|
||||||
tags=['Authentication']
|
|
||||||
)
|
|
||||||
clients = Clients()
|
clients = Clients()
|
||||||
config: dict = load_config()
|
config: dict = load_config()
|
||||||
|
|
||||||
@router.post('/', response_model=ResponseModels.ClientAuthTokenResponse, status_code=status.HTTP_200_OK)
|
@router.post('/auth', response_model=ResponseModels.ClientAuthTokenResponse, status_code=status.HTTP_200_OK, tags=['Authentication'])
|
||||||
async def auth(request: Request, response: Response, client: ClientModels.ClientAuthModel, Authorize: AuthPASETO = Depends()) -> dict:
|
async def auth(request: Request, response: Response, client: ClientModels.ClientAuthModel, Authorize: AuthPASETO = Depends()) -> dict:
|
||||||
"""Authenticate a client and get an auth token.
|
"""Authenticate a client and get an auth token.
|
||||||
|
|
||||||
Returns:
|
Returns:
|
||||||
access_token: auth token
|
access_token: auth token
|
||||||
refresh_token: refresh token
|
|
||||||
"""
|
"""
|
||||||
|
|
||||||
admin_claim: dict[str, bool]
|
admin_claim: dict[str, bool]
|
||||||
@ -43,36 +39,10 @@ async def auth(request: Request, response: Response, client: ClientModels.Client
|
|||||||
user_claims=admin_claim,
|
user_claims=admin_claim,
|
||||||
fresh=True)
|
fresh=True)
|
||||||
|
|
||||||
refresh_token = Authorize.create_refresh_token(subject=client.id,
|
return {"access_token": access_token}
|
||||||
user_claims=admin_claim)
|
|
||||||
|
|
||||||
return {"access_token": access_token, "refresh_token": refresh_token}
|
|
||||||
else:
|
else:
|
||||||
raise HTTPException(status_code=401, detail={
|
raise HTTPException(status_code=401, detail={
|
||||||
"error": GeneralErrors.Unauthorized().error,
|
"error": GeneralErrors.Unauthorized().error,
|
||||||
"message": GeneralErrors.Unauthorized().message
|
"message": GeneralErrors.Unauthorized().message
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
|
||||||
@router.post('/refresh', response_model=ResponseModels.ClientTokenRefreshResponse,
|
|
||||||
status_code=status.HTTP_200_OK, tags=['Authentication'])
|
|
||||||
async def refresh(request: Request, response: Response,
|
|
||||||
Authorize: AuthPASETO = Depends()) -> dict:
|
|
||||||
"""Refresh an auth token.
|
|
||||||
|
|
||||||
Returns:
|
|
||||||
access_token: auth token
|
|
||||||
"""
|
|
||||||
|
|
||||||
Authorize.paseto_required(refresh_token=True)
|
|
||||||
|
|
||||||
admin_claim: dict[str, bool] = {"admin": False}
|
|
||||||
|
|
||||||
current_user: str | int | None = Authorize.get_subject()
|
|
||||||
|
|
||||||
if 'admin' in Authorize.get_token_payload():
|
|
||||||
admin_claim = {"admin": Authorize.get_token_payload()['admin']}
|
|
||||||
|
|
||||||
return {"access_token": Authorize.create_access_token(subject=current_user,
|
|
||||||
user_claims=admin_claim,
|
|
||||||
fresh=False)}
|
|
@ -54,6 +54,9 @@ database = 4
|
|||||||
[mirrors]
|
[mirrors]
|
||||||
database = 5
|
database = 5
|
||||||
|
|
||||||
|
[auth]
|
||||||
|
access_token_expires = false
|
||||||
|
|
||||||
[app]
|
[app]
|
||||||
|
|
||||||
repositories = ["TeamVanced/VancedMicroG", "revanced/revanced-cli", "revanced/revanced-patcher", "revanced/revanced-patches", "revanced/revanced-integrations", "revanced/revanced-manager", "revanced/revanced-website"]
|
repositories = ["TeamVanced/VancedMicroG", "revanced/revanced-cli", "revanced/revanced-patcher", "revanced/revanced-patches", "revanced/revanced-integrations", "revanced/revanced-manager", "revanced/revanced-website"]
|
||||||
|
Loading…
x
Reference in New Issue
Block a user