Skip to content

Commit ae055f1

Browse files
committed
Core: Added token refreshing
1 parent 44efbbd commit ae055f1

File tree

2 files changed

+17
-1
lines changed

2 files changed

+17
-1
lines changed

README.md

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,4 +98,7 @@ jules.lasne@gmail.com
9898
- [ ] Migrate tests to pytest-recording
9999
- [ ] Add a readthedocs documentation
100100
- [ ] Switch to an OpenAPI generated client ? see https://github.com/shellhub-io/shellhub/issues/3497#issuecomment-1917478654
101-
- [ ] Add deployment to pypi on merge to main
101+
- [ ] Add deployment to pypi on merge to main
102+
- [ ] Add a changelog
103+
- [ ] Setup coverage reporting
104+
- [ ] Update tests to tests on multiple python versions

shellhub/models/base.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,19 @@ def make_request(
6868
},
6969
json=json,
7070
)
71+
72+
if response.status_code == 401:
73+
self._login()
74+
response = getattr(requests, method.lower())(
75+
f"{self._endpoint}{endpoint}{params if params else ''}",
76+
headers={
77+
"Authorization": f"Bearer {self._access_token}",
78+
},
79+
json=json,
80+
)
81+
if response.status_code == 401:
82+
raise ShellHubApiError("Couldn't fix request with a token refresh")
83+
7184
return response
7285

7386
def _get_devices(

0 commit comments

Comments
 (0)