Skip to main content

SenWeaver-OAuth

💫 强大、灵活且易用的OAuth授权集成组件 - Python版。提供统一便捷的第三方登录解决方案,已集成40+主流平台,包括Github、Gitee、微博、钉钉、百度、QQ、微信、Google、Facebook、抖音、领英、微软、飞书、京东、支付宝等国内外知名平台的OAuth授权。

特性

  • 丰富的OAuth平台: 支持国内外数十家知名的第三方平台的OAuth登录
  • 自定义state: 支持自定义State和缓存方式,开发者可根据实际情况选择任意缓存插件
  • 自定义OAuth: 提供统一接口,支持接入任意OAuth网站,快速实现OAuth登录功能
  • 自定义Http接口: 提供统一的HTTP工具接口,开发者可以根据自己项目的实际情况选择相对应的HTTP工具
  • 自定义Scope: 支持自定义scope,以适配更多的业务场景,而不仅仅是为了登录
  • 多种缓存实现: 支持内存缓存和Redis缓存,满足单实例和分布式应用的需求
  • 代码规范·简单: 代码结构清晰、逻辑简单,遵循Python编码规范

快速开始

安装

pip install senweaver-oauth

使用示例

from senweaver_oauth import AuthRequest, AuthConfig
from senweaver_oauth.source import AuthGiteeSource

# 创建授权request
auth_config = AuthConfig(
    client_id="clientId",
    client_secret="clientSecret",
    redirect_uri="redirectUri"
)
auth_request = AuthRequest.build(AuthGiteeSource, auth_config)

# 生成授权页面
auth_url = auth_request.authorize("state")
print(auth_url)

# 授权登录
callback = {
    "code": "授权码",
    "state": "state"
}
auth_response = auth_request.login(callback)
print(auth_response)

或者使用Builder模式:

from senweaver_oauth import AuthRequestBuilder
from senweaver_oauth import AuthConfig

# 方式一:静态配置AuthConfig
auth_request = AuthRequestBuilder.builder() \
    .source("gitee") \
    .auth_config(AuthConfig(
        client_id="clientId",
        client_secret="clientSecret",
        redirect_uri="redirectUri"
    )) \
    .build()

# 生成授权页面
auth_url = auth_request.authorize("state")
print(auth_url)

# 方式二:动态获取并配置AuthConfig
def get_config(source):
    # 通过source动态获取AuthConfig
    # 此处可以灵活的从数据库或配置文件中获取配置
    return AuthConfig(
        client_id="clientId",
        client_secret="clientSecret",
        redirect_uri="redirectUri"
    )

auth_request = AuthRequestBuilder.builder() \
    .source("gitee") \
    .auth_config_function(get_config) \
    .build()

# 自定义平台
auth_request = AuthRequestBuilder.builder() \
    .extend_source(CustomAuthSource) \
    .source("custom") \
    .auth_config(AuthConfig(
        client_id="clientId",
        client_secret="clientSecret",
        redirect_uri="redirectUri"
    )) \
    .build()

使用Redis缓存

默认情况下,SenWeaver OAuth使用内存缓存存储OAuth状态和令牌信息。对于分布式应用,可以使用Redis缓存:

import redis
from senweaver_oauth.cache import RedisCacheStore, DefaultCacheStore

# 创建Redis客户端
redis_client = redis.Redis(
    host="localhost",
    port=6379,
    db=0,
    password=None
)

# 创建Redis缓存存储
redis_cache = RedisCacheStore(
    redis_client=redis_client,
    prefix="senweaver_oauth:",  # 缓存键前缀
    ttl=300  # 默认过期时间(秒)
)

# 设置为默认缓存实例
DefaultCacheStore.set_instance(redis_cache)

更多缓存配置请参考缓存存储文档。

已实现的平台

SenWeaver OAuth目前已集成以下40+平台的授权登录:

平台 授权方式 平台 授权方式 平台 授权方式
Github OAuth 2.0 Gitee OAuth 2.0 微博 OAuth 2.0
钉钉 OAuth 2.0 百度 OAuth 2.0 QQ OAuth 2.0
微信 OAuth 2.0 微信开放平台 OAuth 2.0 微信小程序 OAuth 2.0
微信企业版 OAuth 2.0 Google OAuth 2.0 Facebook OAuth 2.0
抖音 OAuth 2.0 领英 OAuth 2.0 微软 OAuth 2.0
飞书 OAuth 2.0 淘宝 OAuth 2.0 京东 OAuth 2.0
支付宝 OAuth 2.0 推特 OAuth 1.0a 小米 OAuth 2.0
华为 OAuth 2.0 企业微信 OAuth 2.0 酷家乐 OAuth 2.0
Gitlab OAuth 2.0 美团 OAuth 2.0 饿了么 OAuth 2.0
阿里云 OAuth 2.0 今日头条 OAuth 2.0 Teambition OAuth 2.0
StackOverflow OAuth 2.0 Pinterest OAuth 2.0 人人网 OAuth 2.0
腾讯云开发平台 OAuth 2.0 OSChina OAuth 2.0 Coding OAuth 2.0
Amazon OAuth 2.0 Slack OAuth 2.0 Line OAuth 2.0
喜马拉雅 OAuth 2.0 学科网 OAuth 2.0

更多平台正在持续添加中...

示例项目

贡献

欢迎贡献代码,提交问题和建议!

开源协议

MIT

Metadata

Release files for senweaver-oauth 0.1.4

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for senweaver-oauth 0.1.4
File Size Uploaded
senweaver_oauth-0.1.4.tar.gz 52.3 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for senweaver-oauth 0.1.4
File Interpreter ABI Platform
senweaver_oauth-0.1.4-py3-none-any.whl Python 3 none any Details

Total release size: 161.9 kB

Release files / senweaver_oauth-0.1.4.tar.gz

Download URL senweaver_oauth-0.1.4.tar.gz
Size 52.3 kB
Tags Source
SHA-256 checksum
How to use checksums
f678bb4c7f767a24bdd28478122188f4e79a6025953fa427865882f8a8533f9d
BLAKE2b-256 checksum
How to use checksums
0ca508564b70416cf59fc787dd082de334c68ee2fcfe37a0713e038e0c0f8612
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.13.7

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Feb 2, 2026.

Transparency log

Release files / senweaver_oauth-0.1.4-py3-none-any.whl

Download URL senweaver_oauth-0.1.4-py3-none-any.whl
Size 109.6 kB
Tags Python 3
SHA-256 checksum
How to use checksums
58c65a3c5320d10b4e859af6e7e41c175350c0f64bfcad38b20b1fc27abb4d30
BLAKE2b-256 checksum
How to use checksums
88e49c46b70663eac6959fe6d6d4272ca27859ddfeb4c5cf8d2dd96abc4c87c6
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.13.7

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Feb 2, 2026.

Transparency log

Release history Release notifications | RSS feed

This release

0.1.4 This release

2 release files

0.1.3

2 release files

0.1.2

2 release files

0.1.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page