极简和独立于框架的oauth(1&2)消费者

uniauth的Python项目详细描述


注意

有关最新消息来源、讨论等,请访问 GitHub repository

单位

https://travis-ci.org/jthi3rry/uniauth.svg?branch=masterhttps://coveralls.io/repos/jthi3rry/uniauth/badge.png?branch=master

提供通用OAuth(1&2)消费者(或轻松添加更多内容的能力)的极简和独立于框架的包。

  • 将oauth1和oauth2结合成一个简单明了的舞蹈
  • 规范提供商的配置文件数据
  • 使OAuth1&2令牌正常化以进行存储/恢复
  • 基于oauthlibrequests

安装

pip install uniauth

使用量

检索令牌:

from uniauth import Bitbucket, GitHub

# Use an OAuth2 client
client = GitHub(client_id="****************", client_secret="****************", scope=None)

# Or an OAuth1 client
client = Bitbucket(client_id="****************", client_secret="****************")

# Provides a unified flow for both OAuth1 & OAuth2
oauth_dance = client.dance(stash, "http://example.org/oauth/callback")

# 'stash' allows to complete the oauth dance over multiple requests (by maintaining OAuth1's request token or OAuth2's state)
# It can be anything as long as it implements __setattr__(key, value) and pop(key, default)
# e.g.:
#     stash = request.session
# Or
#     stash = {}

# Redirect your user to:
oauth_dance.get_authorization_url()

# Get the access token using the absolute url the povider redirected your user to:
normalised_token = oauth_dance.get_access_token(callback_url)
# {"token": "**********", "extra": "**********", "expires_at": None, "scope": None}

# The token is also stored in the client state
client.get_profile()

还原令牌:

# OAuth2 client
client = GitHub(client_id="****************", client_secret="****************", scope=None, token=normalised_token)

# or OAuth1 client
client = Bitbucket(client_id="****************", client_secret="****************", token=normalised_token)

client.get_profile()

请求任何资源:

# client.request has a similar signature to requests.request but with an optional method (it uses "GET" by default)
response = client.request(url_to_resource)

# response is an instance of requests.Response
response.raise_for_status()

data = response.json()

就这样。

可用消费者

位桶

使用uniauth.Bitbucket

Facebook

使用uniauth.Facebook

Github

使用uniauth.GitHub

谷歌

使用uniauth.Google

LinkedIn

使用uniauth.LinkedIn

贡献更多

很容易添加更多消费者:

from uniauth.base import ProfileMixin
from uniauth.oauth2 import OAuth2Consumer

class MyProviderName(ProfileMixin, OAuth2Consumer):
    authorization_url = "https://example.org/oauth2/authorization"
    access_token_url = "https://example.org/oauth2/access_token"
    profile_url = "https://example.org/user/"

    def normalize_profile_data(self, data):
        # transform provider's format into normalised format
        return {"uid": data.get("id"),
                "email": data.get("email_address"),
                "username": data.get("login"),
                "first_name": data.get("given_name"),
                "last_name": data.get("family_name"),
                "gender": data.get("sex"),
                "birthdate": data.get("dob"),
                "avatar_url": data.get("picture"),
                "is_verified": data.get("verified")}

运行测试

获取存储库的副本:

git clone git@github.com:OohlaLabs/uniauth.git .

安装tox

pip install tox

运行测试:

tox

贡献

欢迎大家发表意见。

更改日志

v0.0.2

  • 将默认提供程序名称强制转换为Unicode
  • 修复未使用的资源请求附加参数

v0.0.1

  • 首字母

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

推荐PyPI第三方库


热门话题
java爬虫获取外部网站搜索结果   java Bluestack未连接到eclipse   java如何从ConstraintViolationException Hibernamte获取数据库字段名   HttpResponse HttpResponse=httpClient引发java运行时错误。执行(httpPost);   Jama中矩阵的java点积和叉积   java有什么方法可以唯一地识别可扩展设备吗?   java我需要用*来写我的名字,但我不断遇到一个错误,我对编码很陌生   java变量是在内部类中访问的。需要被宣布为最终决定。但我不想宣布最终结果   java如何缩短base64图像字符串,Android?   JavaSpringMVC:计划方法不自动触发   图形学习Java 2D API的好资源是什么?   如何在java中对方法进行排队   java JavaFX多行   java Selenium无法在[链接]上找到基于CSS元素的密码字段元素http://www.cartasi.it/gtwpages/index.jsp   Java中的equals()和hashCode()契约   软删除情况下的java Hibernate二级缓存   java为什么这段代码要两次调用这些方法?