Skip to content

Commit

Permalink
Merge pull request #2377 from johannaengland/secure-api-token
Browse files Browse the repository at this point in the history
Generate more secure API tokens
  • Loading branch information
johannaengland authored Mar 30, 2022
2 parents a1a6a15 + 7fabaab commit d0e14cf
Showing 1 changed file with 3 additions and 6 deletions.
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

0 comments on commit d0e14cf

Please sign in to comment.