oauth2.py 文件源码

python
阅读 29 收藏 0 点赞 0 评论 0

项目:st2-auth-backend-oauth2 作者: pidah 项目源码 文件源码
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
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号