Skip to content

Commit ba72884

Browse files
authored
Merge pull request #88 from LounesAl/fix-refresh-token
Fix: Preserve refresh token if not returned in OAuth refresh response
2 parents cba4767 + e97dcdd commit ba72884

File tree

2 files changed

+6
-1
lines changed

2 files changed

+6
-1
lines changed

streamlit_oauth/__init__.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,11 @@ def refresh_token(self, token, force=False):
134134
if token.get('refresh_token') is None:
135135
raise Exception("Token is expired and no refresh token is available")
136136
else:
137-
token = asyncio.run(self.client.refresh_token(token.get('refresh_token')))
137+
new_token = asyncio.run(self.client.refresh_token(token.get('refresh_token')))
138+
# Keep the old refresh token if the new one is missing it
139+
if not new_token.get('refresh_token'):
140+
new_token['refresh_token'] = token.get('refresh_token')
141+
token = new_token
138142
return token
139143

140144
def revoke_token(self, token, token_type_hint="access_token"):

tests/test_oauth_component.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ def test_refresh_token_expired(monkeypatch):
4848
result = oauth.refresh_token(token)
4949

5050
assert result["access_token"] == "new"
51+
assert "refresh_token" in result
5152

5253

5354
def test_revoke_token(monkeypatch):

0 commit comments

Comments
 (0)