跳转到主要内容

RADIUS认证模块

项目描述

Travis CI Status Code Coverage https://badge.fury.io/py/py-radius.svg

py-radius

Python 2.7.13+的RADIUS认证模块

(c) 1999 Stuart Bishop <zen@shangri-la.dropbear.id.au>

此模块提供了基本的RADIUS客户端功能,允许您的Python代码对任何符合RFC2138规范的RADIUS服务器进行认证。

安装

$ pip install py-radius

使用方法

radius.py模块可以从命令行运行,提供一个最小的RADIUS客户端来测试RADIUS服务器

$ python -m radius
Host [default: 'radius']: radius
Port [default: 1812]: 1812
Enter RADIUS Secret: s3cr3t
Enter your username: foobar
Enter your password: qux
...
Authentication Successful

示例

以下是使用库的一个示例。

import radius

radius.authenticate(username, password, secret, host='radius', port=1812)

# - OR -

r = radius.Radius(secret, host='radius', port=1812)
print('success' if r.authenticate(username, password) else 'failure')

如果您的RADIUS服务器需要挑战/响应,使用方法会更复杂一些。

import radius

r = radius.Radius(secret, host='radius')

try:
    print('success' if r.authenticate(username, password) else 'failure')
    sys.exit(0)
except radius.ChallengeResponse as e:
    pass

# The ChallengeResponse exception has `messages` and `state` attributes
# `messages` can be displayed to the user to prompt them for their
# challenge response. `state` must be echoed back as a RADIUS attribute.

# Send state as an attribute _IF_ provided.
attrs = {'State': e.state} if e.state else {}

# Finally authenticate again using the challenge response from the user
# in place of the password.
print('success' if r.authenticate(username, response, attributes=attrs)
                else 'failure')

此模块具有详细的日志记录,您可以使用Python日志框架启用它。

项目详情


下载文件

下载适合您平台的文件。如果您不确定要选择哪个,请了解更多关于安装包的信息。

源代码分发

py-radius-2.0.2-1.tar.gz (8.3 kB 查看哈希)

上传时间: 源代码

由以下提供支持

AWS AWS 云计算和安全赞助商 Datadog Datadog 监控 Fastly Fastly CDN Google Google 下载分析 Microsoft Microsoft PSF赞助商 Pingdom Pingdom 监控 Sentry Sentry 错误日志 StatusPage StatusPage 状态页面