Skip to content

Commit

Permalink
Specify token name when requesting token (#217)
Browse files Browse the repository at this point in the history
- Allows better token control on the server
  • Loading branch information
SchrodingersGat committed Jan 30, 2024
1 parent 4a8433e commit aa49c25
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion inventree/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ def __init__(self, host=None, **kwargs):
username - Login username
password - Login password
token - Authentication token (if provided, username/password are ignored)
token-name - Name of the token to use (default = 'inventree-python-client')
use_token_auth - Use token authentication? (default = True)
verbose - Print extra debug messages (default = False)
timeout - Set timeout to use (in seconds). Default: 10
Expand All @@ -62,6 +63,7 @@ def __init__(self, host=None, **kwargs):
self.username = kwargs.get('username', os.environ.get('INVENTREE_API_USERNAME', None))
self.password = kwargs.get('password', os.environ.get('INVENTREE_API_PASSWORD', None))
self.token = kwargs.get('token', os.environ.get('INVENTREE_API_TOKEN', None))
self.token_name = kwargs.get('token_name', os.environ.get('INVENTREE_API_TOKEN_NAME', 'inventree-python-client'))
self.timeout = kwargs.get('timeout', os.environ.get('INVENTREE_API_TIMEOUT', 10))
self.proxies = kwargs.get('proxies', dict())

Expand Down Expand Up @@ -244,7 +246,12 @@ def requestToken(self):

# Request an auth token from the server
try:
response = self.get('/user/token/')
response = self.get(
'/user/token/',
params={
'name': self.token_name,
}
)
except Exception as e:
logger.error(f"Error requesting token: {str(type(e))}")
return None
Expand Down

0 comments on commit aa49c25

Please sign in to comment.