{"id":21155628,"url":"https://github.com/locaweb/cassette","last_synced_at":"2026-03-05T16:03:46.733Z","repository":{"id":29080593,"uuid":"32608744","full_name":"locaweb/cassette","owner":"locaweb","description":"Library to authenticate and validate using CAS servers","archived":false,"fork":false,"pushed_at":"2024-12-09T17:36:53.000Z","size":148,"stargazers_count":16,"open_issues_count":11,"forks_count":15,"subscribers_count":12,"default_branch":"main","last_synced_at":"2025-12-20T00:35:01.833Z","etag":null,"topics":["hacktoberfest"],"latest_commit_sha":null,"homepage":"","language":"Ruby","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":"ageitgey/face_recognition","license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/locaweb.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","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":"2015-03-20T21:46:39.000Z","updated_at":"2025-10-06T08:59:36.000Z","dependencies_parsed_at":"2024-11-20T12:06:34.228Z","dependency_job_id":null,"html_url":"https://github.com/locaweb/cassette","commit_stats":{"total_commits":88,"total_committers":15,"mean_commits":5.866666666666666,"dds":0.5227272727272727,"last_synced_commit":"4e825e2f53aff5fb73c4c1aa22dc8f8498d61652"},"previous_names":[],"tags_count":23,"template":false,"template_full_name":null,"purl":"pkg:github/locaweb/cassette","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/locaweb%2Fcassette","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/locaweb%2Fcassette/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/locaweb%2Fcassette/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/locaweb%2Fcassette/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/locaweb","download_url":"https://codeload.github.com/locaweb/cassette/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/locaweb%2Fcassette/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":30134580,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-03-05T15:35:27.018Z","status":"ssl_error","status_checked_at":"2026-03-05T15:35:23.768Z","response_time":93,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.6:443 state=error: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"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":["hacktoberfest"],"created_at":"2024-11-20T11:24:43.803Z","updated_at":"2026-03-05T16:03:46.710Z","avatar_url":"https://github.com/locaweb.png","language":"Ruby","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Cassette::Client\n\n[![Build Status](https://github.com/locaweb/cassette/actions/workflows/ci.yml/badge.svg)](https://github.com/locaweb/cassette/actions/workflows/ci.yml)\n\n[![Test Coverage](https://codeclimate.com/github/locaweb/cassette/badges/coverage.svg)](https://codeclimate.com/github/locaweb/cassette/coverage)\n\nLibrary to generate and validate STs and TGTs\n\n## Installation\n\nAdd this line to your application's Gemfile:\n\n```ruby\ngem 'cassette'\n```\n\nAnd then execute:\n\n```shell\n$ bundle\n```\n\n## Usage\n\nRequire this library and create an intializer to set its configuration:\n\n```ruby\nCassete.config = OpenStruct.new(\n  username: 'user',\n  password: 'secret',\n  service: 'test-api.example.org',\n  base: 'https://some-cas.example.org',\n  base_authority: 'CASTEST',\n  verify_ssl: true,       # If not defined, the default value will be: false.\n  tls_version: 'TLSv1_2'  # if not defined, the default value will be: 'TLSv1'.\n)\n```\n\nwhere config is an OpenStruct that responds to the methods `base` for the base CAS uri, `username` and `password` if you are authenticating on other systems and `service` and `base_authority` if you are using the authentication filter to authenticate your app.\n\nYou may also set the caching backend using the .backend= module method:\n\n```ruby\nCassette::Cache.backend = ActiveSupport::Cache::MemcacheStorage.new\n```\n\nBy default, `Cassette::Cache` will check if you have `Rails.cache` defined or instantiate a new `ActiveSupport::Cache::MemoryStore`\n\nTo authenticate your Rails app, add to your `ApplicationController` (or any authenticated controller):\n\n```ruby\nclass ApplicationController \u003c ActionController::Base\n  include Cassette::Authentication::Filter\n\n  # ...\nend\n```\n\nYou should also rescue from `Cassette::Errors::Forbidden` with more friendly errors\n\nIf you wish to have actions that skip the authentication filter, add to your controller:\n\n```ruby\nclass SomeController \u003c ApplicationController\n    skip_authentication # [*options]\n\n    # skip_authentication only: \"index\"\nend\n```\n\nWhere options are the same options you can pass to Rails' `skip_before_action` method.\n\nYou also can skip the whole CAS authentication using an environment variable `NOAUTH=true`. The method `current_user` will keep available. This is useful for development environments. **Be careful not to set and/or forget this variable in production environment**.\n\n\n### Overriding the authenticated service\n\nYou can the service being authenticated in a controller (or group of controllers). To do this, override the instance method `authentication_service`:\n\n```ruby\nclass ApiController \u003c ApplicationController\n  def authentication_service\n    \"api.#{super}\"\n\n    # or maybe a hardcoded:\n    # \"api.example.org\"\n\n    # looking like regular RubyCAS, using the url\n    # request.url\n  end\nend\n```\n\n### Accepting multiple services (restricting from a list)\n\nYour config object must respond to `services` and the filter will check your controller `authentication_service` against the list or the configured service.\n\nIn your initializer:\n\n```ruby\nCassete.config = OpenStruct.new(\n  # omitted\n  service: \"example.org\",\n  services: [\"api.example.org\", \"www.example.org\", \"subdomain.example.org\"]\n)\n```\n\nAnd in your controller:\n\n```ruby\nclass ApplicationController \u003c ActionController::Base\n  def authentication_service\n    request.host\n  end\nend\n```\n\nIn this example, only tickets generated for __api.example.org__, __www.example.org__, __subdomain.example.org__ or __example.org__ will be accepted others will raise a `Cassette::Errors::Forbidden`.\n\n### Accepting multiple services (customized)\n\nIf whitelisting services is not enough for your application, you can override the `accepts_authentication_service?` in your controller.\nThis method receives the service and returns a boolean if the service is ok or not.\n\n```ruby\nclass ApplicationController \u003c ActionController::Base\n  def accepts_authentication_service?(service)\n    service.ends_with?('my-domain.com')\n  end\n\n  def authentication_service\n    request.host\n  end\nend\n```\n\n## RubyCAS client helpers\n\n\nIf you are authenticating users with RubyCAS and want role checking, in your rubycas initializer:\n\n```ruby\nrequire \"cassette/rubycas\"\n```\n\nAnd in your `ApplicationController` (or any authenticated controller):\n\n```ruby\nclass SomeController \u003c ApplicationController\n    include Cassette::Rubycas::Helper\n\n    # - Allow only employees:\n    #\n    # before_action :employee_only_filter\n    #\n    # rescue_from Cassette::Errors::NotAnEmployee do\n    #   redirect_to '/403.html'\n    # end\n\n    # - Allow only customers:\n    #\n    # before_action :customer_only_filter\n    #\n    # rescue_from Cassette::Errors::NotACustomer do\n    #   redirect_to '/403.html'\n    # end\nend\n```\n\n### Constraining routes for roles\n\nThis is useful if you want to mount an unauthenticated Rack app (like Resque)\n\nAdd to your `config/routes.rb`:\n\n```ruby\n  mount Resque::Server.new, at: '/resque', constraints: Cassette::Rubycas::RoutingConstraint.new(:admin)\n```\n\nThis will make your /resque route require your `BASEAUTHORITY_ADMIN` role.\n\nYou can also use raw roles:\n\n```ruby\n  mount Resque::Server.new, at: '/resque', constraints: Cassette::Rubycas::RoutingConstraint.new('OTHERAPP_ROLE', raw: true)\n```\n\nAnd your /resque route will require the `OTHERAPP_ROLE` role.\n\n## Instantiating Cassette::Client and Cassette::Authentication\n\nYou can create your own instances of `Cassette::Client` (st/tgt generator) and `Cassette::Authentication` (st validator).\n\nThe constructor accepts a hash with keys (as symbols) for the values of cache, logger, http_client and configuration.\n\nAll values default to the same values used when accessing the class methods directly.\n\nPlease check the constructors or integration specs for details.\n\n## About caching and tests\n\nIt is a good idea to always clear the cache between tests, specially if you're\nusing VCR. You can do it by using the invoking the `#clear` method of the cache\nbackend in use. The following excerpt will clear the cache of the default client\n`Cassette::Client` instance:\n\n```\nCassette::Client.cache.backend.clear\n```\n\n## Contributing\n\n1. Fork it\n2. Create your feature branch (`git checkout -b my-new-feature`)\n3. Commit your changes (`git commit -am 'Added some feature'`)\n4. Push to the branch (`git push origin my-new-feature`)\n5. Create new Pull Request\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flocaweb%2Fcassette","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Flocaweb%2Fcassette","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flocaweb%2Fcassette/lists"}