python oauth 2.0客户端用于针对欧洲xfel web应用程序的后端应用程序策略登录

oauth2-xfel-client的Python项目详细描述


负责管理用户身份验证的小型python库 OAuth 2.0客户端后端应用程序策略(从非Web软件到 Web OAuth2提供商)

存储库:

依赖项:

安装

python项目

  1. 安装要求,如果以前从未安装过

1.1. For OS X distributions:

sudo port install python35
sudo port

sudo port select --set python3 python35

sudo port install py35-pip
sudo port select --set pip pip35

sudo port install py35-nose
sudo port select --set nosetests nosetests-3.5

1.2. For Linux distributions:

sudo apt-get update
sudo apt-get install python3.5
  1. 在您的python环境中提供oauth2_xfel_客户端库

2.1. Install it via pip:

# Install dependencies from local wheels files
pip install --no-index --upgrade --find-links ./external_dependencies/*

# Install dependencies from the pypi
pip install -r requirements.txt

Or as a normal python project (via .egg file):

python setup.py install

Running this command the “compiled” oauth2_xfel_client-5.1.1-py3.4.egg file is generated under the current Python installation site-packages folder.

2.2. Install it as a normal python project (via Wheel):

python setup.py bdist_wheel

Running this command 2 folders are generated under the current Python installation site-packages folder:

  • oauth2_xfel_client with the sources;
  • oauth2_xfel_client-5.1.1.dist-info/ with Wheels configuration files.
  1. 要识别python站点包文件夹,请运行:

    python -c "from distutils.sysconfig import get_python_lib; print(get_python_lib())"
    

用法

要使用此项目,您需要导入它。

如果您想直接与这个库交互,您应该导入oauth2clientbackend类:

from oauth2_xfel_client.oauth2_client_backend import Oauth2ClientBackend

或导入所有内容:

import oauth2_xfel_client
  1. 连接到OAuth2客户端:

    from oauth2_xfel_client.oauth2_client_backend import \
    Oauth2ClientBackend as Oauth2Client
    
    # Necessary configuration variables to establish a connection
    # Go to https://in.xfel.eu/metadata/oauth/applications to make a token for
    # the metadata catalogue.
    user_id = '201ed15ff071a63e76cb0b91a1ab17b36d5f92d24b6df4497aa646e39c46a324'
    user_secret = 'a8ae80f5e96531f19bf2d2b6102f5a537196aca44a673ad36533310e07529757'
    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 = ''
    
    # 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)
    
  2. 与oauth2client的交互:

2.1 Example data_group_types:

current_token = oauth_client_valid.get_session_token()

开发和测试

开发时,在提交更改之前,请验证:

  1. 所有测试继续成功通过(以验证运行nosetests):

    # Go to the source code directory
    cd oauth2_xfel_client
    
    # Run all tests
    nosetests .
    
    # Run all tests and get information about coverage for all files inside oauth2_xfel_client package
    pip install nose-cov
    nosetests --with-cov --cover-erase --cover-inclusive --cov-report term-missing --cov oauth2_xfel_client
    
    # Run all tests with xunit
    nosetests --where=./oauth2_xfel_client/ --with-xunit --xunit-file=pythonTest.xml
    
    # If you don't want use nosetests you can simply run the test class
    python oauth2_xfel_client/tests/oauth2_client_backend_test.py
    
  2. 代码始终遵守pycodesyle代码约定(以验证运行pycodesyle):

    pycodestyle .
    
  3. 要为依赖项生成所有wheels文件,请执行:

    # Generate Wheels to its dependencies
    pip wheel --wheel-dir=./external_dependencies -r requirements.txt
    pip wheel --wheel-dir=./external_dependencies --find-links=./external_dependencies -r requirements.txt
    
    # Generate Wheels to itself and dependencies
    pip wheel --wheel-dir=./external_dependencies .
    pip wheel --wheel-dir=./external_dependencies --find-links=./external_dependencies .
    

请确保在requirements.txt和setup.py文件中具有所需的版本。

欢迎加入QQ群-->: 979659372 Python中文网_新手群

推荐PyPI第三方库


热门话题
java如何在收到spring mqtt集成中停止重复订阅保留的消息   java改造安卓在textview中显示数据   读取CSV Java时获取While循环中的最后一行数据   将Java程序转换为小程序的部署   java如何在不向Src添加文件的情况下将文件放入GitLab测试   java包含字节数组列表的方法   java十进制转换错误   eclipse是由java引起的。lang.ClassNotFoundException:org。springframework。js。资源ResourceServlet   继承Java向上与向下   java自动调整标签内容的大小   java从Android中的AlertDialog返回信息   java在声明按钮时仿真程序中出现错误   java编写刷新线程的最佳方法   Java初学者错误   java需要帮助重置JComboBox   java如何用Spring/MultipartFile捕获中断流   java是否可以在JUnit中设置被测试类的方法的返回值?