Skip to main content

base

AuthComponent

from dara.core.auth.base import AuthComponent

class AuthComponent(TypedDict)

Defines an auth component.

This is separate from the main component system because it is used for auth, before an authenticated session is created and we can use the component system.

Attributes

  • py_module: str
  • js_module: str
  • js_name: str

py_module

Name of python module

js_module

Name of javascript module

js_name

Name of javascript component

AuthComponentConfig

from dara.core.auth.base import AuthComponentConfig

class AuthComponentConfig(BaseModel)

Attributes

  • login: AuthComponent
  • logout: AuthComponent
  • extra: Dict[str, AuthComponent]

login

Login component

logout

Logout component

extra

Extra components, map of route -> component

BaseAuthConfig

from dara.core.auth.base import BaseAuthConfig

class BaseAuthConfig(BaseModel, abc.ABC)

Attributes

  • component_config: ClassVar[AuthComponentConfig]

Methods

component_config

Defines components to use for auth routes

get_token

@abc.abstractmethod
def get_token(
body: SessionRequestBody) -> Union[TokenResponse, RedirectResponse]

Get a session token.

Can return the token directly or choose to return a redirect response instead

Arguments:

  • body: request body

verify_token

@abc.abstractmethod
def verify_token(token: str) -> Union[Any, TokenData]

Verify a session token.

Should set SESSION_ID and USER context variables

Returns token data

Arguments:

  • token: encoded token

refresh_token

def refresh_token(old_token: TokenData, refresh_token: str) -> tuple[str, str]

Create a new session token and refresh token from a refresh token.

Note: the new issued session token should include the same session_id as the old token

Arguments:

  • old_token: old session token data
  • refresh_token: encoded refresh token

Returns:

new session token, new refresh token

revoke_token

def revoke_token(
token: str,
response: Response) -> Union[SuccessResponse, RedirectResponse]

Revoke a session token.

Arguments:

  • token: encoded token
  • response: response object