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

Generate more secure API tokens #2377

Merged
merged 1 commit into from
Mar 30, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 3 additions & 6 deletions python/nav/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
from functools import wraps
from itertools import chain, tee, groupby, islice
from operator import itemgetter
from secrets import token_hex

import IPy

Expand Down Expand Up @@ -469,12 +470,8 @@ def address_to_string(ip, port):


def auth_token():
"""Generates a hash that can be used as an OAuth API token"""
from django.conf import settings

_hash = hashlib.sha1(str(uuid.uuid4()).encode('utf-8'))
_hash.update(settings.SECRET_KEY.encode('utf-8'))
return _hash.hexdigest()
"""Generates a hex token that can be used as an OAuth API token"""
return token_hex(32)


def consecutive(seq):
Expand Down