Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Extend the starlette simple user #120

Closed
signebedi opened this issue Mar 29, 2024 · 1 comment
Closed

Extend the starlette simple user #120

signebedi opened this issue Mar 29, 2024 · 1 comment

Comments

@signebedi
Copy link
Owner

Right now, the starlette simple user only stores the username. But, in order to minimize the number of database queries, perhaps we can store a little more - like the user ID and API key...

Originally posted by @signebedi in #19 (comment)

@signebedi
Copy link
Owner Author

See source at https://github.com/encode/starlette/blob/master/starlette/authentication.py:

class BaseUser:
    @property
    def is_authenticated(self) -> bool:
        raise NotImplementedError()  # pragma: no cover

    @property
    def display_name(self) -> str:
        raise NotImplementedError()  # pragma: no cover

    @property
    def identity(self) -> str:
        raise NotImplementedError()  # pragma: no cover


class SimpleUser(BaseUser):
    def __init__(self, username: str) -> None:
        self.username = username

    @property
    def is_authenticated(self) -> bool:
        return True

    @property
    def display_name(self) -> str:
        return self.username


class UnauthenticatedUser(BaseUser):
    @property
    def is_authenticated(self) -> bool:
        return False

    @property
    def display_name(self) -> str:
        return ""

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant