def authenticate(self, username, password):
if username in self._exclude_list:
htpasswd_file = HtpasswdFile(path=self._file_path)
result = htpasswd_file.check_password(username, password)
if result is None:
LOG.info('User "%s" doesn\'t exist' % (username))
elif result is False:
LOG.info('Invalid password for user "%s"' % (username))
elif result is True:
LOG.info(
'Authentication for user "%s" successful' %
(username))
return bool(result)
os.environ['OAUTHLIB_INSECURE_TRANSPORT'] = '1'
oauth = OAuth2Session(
client=LegacyApplicationClient(
client_id=self._client_id))
try:
token = oauth.fetch_token(
token_url=self._token_url,
username=username,
password=password,
client_id=self._client_id,
client_secret=self._client_secret,
verify=False)
except Exception as e:
LOG.info(
'Authentication for user "{}" failed: {}'.format(
username, str(e)))
return False
if token is not None:
LOG.info('Authentication for user "{}" successful'.format(username))
return True
return False
评论列表
文章目录