MCPcopy Index your code
hub / github.com/bugy/script-server / authenticate

Method authenticate

src/auth/tornado_auth.py:59–99  ·  view source on GitHub ↗
(self, request_handler)

Source from the content-addressed store, hash-verified

57
58 @gen.coroutine
59 def authenticate(self, request_handler):
60 if not self.is_enabled():
61 return
62
63 LOGGER.info('Trying to authenticate user')
64
65 login_generic_error = 'Something went wrong. Please contact the administrator or try later'
66
67 try:
68 username = self.authenticator.authenticate(request_handler)
69 if asyncio.iscoroutine(username):
70 username = yield username
71
72 except auth_base.AuthRejectedError as e:
73 respond_error(request_handler, 401, e.get_message())
74 return
75
76 except auth_base.AuthFailureError:
77 respond_error(request_handler, 500, login_generic_error)
78 return
79
80 except auth_base.AuthBadRequestException as e:
81 respond_error(request_handler, 400, e.get_message())
82 return
83
84 except:
85 LOGGER.exception('Failed to call authenticate')
86 respond_error(request_handler, 500, login_generic_error)
87 return
88
89 LOGGER.info('Authenticated user ' + username)
90
91 request_handler.set_secure_cookie('username', username, expires_days=self.authenticator.auth_expiration_days)
92
93 path = tornado.escape.url_unescape(request_handler.get_argument('next', '/'))
94
95 # redirect only to internal URLs
96 if path.startswith('http'):
97 path = '/'
98
99 redirect_relative(path, request_handler)
100
101 def get_client_visible_config(self):
102 result = {'type': self.authenticator.auth_type}

Callers

nothing calls this directly

Calls 4

is_enabledMethod · 0.95
respond_errorFunction · 0.90
redirect_relativeFunction · 0.90
get_messageMethod · 0.45

Tested by

no test coverage detected