Skip to content

Commit d519350

Browse files
committed
#654 made oauth failure to logout user for any oauth (not only keycloak)
1 parent 1940e9e commit d519350

File tree

3 files changed

+10
-14
lines changed

3 files changed

+10
-14
lines changed

src/auth/auth_abstract_oauth.py

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
import tornado
1414
import tornado.ioloop
1515
from tornado import httpclient, escape
16+
from tornado.httpclient import HTTPClientError
1617

1718
from auth import auth_base
1819
from auth.auth_base import AuthFailureError, AuthBadRequestException, AuthRejectedError
@@ -266,10 +267,13 @@ async def _do_update_user_auth_async(self, username, user_state, access_token):
266267

267268
try:
268269
user_info = await self.fetch_user_info(access_token) # type: _OauthUserInfo
269-
except AuthRejectedError:
270-
LOGGER.info(f'User {username} is not authenticated anymore. Logging out')
271-
self._remove_user(username)
272-
return
270+
except (AuthRejectedError, HTTPClientError) as e:
271+
if (not isinstance(e, HTTPClientError)) or (e.code == 401):
272+
LOGGER.info(f'User {username} is not authenticated anymore. Logging out')
273+
self._remove_user(username)
274+
return
275+
else:
276+
raise e
273277

274278
if (not user_info) or (not user_info.username):
275279
LOGGER.error('Failed to fetch user info: %s', str(user_info))

src/auth/auth_keycloak_openid.py

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,8 @@
11
import logging
22

33
from tornado import escape
4-
from tornado.httpclient import HTTPClientError
54

65
from auth.auth_abstract_oauth import AbstractOauthAuthenticator, _OauthUserInfo
7-
from auth.auth_base import AuthRejectedError
86
from model import model_helper
97

108
LOGGER = logging.getLogger('script_server.GoogleOauthAuthorizer')
@@ -33,13 +31,7 @@ async def fetch_user_info(self, access_token) -> _OauthUserInfo:
3331
self._realm_url + 'protocol/openid-connect/userinfo',
3432
headers={'Authorization': 'Bearer ' + access_token})
3533

36-
try:
37-
user_response = await user_future
38-
except HTTPClientError as e:
39-
if e.code == 401:
40-
raise AuthRejectedError('Failed to fetch user info')
41-
else:
42-
raise e
34+
user_response = await user_future
4335

4436
if not user_response:
4537
raise Exception('No response during loading userinfo')

src/web/script_config_socket.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -197,7 +197,7 @@ def load_model():
197197
self.close(code=CorruptConfigFileException.HTTP_CODE, reason=str(e))
198198
return None
199199
except Exception:
200-
message = 'Failed to load script config ' + config_name
200+
message = 'Failed to load script config ' + str(config_name)
201201
LOGGER.exception(message)
202202
self.close(code=500, reason=message)
203203
return None

0 commit comments

Comments
 (0)