Project Icon

authentication-zero

Rails应用的自动化认证系统生成器

Authentication Zero是一个Rails插件,为Web和API应用自动生成认证系统代码。它遵循安全和Rails最佳实践,支持注册、登录、密码重置、双因素认证等功能。通过生成代码而非使用库,该插件允许开发者自由修改认证系统,以适应特定需求。Authentication Zero简化了认证系统的实现,同时保持了高度的可定制性。

Authentication Zero

The purpose of authentication zero is to generate a pre-built authentication system into a rails application (web or api-only) that follows both security and rails best practices. By generating code into the user's application instead of using a library, the user has complete freedom to modify the authentication system so it works best with their app.

Installation

$ bundle add authentication-zero

If you are using Rails < 7.1, you must use version 2.

$ bundle add authentication-zero --version "~> 2"

Usage

$ rails generate authentication

Developer responsibilities

Since Authentication Zero generates this code into your application instead of building these modules into the gem itself, you now have complete freedom to modify the authentication system, so it works best with your use case. The one caveat with using a generated authentication system is it will not be updated after it's been generated. Therefore, as improvements are made to the output of rails generate authentication, it becomes your responsibility to determine if these changes need to be ported into your application. Security-related and other important improvements will be explicitly and clearly marked in the CHANGELOG.md file and upgrade notes.

Features

Essential

  • Sign up
  • Email and password validations
  • Checks if a password has been found in any data breach (--pwned)
  • Authentication by cookie
  • Authentication by token (--api)
  • Two factor authentication + recovery codes (--two-factor)
  • Two factor authentication using a hardware security key (--webauthn)
  • Verify email using a link with token
  • Ask password before sensitive data changes, aka: sudo (--sudoable)
  • Reset the user password and send reset instructions
  • Reset the user password only from verified emails
  • Lock mechanism to prevent email bombing (--lockable)
  • Rate limiting for your app, 1000 reqs/minute (--ratelimit)
  • Send e-mail confirmation when your email has been changed
  • Manage multiple sessions & devices
  • Activity log (--trackable)
  • Log out

More

  • Social login with omni auth (--omniauthable)
  • Passwordless authentication (--passwordless)
  • Send invitations (--invitable)
  • "Sign-in as" button (--masqueradable)
  • Multi-tentant application (--tenantable)

Generated code

  • has_secure_password: Adds methods to set and authenticate against a bcrypt password.
  • authenticate_by: Given a set of attributes, finds a record using the non-password attributes, and then authenticates that record using the password attributes.
  • generates_token_for: Defines the behavior of tokens generated for a specific purpose.
  • signed cookies: Returns a jar that'll automatically generate a signed representation of cookie value and verify it when reading from the cookie again.
  • httponly cookies: A cookie with the httponly attribute is inaccessible to the JavaScript, this precaution helps mitigate cross-site scripting (XSS) attacks.
  • signed_id: Returns a signed id that is tamper proof, so it's safe to send in an email or otherwise share with the outside world.
  • current attributes: Abstract super class that provides a thread-isolated attributes singleton, which resets automatically before and after each request.
  • action mailer: Action Mailer allows you to send email from your application using a mailer model and views.
  • log filtering: Parameters 'token' and 'password' are marked [FILTERED] in the log.
  • functional tests: In Rails, testing the various actions of a controller is a form of writing functional tests.
  • system testing: System tests allow you to test user interactions with your application, running tests in either a real or a headless browser.

Sudoable

Use before_action :require_sudo in controllers with sensitive information, it will ask for your password on the first access or after 30 minutes.

Tenantable

Some artifacts are generated in the application, which makes it possible to implement row-level multitenancy applications. The Current.account is set using the current user account.

You should follow some steps to make it work:

  • Add account_id to each scoped table. ex: rails g migration add_account_to_projects account:references.
  • Add include AccountScoped to scoped models. It set up the account relationship and default scope using the current account.

Set Current.account through the URL. http://myapp.com/:account_id. (optional)

  • Add require_relative "../lib/account_middleware" to config/application.rb.
  • Add config.middleware.use AccountMiddleware to your application class.
  • More customization is required...

Development

To release a new version, update the version number in version.rb, and then run bundle exec rake release, which will create a git tag for the version, push git commits and tags, and push the .gem file to rubygems.org.

Contributing

Bug reports and pull requests are welcome on GitHub at https://github.com/lazaronixon/authentication-zero. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the code of conduct.

License

The gem is available as open source under the terms of the MIT License.

Code of Conduct

Everyone interacting in the AuthenticationZero project's codebases, issue trackers, chat rooms and mailing lists is expected to follow the code of conduct.

项目侧边栏1项目侧边栏2
推荐项目
Project Cover

豆包MarsCode

豆包 MarsCode 是一款革命性的编程助手,通过AI技术提供代码补全、单测生成、代码解释和智能问答等功能,支持100+编程语言,与主流编辑器无缝集成,显著提升开发效率和代码质量。

Project Cover

AI写歌

Suno AI是一个革命性的AI音乐创作平台,能在短短30秒内帮助用户创作出一首完整的歌曲。无论是寻找创作灵感还是需要快速制作音乐,Suno AI都是音乐爱好者和专业人士的理想选择。

Project Cover

白日梦AI

白日梦AI提供专注于AI视频生成的多样化功能,包括文生视频、动态画面和形象生成等,帮助用户快速上手,创造专业级内容。

Project Cover

有言AI

有言平台提供一站式AIGC视频创作解决方案,通过智能技术简化视频制作流程。无论是企业宣传还是个人分享,有言都能帮助用户快速、轻松地制作出专业级别的视频内容。

Project Cover

Kimi

Kimi AI助手提供多语言对话支持,能够阅读和理解用户上传的文件内容,解析网页信息,并结合搜索结果为用户提供详尽的答案。无论是日常咨询还是专业问题,Kimi都能以友好、专业的方式提供帮助。

Project Cover

讯飞绘镜

讯飞绘镜是一个支持从创意到完整视频创作的智能平台,用户可以快速生成视频素材并创作独特的音乐视频和故事。平台提供多样化的主题和精选作品,帮助用户探索创意灵感。

Project Cover

讯飞文书

讯飞文书依托讯飞星火大模型,为文书写作者提供从素材筹备到稿件撰写及审稿的全程支持。通过录音智记和以稿写稿等功能,满足事务性工作的高频需求,帮助撰稿人节省精力,提高效率,优化工作与生活。

Project Cover

阿里绘蛙

绘蛙是阿里巴巴集团推出的革命性AI电商营销平台。利用尖端人工智能技术,为商家提供一键生成商品图和营销文案的服务,显著提升内容创作效率和营销效果。适用于淘宝、天猫等电商平台,让商品第一时间被种草。

Project Cover

AIWritePaper论文写作

AIWritePaper论文写作是一站式AI论文写作辅助工具,简化了选题、文献检索至论文撰写的整个过程。通过简单设定,平台可快速生成高质量论文大纲和全文,配合图表、参考文献等一应俱全,同时提供开题报告和答辩PPT等增值服务,保障数据安全,有效提升写作效率和论文质量。

投诉举报邮箱: service@vectorlightyear.com
@2024 懂AI·鲁ICP备2024100362号-6·鲁公网安备37021002001498号