Skip to main content
Class representing a user that must be authenticated by logging in. This is often used to define the user returned by the get_user function of the ProviderConfigs class. This class can be imported from the squirrels.auth or the squirrels module.

Constructor

Creates a RegisteredUser object.
def __init__(
    self, *, username: str, access_level: Literal['admin', 'member'], 
    custom_fields: CustomUserFields
) -> None:

Example

from squirrels import auth, arguments as args

@auth.provider(
  name="google", label="Google", 
  icon="https://www.google.com/favicon.ico"
)
def google_auth_provider(sqrl: args.AuthProviderArgs) -> auth.ProviderConfigs:
    def get_sqrl_user(claims: dict) -> auth.RegisteredUser:
        custom_fields = auth.CustomUserFields() # or the derived class
        return auth.RegisteredUser(
            username=claims["email"],
            access_level="member",
            custom_fields=custom_fields
        )
    
    provider_configs = auth.ProviderConfigs(
        client_id=sqrl.env_vars["GOOGLE_CLIENT_ID"],
        client_secret=sqrl.env_vars["GOOGLE_CLIENT_SECRET"],
        server_url="https://accounts.google.com",
        client_kwargs={"scope": "openid email profile"},
        get_user=get_sqrl_user
    )

    return provider_configs