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

Update GET header API Token for new GLPI versions #30

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
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
14 changes: 11 additions & 3 deletions glpi/glpi.py
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,9 @@ def set_session_token(self):
full_url = self.url + '/initSession'
auth = None

headers = {"App-Token": self.app_token,
self.app_token_format = 'App-Token'

headers = {self.app_token_format: self.app_token,
"Content-Type": "application/json"}

if self.token_auth is not None:
Expand All @@ -215,6 +217,12 @@ def set_session_token(self):
r = requests.request('GET', full_url,
auth=auth, headers=headers)

if r.status_code == 400:
del headers[self.app_token_format]
self.app_token_format = 'App_Token'
headers[self.app_token_format] = self.app_token
r = requests.request('GET', full_url, auth=auth, headers=headers)

try:
if r.status_code == 200:
self.session = r.json()['session_token']
Expand All @@ -237,7 +245,7 @@ def finish_session_token(self):
auth = None

headers = {
"App-Token": self.app_token,
self.app_token_format: self.app_token,
"Content-Type": "application/json",
"Session-Token": self.session
}
Expand Down Expand Up @@ -310,7 +318,7 @@ def request(self, method, url, accept_json=False, headers={},
raise GlpiException("Unable to get Session token: {}".format(e))

if self.app_token is not None:
headers.update({'App-Token': self.app_token})
headers.update({self.app_token_format: self.app_token})

headers.update(input_headers)

Expand Down