{"id":13879645,"url":"https://github.com/rzane/tiny_auth","last_synced_at":"2025-10-15T07:45:45.828Z","repository":{"id":62559038,"uuid":"221850280","full_name":"rzane/tiny_auth","owner":"rzane","description":"A collection of utilities for authenticating users.","archived":false,"fork":false,"pushed_at":"2021-05-20T15:21:05.000Z","size":51,"stargazers_count":2,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-03-29T10:50:37.620Z","etag":null,"topics":["authentication","password","rails","reset","token"],"latest_commit_sha":null,"homepage":"","language":"Ruby","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/rzane.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.txt","code_of_conduct":"CODE_OF_CONDUCT.md","threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2019-11-15T05:25:41.000Z","updated_at":"2022-05-09T20:48:18.000Z","dependencies_parsed_at":"2022-11-03T11:15:50.984Z","dependency_job_id":null,"html_url":"https://github.com/rzane/tiny_auth","commit_stats":null,"previous_names":[],"tags_count":8,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rzane%2Ftiny_auth","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rzane%2Ftiny_auth/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rzane%2Ftiny_auth/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rzane%2Ftiny_auth/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/rzane","download_url":"https://codeload.github.com/rzane/tiny_auth/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248662361,"owners_count":21141562,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["authentication","password","rails","reset","token"],"created_at":"2024-08-06T08:02:27.620Z","updated_at":"2025-10-15T07:45:40.766Z","avatar_url":"https://github.com/rzane.png","language":"Ruby","funding_links":[],"categories":["Ruby"],"sub_categories":[],"readme":"# TinyAuth [![Build Status](https://travis-ci.org/rzane/tiny_auth.svg?branch=master)](https://travis-ci.org/rzane/tiny_auth) [![Coverage Status](https://coveralls.io/repos/github/rzane/tiny_auth/badge.svg?branch=master)](https://coveralls.io/github/rzane/tiny_auth?branch=master)\n\nA utility for minimal user authentication.\n\n## Installation\n\nAdd this line to your application's Gemfile:\n\n```ruby\ngem 'tiny_auth'\n```\n\nAnd then execute:\n\n    $ bundle\n\n## Usage\n\n### `TinyAuth::Model`\n\nFirst, create a table to store your users:\n\n```ruby\ncreate_table :users do |t|\n  t.string :email, null: false\n  t.string :password_digest, null: false\n  t.integer :token_version, null: false, default: 0\n  t.index :email, unique: true\n  t.index [:id, :token_version], unique: true\nend\n```\n\nYour model should look like this:\n\n```ruby\nclass User \u003c ApplicationRecord\n  include TinyAuth::Model\nend\n```\n\n#### `#generate_token(purpose: :access, expires_in: 24.hours)`\n\nGenerate a token. The token is generated from the user's `id` and their `token_version`.\n\nIf the `token_version` changes, all previously issued tokens will be revoked. Anytime the\nuser's password changes, this will happen automatically.\n\n```ruby\nirb\u003e user.generate_token\n\"eyJfcmFpbHMiOnsibWVzc2FnZSI6IkJ...\"\n\nirb\u003e user.generate_token(purpose: :reset, expires_in: 1.hour)\n\"eyJfcmFpbHMiOnsibWVzc2FnZSI6IkJ...\"\n```\n\n#### `#invalidate_tokens`\n\nIncrements the `#token_version`, but does not apply the change to the database.\n\n#### `#invalidate_tokens!`\n\nIncrements the `#token_version` and applies the change to the database.\n\n#### `.find_by_email(email)`\n\nFind a user by their email address. The query will disregard casing.\n\n```ruby\nirb\u003e User.find_by_email(\"user@example.com\")\n#\u003cUser id: 1, email: \"user@example.com\"\u003e\n```\n\n#### `.find_by_credentials(email, password)`\n\nFind a user by their email, then check that the password matches.\n\nIf the email doesn't exist, `nil` will be returned. If the password doesn't match, `nil` will be returned.\n\n```ruby\nirb\u003e User.find_by_credentials(\"user@example.com\", \"testing123\")\n#\u003cUser id: 1, email: \"user@example.com\"\u003e\n\nirb\u003e User.find_by_credentials(\"user@example.com\", \"\")\nnil\n\nirb\u003e User.find_by_credentials(\"\", \"\")\nnil\n```\n\n#### `.find_by_token(token, purpose: :access)`\n\nFind a user by their token. If the user can't be found, `nil` will be returned.\n\n```ruby\nirb\u003e User.find_by_token(token)\n#\u003cUser id: 1, email: \"user@example.com\"\u003e\n\nirb\u003e User.find_by_token(reset_token, purpose: :reset)\n#\u003cUser id: 1, email: \"user@example.com\"\u003e\n\nirb\u003e User.find_by_token(\"\")\nnil\n```\n\n### `TinyAuth::Controller`\n\n```ruby\nclass ApplicationController \u003c ActionController::Base\n  include TinyAuth::Controller.new(model: User)\nend\n```\n\nThe example above would generate the following methods based on the model's name:\n\n#### `#authenticate_user`\n\nThis method should be called in a `before_action`. If an `Authorization` header is found, it will attempt to locate a user.\n\n#### `#current_user`\n\nAn accessor that can be used to obtain access to the authenticated user after calling `authenticate_user`.\n\n#### `#user_signed_in?`\n\nA convenience method to determine if a user is signed in.\n\n## Contributing\n\nBug reports and pull requests are welcome on GitHub at https://github.com/rzane/tiny_auth. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.\n\n## License\n\nThe gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).\n\n## Code of Conduct\n\nEveryone interacting in the TinyAuth project’s codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/rzane/tiny_auth/blob/master/CODE_OF_CONDUCT.md).\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frzane%2Ftiny_auth","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Frzane%2Ftiny_auth","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frzane%2Ftiny_auth/lists"}