安全地将OAuth响应重定向到已知的客户端。
项目描述
描述
在OAuth工作流程中,由redirect_uri定义的web服务器接收终端用户授权的结果。
通常,这个redirect_uri是一个白名单uri,以避免钓鱼攻击。
不幸的是,这使得编写一个要将OAuth集成到API中的客户端变得很困难,该API的域在事先是未知的。
面对这种情况,我们编写了这个服务器,将谁可以接收OAuth握手结果的决定从OAuth提供者转移到中间件。
工作原理
使用oauth_redirect,OAuth工作流程的工作方式如下
oauth_redirect服务器在TLS受保护的站点上运行。例如: https://oauth.seantis.ch.
OAuth提供者被配置为允许重定向到 https://oauth.seantis.ch/redirect.
想要获取授权的客户端使用一个秘密认证码向oauth_redirect服务器注册自己。
终端用户将看到一个OAuth授权站点,其redirect_uri设置为 https://oauth.seantis.ch/redirect.
结果被发送到oauth_redirect服务器,该服务器将根据客户端是否事先注册以及OAuth提供者的请求中是否包含相应的令牌,将请求转发/代理到客户端。
方法
POST /register/<认证 代码>
由客户端/授权寻求者用于注册自己。客户端需要在注册消息中包含一个秘密认证码。
POST请求的主体是以下形式的json
{ 'url': "The url that handles the forwarded OAuth response.", 'method': "The method with which the url should be called (get, put or post).", 'success_url': "The url the server redirects to if the handler url returns a 2XX code.", 'error_url': "The url the server redirects to if the handler url returns a non-2XX code.", 'ttl': "The optional time to live in seconds (defaults to 3600 seconds)", 'secret': "A client-specific secret that should be used authenticate the forwarded request. If the request does not contain this secret, someone other than oauth_redirect has sent it.", }
返回需要由OAuth提供者传递的令牌
{ 'token': "..." }
(GET|POST) /redirect
端点通过 redirect_uri 与 OAuth 提供商进行通信。为了验证来自 OAuth 提供商的请求,必须包含由 /register/<authentication code> 提供的令牌。
通常,OAuth 提供商提供一些可以传递给 redirect_uri 的值。这个值可以用来将令牌带回 oauth_redirect 服务器。
如果没有这样的值,令牌也可以通过 URL(例如,https://oauth.seantis.ch/redirect?token=…)使用查询参数传递。
任何值都可以,可以是 JSON 主体中的值,也可以是表单数据值或查询参数。
如果重定向请求被接受,它将被代理到注册的 URL。/redirect 请求的结果是代理 URL 的结果。
如果请求被接受,它将被删除。
部署
服务器使用 aiohttp 实现。它需要至少 Python 3.5。
尽管在 oauth_redirect 上可能实现 TLS 支持,但我们建议您将其放在合适的 Web 代理(如 nginx/apache)之后。
要运行服务器,请执行
oauth-redirect --host localhost --port 8080 --database registered --auth <your custom auth code>
运行测试
安装 tox 并运行它
pip install tox tox
限制测试到特定的 Python 版本
tox -e py27
约定
oauth_redirect 尽可能遵循 PEP8。要测试它,请运行
tox -e pep8
oauth_redirect 使用 语义版本控制
构建状态
覆盖率
最新的 PyPI 发布版
许可协议
oauth_redirect 根据 GPLv2 发布
变更日志
0.3.0 (2017-05-24)
添加了定义成功和错误 URL 的功能。[链接]
0.2.0 (2017-05-24)
添加了定义重定向目标应调用的 HTTP 方法的功能。[链接]
添加了对重定向视图处理器支持 GET(除了 POST)的功能。[链接]
0.1.0 (2017-05-23)
初始发布。[链接]
项目详情
下载文件
下载适用于您平台的文件。如果您不确定选择哪个,请了解更多关于 安装包 的信息。
源分发
构建分发
oauth_redirect-0.3.0.tar.gz 的散列
算法 | 散列摘要 | |
---|---|---|
SHA256 | 28b0fecace708df8093af79fee29ff5c17d5689e750343a8adf727afdb895242 |
|
MD5 | 40abb8fa1c61418167d96ad5fa16c954 |
|
BLAKE2b-256 | c16b816225d1425ecb5664b76f716dc7e74ea239f45110b1be53eabf5dc869ff |
oauth_redirect-0.3.0-py3-none-any.whl 的散列
算法 | 散列摘要 | |
---|---|---|
SHA256 | f2c0ca2b0d870d70a220a2d27855534e18267e3cf65fb7430bec1a57af9dcb41 |
|
MD5 | 4769222313a7450fa36265e9debb0b45 |
|
BLAKE2b-256 | 4b97a3f36c39b53318ad1432b1b4f286cedbc616061ad47d92a5650c2e6b574d |