用于欧洲XFEL Web应用程序后端应用策略身份验证的Python OAUTH 2.0通用客户端
项目描述
负责管理用户身份验证的Python库,使用OAUTH 2.0客户端后端应用策略(从非Web软件到Web Oauth2提供者)
仓库
依赖关系
oauthlib (https://pypi.python.org/pypi/oauthlib)
requests (https://github.com/psf/requests)
requests-oauthlib (https://github.com/requests/requests-oauthlib)
安装
Python项目
安装要求,如果尚未安装
1.1. 对于OS X发行版
1.1.1. Homebrew brew install python3 1.1.2 Port sudo port install python36 sudo port select --set python3 python36 sudo port install py36-pip sudo port select --set pip pip361.2. 对于Linux发行版
sudo apt-get update sudo apt-get install python3.9
在您的Python环境中提供oauth2_xfel_client库
2.1. 使用pip安装它
# Install dependencies from local wheels files pip install . --no-index --find-links ./external_dependencies/ # Install dependencies from the pypi pip install .安装它将在当前Python安装的site-packages文件夹下放置两个文件夹
oauth2_xfel_client 包含源代码;
oauth2_xfel_client-6.1.1.dist-info/ 包含Wheels配置文件。
要识别您的Python site-packages文件夹,请运行
python -c "from distutils.sysconfig import get_python_lib; print(get_python_lib())"
使用方法
要使用此项目,您需要导入它
from oauth2_xfel_client import Oauth2ClientBackend
连接到Oauth2Client(MyMdC示例)
from oauth2_xfel_client import Oauth2ClientBackend as Oauth2Client # Necessary configuration variables to establish a connection # Go to https://in.xfel.eu/metadata/oauth/applications to make generate # or re-use a Client/Secret tokens from the metadata catalogue. user_id = 'PUT_HERE_YOUR_CLIENT_KEY' user_secret = 'PUT_HERE_YOUR_SECRET_KEY' # Go to https://in.xfel.eu/metadata/users/edit and copy "Contact email" user_email = 'luis.maia@xfel.eu' # URLs for the metadata catalogue token_url = 'https://in.xfel.eu/metadata/oauth/token' refresh_url = 'https://in.xfel.eu/metadata/oauth/token' auth_url = 'https://in.xfel.eu/metadata/oauth/authorize' scope = '' base_api_url = 'https://in.xfel.eu/metadata/api/' # Generate the connection oauth_client_valid = Oauth2Client(client_id=user_id, client_secret=user_secret, scope=scope, token_url=token_url, refresh_url=refresh_url, auth_url=auth_url, session_token=None, max_retries=3, timeout=12, ssl_verify=True)
与oauth2Client的交互
2.1 示例数据_group_types
current_token = oauth_client_valid.get_session_token()
开发和测试
在开发过程中,在提交更改之前,请验证以下内容:
所有测试继续成功通过(要验证,请运行 pytest)
# Go to the source code directory cd oauth2_xfel_client # Upgrade package and all its required packages pip install . -U --upgrade-strategy eager # Install test dependencies pip install '.[test]' -U --upgrade-strategy eager # Run all tests using pytest pytest # When running all tests against the standard http application OAUTHLIB_INSECURE_TRANSPORT=1 pytest # Run all tests and get information about coverage for all files inside oauth2_xfel_client package pytest --cov oauth2_xfel_client --cov-report term-missing
代码始终遵守pycodestyle代码规范(验证请运行 pycodestyle)
pycodestyle .
要生成所有依赖项的wheel文件,执行以下命令
# Generate Wheels to itself and dependencies pip wheel --wheel-dir=./external_dependencies . pip wheel --wheel-dir=./external_dependencies --find-links=./external_dependencies .
请检查您是否在 external_dependencies 文件夹中有所需的依赖项版本,因为当前在 setup.py 中没有设置版本。
在 https://pypi.ac.cn 上注册库
要注册此Python库,需要执行以下步骤
# Install twine python -m pip install --upgrade twine # Generates source distribution (.tar.gz) and wheel (.whl) files in the dist/ folder python setup.py sdist python setup.py bdist_wheel # Upload new version .egg and .whl files twine upload dist/* # In case a test is necessary, it is possible to test it against test.pypi.org twine upload --repository-url https://test.pypi.org/legacy/ dist/* --verbose
项目详情
下载文件
下载适合您平台的文件。如果您不确定选择哪个,请了解更多关于 安装包 的信息。