jazzband / django-rest-knox

Authentication Module for django rest auth
MIT License
1.1k stars 206 forks source link

Issuing Token outside of LoginView #334

Closed HasanAshab closed 2 months ago

HasanAshab commented 3 months ago

Is there any way to create token outside of LoginView.

There is a method create_token in LoginView

def create_token(self):
        token_prefix = self.get_token_prefix()
        return get_token_model().objects.create(
            user=self.request.user, expiry=self.get_token_ttl(), prefix=token_prefix
        )

but, it may be more concise to have a function like create_token(user).

Thanks in advance!

johnraz commented 2 months ago

Well, the manager method above ( https://github.com/jazzband/django-rest-knox/blob/09403255a069c2416a5dfb889f80342a2d7b2646/knox/models.py#L16 ) is the way to create a token, you can access prefix and ttl from the settings. They are proxied by methods in the LoginView in order to be easily overridden.

I don’t think anything is missing.