1
0
mirror of https://github.com/netbox-community/netbox.git synced 2024-05-10 07:54:54 +00:00

Fixes #9949: Fix KeyError exception resulting from invalid API token provisioning request

This commit is contained in:
jeremystretch
2022-08-08 11:43:27 -04:00
parent 90317adae7
commit 36ac83a319
2 changed files with 6 additions and 5 deletions

View File

@ -74,11 +74,11 @@ class TokenProvisionView(APIView):
serializer.is_valid()
# Authenticate the user account based on the provided credentials
user = authenticate(
request=request,
username=serializer.data['username'],
password=serializer.data['password']
)
username = serializer.data.get('username')
password = serializer.data.get('password')
if not username or not password:
raise AuthenticationFailed("Username and password must be provided to provision a token.")
user = authenticate(request=request, username=username, password=password)
if user is None:
raise AuthenticationFailed("Invalid username/password")