Source code for rasenmaeher_api.web.api.tokens.schema

"""Token exchange schemas"""
from typing import Any, Dict

from pydantic import BaseModel, Field, Extra


[docs] class JWTExchangeRequestResponse(BaseModel): # pylint: disable=too-few-public-methods """Exchange a TILAUSPALVELU single-use JWT for RASENMAEHER session JWT"""
[docs] jwt: str = Field(description="The token")
[docs] class Config: # pylint: disable=too-few-public-methods """Example values for schema"""
[docs] extra = Extra.forbid
[docs] schema_extra = { "examples": [ {"jwt": "eyJhbGciOiJSUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiJw...jHv3f3MlSQswcHhM"}, ] }
[docs] class LoginCodeCreateRequest(BaseModel): # pylint: disable=too-few-public-methods """TILAUSPALVELU asks us to create an one-time login code that user can input to a field. If TILAUSPALVELU wants to revoke a code it should just exchange it and discard the result"""
[docs] claims: Dict[str, Any] = Field(description="The claims that should be issued when this token is redeemed")
[docs] class Config: # pylint: disable=too-few-public-methods """Example values for schema"""
[docs] extra = Extra.forbid
[docs] schema_extra = { "examples": [ { "claims": { "anon_admin_session": True, }, }, ] }
[docs] class LoginCodeRequestResponse(BaseModel): # pylint: disable=too-few-public-methods """The response to LoginCodeCreateRequest and also used to exchange the code"""
[docs] code: str = Field(description="The code user must provide to get a session JWT")
[docs] class Config: # pylint: disable=too-few-public-methods """Example values for schema"""
[docs] extra = Extra.forbid
[docs] schema_extra = { "examples": [ { "code": "ABC1233GHIJ", }, ] }