{"id":16183699,"url":"https://github.com/launchpadlab/lp_token_auth","last_synced_at":"2026-01-24T00:17:25.672Z","repository":{"id":46676447,"uuid":"81156259","full_name":"LaunchPadLab/lp_token_auth","owner":"LaunchPadLab","description":"Simple token authentication","archived":false,"fork":false,"pushed_at":"2024-02-05T03:50:27.000Z","size":73,"stargazers_count":0,"open_issues_count":4,"forks_count":0,"subscribers_count":19,"default_branch":"master","last_synced_at":"2025-02-28T14:07:34.997Z","etag":null,"topics":["authentication","jwt","rails"],"latest_commit_sha":null,"homepage":null,"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/LaunchPadLab.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.txt","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2017-02-07T02:21:24.000Z","updated_at":"2021-12-23T18:09:10.000Z","dependencies_parsed_at":"2024-02-05T04:47:26.373Z","dependency_job_id":null,"html_url":"https://github.com/LaunchPadLab/lp_token_auth","commit_stats":{"total_commits":112,"total_committers":9,"mean_commits":"12.444444444444445","dds":0.5625,"last_synced_commit":"b5ee18a6e81d2351a0cce4f7316183c84b159645"},"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/LaunchPadLab%2Flp_token_auth","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/LaunchPadLab%2Flp_token_auth/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/LaunchPadLab%2Flp_token_auth/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/LaunchPadLab%2Flp_token_auth/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/LaunchPadLab","download_url":"https://codeload.github.com/LaunchPadLab/lp_token_auth/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":243960434,"owners_count":20375101,"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","jwt","rails"],"created_at":"2024-10-10T07:06:02.947Z","updated_at":"2026-01-24T00:17:23.615Z","avatar_url":"https://github.com/LaunchPadLab.png","language":"Ruby","readme":"[![Documentation](http://img.shields.io/badge/docs-rdoc.info-blue.svg)](http://www.rubydoc.info/github/LaunchPadLab/lp_token_auth)\n[![Build Status](https://travis-ci.org/LaunchPadLab/lp_token_auth.svg?branch=master)](https://travis-ci.org/LaunchPadLab/lp_token_auth)\n[![Test Coverage](https://codeclimate.com/repos/593aabffc759c90269001912/badges/1e40a4f9bc94a46fc508/coverage.svg)](https://codeclimate.com/repos/593aabffc759c90269001912/coverage)\n[![Code Climate](https://codeclimate.com/repos/593aabffc759c90269001912/badges/1e40a4f9bc94a46fc508/gpa.svg)](https://codeclimate.com/repos/593aabffc759c90269001912/feed)\n\n# LP Token Auth\nSimple token authentication logic with JWTs for Rails apps. No baked in routing, just the barebones logic you need to implement token authentication with JWTs.\n\n* [Installation](#installation)\n* [Usage](#usage)\n* [Examples](#examples)\n* [Migration Guide](#migration-guide)\n\n## Installation\nAdd this line to your application's Gemfile:\n\n`gem 'lp_token_auth'`\n\nAnd then execute:\n\n`$ bundle`\n\nOr install it yourself as:\n\n`$ gem install lp_token_auth`\n\n## Usage\n1. Run `bundle exec rails generate lp_token_auth:install` to generate an initializer at `../config/initalizers/lp_token_auth.rb`. See the initializer for more details about what is configurable.\n2. In the most senior controller that you want to authenticate, add `include LpTokenAuth::Controller`. This gives you 4 methods that are available in this and all child controllers:\n  + `login(user)` - Given a valid user, this will generate a JWT and return it. The token should be sent to the client and passed in the 'Authorization' header in all subsequent requests to the server.\n  + `authenticate_request!` - This is a `before_action` to use in your controllers that will extract the token from the header and authenticate it before proceeding. If the resource class that you're using is not the default `User`, you may override the `authenticate_request!` method by creating a custom `before_action`, in which you may pass in the resource class name.\n\n  ```\n    class AuthenticationController \u003c ApplicationController\n      include LpTokenAuth::Controller\n\n      before_action :authenticate_request\n\n      protected\n\n      def authenticate_request\n        authenticate_request!('AdminUser')\n      end\n    end\n  ```\n  + `authenticate_token!(token)` - This is called by `authenticate_request!` but is available to use if you ever need to manually authenticate a token.\n  + `current_user` - This returns the current user identified by `authenticate!`. It is available after logging in the user or authenticating.\n3. All errors will return an instance of `LpTokenAuth::Error`\n\n## Migration Guide\nVersion 2.0 contains breaking changes for LP Token Auth. This migration guide contains instructions for using v2.0. [Migration Guide](https://github.com/LaunchPadLab/lp_token_auth/blob/master/migration-guide.md)\n\n## Examples\n### Controller\n```\nclass AuthenticatingController \u003c ApplicationController\n  include LpTokenAuth::Controller\n\n  before_action :authenticate_request!\n\n  rescue_from LpTokenAuth::Error, with: :unauthorized\n\n  protected\n\n  def unauthorized(error)\n    render json: { data: error.message }, status: :unauthorized\n  end\nend\n```\n\n### Api Request\n```\n// Using fetch api\nconst jwt = '...'\nfetch('localhost:3000/authenticated-route', {\n  headers: {\n    'Authorization': `Bearer ${jwt}`\n    ...\n  }\n  ...\n})\n```\n\n## Development\n+ `git clone git@github.com:LaunchPadLab/lp_token_auth.git`\n+ `bundle install`\n\n### Testing\n+ Run tests with `rake`\n\n## FAQ\n\n### Can I use this without ActiveRecord?\n\nAlmost! There is a slight dependence on the ActiveRecord method `find`, which is used in order to decode a token based on the resource's `id`. The current workaround is to make sure the resource class you're using implements `find`, and has either a column `id` or implements a method called `id`.\n\n## Authenticate away!\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flaunchpadlab%2Flp_token_auth","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Flaunchpadlab%2Flp_token_auth","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flaunchpadlab%2Flp_token_auth/lists"}