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

Enforce authentication statically for ListenBrainz client #8

Open
InputUsername opened this issue Oct 19, 2021 · 2 comments
Open

Enforce authentication statically for ListenBrainz client #8

InputUsername opened this issue Oct 19, 2021 · 2 comments
Labels
enhancement New feature or request

Comments

@InputUsername
Copy link
Owner

We can use the "typestate pattern" to enforce authentication at compile time. To do this, we can make the ListenBrainz type generic over authentication status using a marker trait (eg. AuthStatus). A ListenBrainz<NotAuthenticated> instance then first has to be authenticated to obtain a ListenBrainz<Authenticated>, which can perform methods that require authentication.

I've implemented a proof-of-concept of this in the feature/static-auth branch.

Thoughts?

@InputUsername InputUsername added the enhancement New feature or request label Oct 19, 2021
@shymega
Copy link
Collaborator

shymega commented Apr 5, 2023

I really like this approach. Would you like me to rebase the branch against mainline?

Thinking of using the same approach for my Rust crate for Starling Bank.

@InputUsername
Copy link
Owner Author

Would you like me to rebase the branch against mainline?

Sure, go ahead. I'm very busy at the moment but I might have time to look into it soon.

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

No branches or pull requests

2 participants