Skip to content

Commit

Permalink
Reset token to empty string
Browse files Browse the repository at this point in the history
  • Loading branch information
LLipter committed Dec 6, 2024
1 parent 73798be commit a3b4d67
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 3 deletions.
8 changes: 6 additions & 2 deletions python/mujinwebstackclient/controllerwebclientraw.py
Original file line number Diff line number Diff line change
Expand Up @@ -258,5 +258,9 @@ def CallGraphAPI(self, query, variables=None, headers=None, timeout=5.0):
return content['data']

def UpdateJsonWebToken(self, jsonWebToken):
self._session.auth = None
self._headers['Authorization'] = 'Bearer ' + jsonWebToken
if jsonWebToken == '':
self._session.auth = None
self._headers['Authorization'] = 'Bearer ' + jsonWebToken
else:
self._session.auth = requests_auth.HTTPBasicAuth(self._username, self._password)
self._headers.pop('Authorization', None)
4 changes: 3 additions & 1 deletion python/mujinwebstackclient/webstackclient.py
Original file line number Diff line number Diff line change
Expand Up @@ -206,10 +206,12 @@ def Login(self, timeout=5):
"""
try:
self.jsonWebToken = self.graphApi.Login(username=self.controllerusername, password=self.controllerpassword, fields={'jsonWebToken': None})['jsonWebToken']
self._webclient.UpdateJsonWebToken(self.jsonWebToken)
except Exception as e:
self.jsonWebToken = ''
log.debug('failed to login through graphql api, use basic HTTP authorization: %s', e)
self.Ping(timeout=timeout)
finally:
self._webclient.UpdateJsonWebToken(self.jsonWebToken)

def Ping(self, timeout=5):
"""Sends a dummy HEAD request to api endpoint
Expand Down

0 comments on commit a3b4d67

Please sign in to comment.