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

Add HttpToken class for authenticating tokens with 'Token' prefix #1371

Closed
wants to merge 1 commit into from

Conversation

Mooshiiee
Copy link

Just a copy-and-paste of the HttpBearer class that instead checks for 'Token' prefix.

'Token' Prefix comes standard with Django DRF TokenAuthentication and should be included for more seamless use within DRF ecosystem.

Just a copy-and-paste of the HttpBearer class that instead checks for 'Token' prefix.

'Token' Prefix comes standard with Django DRF TokenAuthentication  and should be included for more seamless use within DRF ecosystem.
@vitalik
Copy link
Owner

vitalik commented Dec 29, 2024

Hi @Mooshiiee

I think you can simply extend bearer class:

class HttpToken(HttpBearer):
    openapi_scheme: str = "token"

@jnoring-pw
Copy link

jnoring-pw commented Dec 30, 2024

I used @vitalik 's precise solution.

It's also worth noting DRF is incorrect to use "token"; that is not covered by any official IETF standard and is essentially a custom scheme name. Also, the openapi documentation barfs if you try to use "token". It should just be "bearer", which works correctly with the auto-generated documentation.

@Mooshiiee
Copy link
Author

I appreciate the response! Extending the class is an embarrassing oversight. Happy New Year!

@Mooshiiee Mooshiiee closed this Jan 1, 2025
@Mooshiiee Mooshiiee deleted the patch-1 branch January 1, 2025 21:24
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

Successfully merging this pull request may close these issues.

3 participants