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

devel: rest api token auth #469

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

jelly
Copy link
Member

@jelly jelly commented Jul 3, 2023

Implement a simple token authentication header for various "restish" endpoints we might want for adoption/disowning of packages.

Implement a simple token authentication header for various "restish"
endpoints we might want for adoption/disowning of packages.
@raffomania
Copy link

Hey, just a reminder, if you don't find the time to continue this, I'd like to help out :)

Copy link
Member

@anthraxx anthraxx left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Awesome to see progress on this, this will be a very useful feature. Thank you for working on this.


from .fields import PGPKeyField
from main.utils import make_choice, set_created_field

from planet.models import Feed


class AuthTokenBackend(object):
def authenticate(self, request, username=None, password=None):
if 'X-Archweb-Token' in request.headers:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wouldn't it make sense to use Authorization: Bearer as header, this is a quite widely used way for such API and would also allow a lot of HTTP clients to use implemented helper methods for authenticate a request with a token. Otherwise you'd need to pass around custom header strings like X-Archweb-Token.
What are your thoughts about this?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sounds fine to me, it shouldn't conflict with things I suppose.

<form id="api-profile-form" enctype="multipart/form-data" method="post" action="">{% csrf_token %}
<h3>API token</h3>
<p>Token for completing todolist items with for example, rebuild-todo</p>
{% if profile.api_token is None %}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I assume it would be a good pattern to be able to revoke a token, or to phrase it differently: Generate a new token and invalidate the existing one.
I'd probably propose something like only showing the token once when the generate button is clicked and otherwise show an invalidate/regenerate button instead. We should hide the token after generating it.

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