{"id":18338128,"url":"https://github.com/gr1d99-ke/gr1d99_auth","last_synced_at":"2025-04-09T20:19:48.774Z","repository":{"id":102250571,"uuid":"184874472","full_name":"gr1d99-ke/gr1d99_auth","owner":"gr1d99-ke","description":"A simple JWT authentication gem for Rails API applications","archived":false,"fork":false,"pushed_at":"2023-01-20T15:42:11.000Z","size":31,"stargazers_count":1,"open_issues_count":4,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-04-09T20:19:45.147Z","etag":null,"topics":["api-authentication","jwt","jwt-authentication","jwt-token","rails","rails-api"],"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/gr1d99-ke.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,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2019-05-04T09:16:11.000Z","updated_at":"2020-03-12T20:08:36.000Z","dependencies_parsed_at":null,"dependency_job_id":"61ac1bb8-a8e1-4f2e-a58f-d620b8124887","html_url":"https://github.com/gr1d99-ke/gr1d99_auth","commit_stats":null,"previous_names":[],"tags_count":1,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/gr1d99-ke%2Fgr1d99_auth","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/gr1d99-ke%2Fgr1d99_auth/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/gr1d99-ke%2Fgr1d99_auth/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/gr1d99-ke%2Fgr1d99_auth/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/gr1d99-ke","download_url":"https://codeload.github.com/gr1d99-ke/gr1d99_auth/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248103908,"owners_count":21048246,"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":["api-authentication","jwt","jwt-authentication","jwt-token","rails","rails-api"],"created_at":"2024-11-05T20:13:15.001Z","updated_at":"2025-04-09T20:19:48.751Z","avatar_url":"https://github.com/gr1d99-ke.png","language":"Ruby","readme":"# Gr1d99Auth\n\nA simple JWT authentication gem for a Ruby on Rails API only application\n\n## Installation\n\nAdd this line to your application's Gemfile:\n\n```ruby\ngem 'gr1d99_auth'\n```\n\nAnd then execute:\n\n    $ bundle\n\nOr install it yourself as:\n\n    $ gem install gr1d99_auth\n\n## Usage\n\n### Rails\n1. Add `gem 'gr1d99_auth'` to your gemfile\n2. Create a file named `gr1d99_auth.rb` in **config/initializers** directory and add required configurations.\n\n   It is worth noting that `gr1d99_auth` gem offers minimal configurations to enable the gem to work correctly.\n   \n   These configurations are:\n   1. **jwt_key** - this is just a random string that will be used to encode/decode jwt\n   2. **jwt_verify** - value can either be **true** or **false**, this specifies whether the jwt should be verified during decoding.\n   3. **jwt_algorithm** - specify the algorithm that should be used, currently the tested algorithms and verified that they work correctly is `HS512` and `HS256`, you are highly recommended to use any of them.\n   4. **jwt_exp** - specify the time in seconds that the token should be valid\n   5. **time_zone** - this ensures that the `jwt_exp` is set appropriately.\n   \n   example:\n   in **config/initializers/gr1d99_auth.rb** you would typically have this setup.\n   \n   ```ruby\n   Gr1d99Auth.configure do |config|\n     config.jwt_key = \"my-jwt-key\"\n     config.jwt_verify = true\n     config.jwt_algorithm = 'HS512'\n     config.jwt_exp = 3600\n     config.time_zone = \"Africa/Nairobi\"\n   end\n   ```\n3. In your controller, typically `authentication_controller.rb`, you would encode your payload by\n   ```ruby\n   payload = { id: user.id, email: user.email, roles: user.roles.pluck(:name) }\n   Gr1d99Auth::JWT.encode(payload)\n   ```\n4. To decode token\n   ```ruby\n   token = response.headers[\"HTTP_X_ACCESS_TOKEN\"]\n   Gr1d99Auth::JWT.decode(token)\n   ```\n   \n5. You should also handle errors raised during decoding, these errors are.\n   1. `JWT::DecodeError`\n   2. `JWT::VerificationError`\n   3. `JWT::IncorrectAlgorithm`\n\n## Development\n\nAfter checking out the repo, run `bin/setup` to install dependencies. Then, run `rake test` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.\n\nTo install this gem onto your local machine, run `bundle exec rake install`. 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](https://rubygems.org).\n\n## Contributing\n\nBug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/gr1d99_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 Gr1d99Auth project’s codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/[USERNAME]/gr1d99_auth/blob/master/CODE_OF_CONDUCT.md).\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgr1d99-ke%2Fgr1d99_auth","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fgr1d99-ke%2Fgr1d99_auth","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgr1d99-ke%2Fgr1d99_auth/lists"}