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

How to get the auth token? #219

Closed
steverecio opened this issue Aug 12, 2020 · 2 comments
Closed

How to get the auth token? #219

steverecio opened this issue Aug 12, 2020 · 2 comments

Comments

@steverecio
Copy link

Maybe I'm missing this somewhere in the docs but where do I get the string to pass into the authorization header? I presume its not the digest, token_key, or salt given that those fields are all stored in plaintext in the database but the model doesn't seem to have any helper method to get the actual auth token...

@steverecio
Copy link
Author

Ok I was able to get the token with the following code (discovered by looking through the unit tests):

instance, token = AuthToken.objects.create(user=user)

And then pass the header Authorization: Token {{ token }}.

Is there a way to get this token from the model object so that I can use a non-expiring token for my client facing API keys?

@jonathan-golorry
Copy link

Is there a way to get this token from the model object

No. Only a prefix and hash (and previously salt) are stored in the db. The whole point is that an attacker will be unable to calculate the token even if they get a copy of the DB.

so that I can use a non-expiring token for my client facing API keys?

You can configure knox for non-expiring tokens.

REST_KNOX = {
    "TOKEN_TTL": None,
}

@johnraz johnraz closed this as completed Jul 22, 2024
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

3 participants