展示HN:Oauth2_capture – 一个用于处理OAuth2令牌流的Django包
我创建了 oauth2_capture(<a href="https://github.com/heysamtexas/django-oauth2-capture">https://github.com/heysamtexas/django-oauth2-capture</a>),这是一个 Django 包,旨在简化从多个提供商捕获、存储和刷新 OAuth2 令牌的过程。
该包目前支持 Twitter/X、LinkedIn、GitHub、Reddit、Pinterest 和 Facebook,未来还计划支持更多提供商。它处理整个 OAuth2 流程,从授权到令牌存储和自动刷新。
主要技术特性:
<pre><code> * 支持 PKCE(对需要此功能的提供商)
* 带重试逻辑的令牌刷新,以应对速率限制(429 响应)
* 干净的 Django 模型和管理集成
* 正确处理令牌过期
</code></pre>
我之所以构建这个包,是因为我在不同的项目中不断重新实现 OAuth2 流程,希望能有一个可重用的解决方案。该包设计得易于扩展,以支持更多提供商。
我非常希望社区能对 API 设计、代码质量或其他有用的功能提供反馈。
是的,django-allauth 在 OAuth 和用户注册/管理方面做得非常出色,但这不是它的功能。
何时使用 oauth2_capture
当您的应用需要以下功能时,请选择 oauth2_capture:
<pre><code> * 代表用户向社交媒体平台发布内容
* 使用用户权限访问提供商 API(如 GitHub、LinkedIn 等)
* 执行需要特定范围内新鲜 OAuth 令牌的操作
* 通过自动令牌刷新维持长期的 API 访问
</code></pre>
何时使用 django-allauth
当您主要需要以下功能时,请选择 django-allauth:
<pre><code> * 用户登录的社交身份验证
* 用户注册和管理
* 邮件验证工作流
* 社交提供商之间的账户关联
</code></pre>
它们可以一起使用吗?
当然可以!您可以使用 django-allauth 进行用户身份验证,而使用 oauth2_capture 进行 API 交互。它们解决不同的问题,互为补充。
简单来说:django-allauth 管理用户,oauth2_capture 管理令牌。
查看原文
I've created oauth2_capture (<a href="https://github.com/heysamtexas/django-oauth2-capture/">https://github.com/heysamtexas/django-oauth2-capture/</a>), a Django package that makes it easy to capture, store, and refresh OAuth2 tokens from multiple providers.<p>The package currently supports Twitter/X, LinkedIn, GitHub, Reddit, Pinterest, and Facebook, with more providers planned. It handles the entire OAuth2 flow, from authorization to token storage and automatic refreshing.<p>Key technical features:<p><pre><code> * PKCE support for providers that require it
* Token refresh with retry logic for rate limiting (429 responses)
* Clean Django models and admin integration
* Proper token expiration handling
</code></pre>
I built this because I kept reimplementing OAuth2 flows in different projects and wanted a reusable solution. The package is designed to be easily extended to support additional providers.<p>I'd love feedback from the community on the API design, code quality, or additional features that would be useful.<p>Yes, Allauth does a great job of oauth and user signups/management. This is not that.<p>When to use oauth2_capture<p>Choose oauth2_capture when your application needs to:<p><pre><code> * Post to social media platforms on behalf of users
* Access provider APIs (GitHub, LinkedIn, etc.) using user permissions
* Perform actions that require fresh OAuth tokens with specific scopes
* Maintain long-term API access with automatic token refreshing
* When to use django-allauth
</code></pre>
Choose django-allauth when you primarily need:<p><pre><code> * Social authentication for user login
* User registration and management
* Email verification workflows
* Account linking between social providers
</code></pre>
Can they be used together?<p>Absolutely! You can use django-allauth for user authentication and oauth2_capture for API interactions. They solve different problems and complement each other well.<p>Simply put: django-allauth manages users, oauth2_capture manages tokens.