{"id":13506948,"url":"https://github.com/ankane/pretender","last_synced_at":"2025-11-17T14:09:49.632Z","repository":{"id":7261164,"uuid":"8573419","full_name":"ankane/pretender","owner":"ankane","description":"Log in as another user in Rails","archived":false,"fork":false,"pushed_at":"2025-10-22T03:00:50.000Z","size":80,"stargazers_count":1407,"open_issues_count":0,"forks_count":57,"subscribers_count":11,"default_branch":"master","last_synced_at":"2025-11-08T17:11:29.809Z","etag":null,"topics":[],"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/ankane.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,"zenodo":null}},"created_at":"2013-03-05T06:18:38.000Z","updated_at":"2025-11-05T18:51:12.000Z","dependencies_parsed_at":"2024-01-13T20:13:15.099Z","dependency_job_id":"0b2d7716-4379-4328-9c18-7d5faa4ededc","html_url":"https://github.com/ankane/pretender","commit_stats":{"total_commits":125,"total_committers":10,"mean_commits":12.5,"dds":"0.30400000000000005","last_synced_commit":"68e9e136ccd645558457144033e71007168d3d85"},"previous_names":[],"tags_count":14,"template":false,"template_full_name":null,"purl":"pkg:github/ankane/pretender","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ankane%2Fpretender","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ankane%2Fpretender/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ankane%2Fpretender/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ankane%2Fpretender/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/ankane","download_url":"https://codeload.github.com/ankane/pretender/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ankane%2Fpretender/sbom","scorecard":{"id":197158,"data":{"date":"2025-08-11","repo":{"name":"github.com/ankane/pretender","commit":"ee78f72fe9a55e7ebfbda4c17218c408a272f7b4"},"scorecard":{"version":"v5.2.1-40-gf6ed084d","commit":"f6ed084d17c9236477efd66e5b258b9d4cc7b389"},"score":3.4,"checks":[{"name":"Binary-Artifacts","score":10,"reason":"no binaries found in the repo","details":null,"documentation":{"short":"Determines if the project has generated executable (binary) artifacts in the source repository.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#binary-artifacts"}},{"name":"Pinned-Dependencies","score":0,"reason":"dependency not pinned by hash detected -- score normalized to 0","details":["Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/build.yml:19: update your workflow using https://app.stepsecurity.io/secureworkflow/ankane/pretender/build.yml/master?enable=pin","Warn: third-party GitHubAction not pinned by hash: .github/workflows/build.yml:20: update your workflow using https://app.stepsecurity.io/secureworkflow/ankane/pretender/build.yml/master?enable=pin","Info:   0 out of   1 GitHub-owned GitHubAction dependencies pinned","Info:   0 out of   1 third-party GitHubAction dependencies pinned"],"documentation":{"short":"Determines if the project has declared and pinned the dependencies of its build process.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#pinned-dependencies"}},{"name":"Dangerous-Workflow","score":10,"reason":"no dangerous workflow patterns detected","details":null,"documentation":{"short":"Determines if the project's GitHub Action workflows avoid dangerous patterns.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#dangerous-workflow"}},{"name":"Packaging","score":-1,"reason":"packaging workflow not detected","details":["Warn: no GitHub/GitLab publishing workflow detected."],"documentation":{"short":"Determines if the project is published as a package that others can easily download, install, easily update, and uninstall.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#packaging"}},{"name":"Code-Review","score":0,"reason":"Found 0/30 approved changesets -- score normalized to 0","details":null,"documentation":{"short":"Determines if the project requires human code review before pull requests (aka merge requests) are merged.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#code-review"}},{"name":"SAST","score":0,"reason":"no SAST tool detected","details":["Warn: no pull requests merged into dev branch"],"documentation":{"short":"Determines if the project uses static code analysis.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#sast"}},{"name":"Maintained","score":0,"reason":"0 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 0","details":null,"documentation":{"short":"Determines if the project is \"actively maintained\".","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#maintained"}},{"name":"Token-Permissions","score":0,"reason":"detected GitHub workflow tokens with excessive permissions","details":["Warn: no topLevel permission defined: .github/workflows/build.yml:1","Info: no jobLevel write permissions found"],"documentation":{"short":"Determines if the project's workflows follow the principle of least privilege.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#token-permissions"}},{"name":"CII-Best-Practices","score":0,"reason":"no effort to earn an OpenSSF best practices badge detected","details":null,"documentation":{"short":"Determines if the project has an OpenSSF (formerly CII) Best Practices Badge.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#cii-best-practices"}},{"name":"Security-Policy","score":0,"reason":"security policy file not detected","details":["Warn: no security policy file detected","Warn: no security file to analyze","Warn: no security file to analyze","Warn: no security file to analyze"],"documentation":{"short":"Determines if the project has published a security policy.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#security-policy"}},{"name":"Vulnerabilities","score":10,"reason":"0 existing vulnerabilities detected","details":null,"documentation":{"short":"Determines if the project has open, known unfixed vulnerabilities.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#vulnerabilities"}},{"name":"Fuzzing","score":0,"reason":"project is not fuzzed","details":["Warn: no fuzzer integrations found"],"documentation":{"short":"Determines if the project uses fuzzing.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#fuzzing"}},{"name":"License","score":10,"reason":"license file detected","details":["Info: project has a license file: LICENSE.txt:0","Info: FSF or OSI recognized license: MIT License: LICENSE.txt:0"],"documentation":{"short":"Determines if the project has defined a license.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#license"}},{"name":"Signed-Releases","score":-1,"reason":"no releases found","details":null,"documentation":{"short":"Determines if the project cryptographically signs release artifacts.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#signed-releases"}},{"name":"Branch-Protection","score":0,"reason":"branch protection not enabled on development/release branches","details":["Warn: branch protection not enabled for branch 'master'"],"documentation":{"short":"Determines if the default and release branches are protected with GitHub's branch protection settings.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#branch-protection"}}]},"last_synced_at":"2025-08-16T22:01:17.022Z","repository_id":7261164,"created_at":"2025-08-16T22:01:17.022Z","updated_at":"2025-08-16T22:01:17.022Z"},"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":284177651,"owners_count":26960330,"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","status":"online","status_checked_at":"2025-11-13T02:00:06.582Z","response_time":61,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"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":[],"created_at":"2024-08-01T01:01:00.756Z","updated_at":"2025-11-17T14:09:49.614Z","avatar_url":"https://github.com/ankane.png","language":"Ruby","funding_links":[],"categories":["Uncategorized","Ruby","Authentication"],"sub_categories":["Uncategorized"],"readme":"# Pretender\n\nAs an admin, there are times you want to see exactly what another user sees. Meet Pretender.\n\n- Easily switch between users\n- Minimal code changes\n- Plays nicely with Action Cable and auditing tools\n\n:boom: [Rock on](https://www.youtube.com/watch?v=SBjQ9tuuTJQ)\n\nPretender is flexible and lightweight - less than 100 lines of code :-)\n\nWorks with any authentication system - [Devise](https://github.com/plataformatec/devise), [Authlogic](https://github.com/binarylogic/authlogic), and [Sorcery](https://github.com/Sorcery/sorcery) to name a few.\n\n:tangerine: Battle-tested at [Instacart](https://www.instacart.com/opensource)\n\n[![Build Status](https://github.com/ankane/pretender/actions/workflows/build.yml/badge.svg)](https://github.com/ankane/pretender/actions)\n\n## Installation\n\nAdd this line to your application’s Gemfile:\n\n```ruby\ngem \"pretender\"\n```\n\nAnd add this to your `ApplicationController`:\n\n```ruby\nclass ApplicationController \u003c ActionController::Base\n  impersonates :user\nend\n```\n\n## How It Works\n\nSign in as another user with:\n\n```\nimpersonate_user(user)\n```\n\nThe `current_user` method now returns the impersonated user.\n\nYou can access the true user with:\n\n```\ntrue_user\n```\n\nAnd stop impersonating with:\n\n```ruby\nstop_impersonating_user\n```\n\n### Sample Implementation\n\nCreate a controller\n\n```ruby\nclass UsersController \u003c ApplicationController\n  before_action :require_admin! # your authorization method\n\n  def index\n    @users = User.order(:id)\n  end\n\n  def impersonate\n    user = User.find(params[:id])\n    impersonate_user(user)\n    redirect_to root_path\n  end\n\n  def stop_impersonating\n    stop_impersonating_user\n    redirect_to root_path\n  end\nend\n```\n\nAdd routes\n\n```ruby\nresources :users, only: [:index] do\n  post :impersonate, on: :member\n  post :stop_impersonating, on: :collection\nend\n```\n\nCreate an index view\n\n```erb\n\u003cul\u003e\n  \u003c% @users.each do |user| %\u003e\n    \u003cli\u003eSign in as \u003c%= button_to user.name, impersonate_user_path(user), data: {turbo: false} %\u003e\u003c/li\u003e\n  \u003c% end %\u003e\n\u003c/ul\u003e\n```\n\nAnd show when someone is signed in as another user in your application layout\n\n```erb\n\u003c% if current_user != true_user %\u003e\n  You (\u003c%= true_user.name %\u003e) are signed in as \u003c%= current_user.name %\u003e\n  \u003c%= button_to \"Back to admin\", stop_impersonating_users_path, data: {turbo: false} %\u003e\n\u003c% end %\u003e\n```\n\n## Audits\n\nIf you keep audit logs with a library like [Audited](https://github.com/collectiveidea/audited), make sure it uses the **true user**.\n\n```ruby\nAudited.current_user_method = :true_user\n```\n\n## Action Cable\n\nAnd add this to your `ApplicationCable::Connection`:\n\n```ruby\nmodule ApplicationCable\n  class Connection \u003c ActionCable::Connection::Base\n    identified_by :current_user, :true_user\n    impersonates :user\n\n    def connect\n      self.current_user = find_verified_user\n      reject_unauthorized_connection unless current_user\n    end\n\n    private\n\n    def find_verified_user\n      env[\"warden\"].user # for Devise\n    end\n  end\nend\n```\n\nThe `current_user` method now returns the impersonated user in channels.\n\n## Configuration\n\nPretender is super flexible. You can change the names of methods and even impersonate multiple roles at the same time. Here’s the default configuration.\n\n```ruby\nimpersonates :user,\n             method: :current_user,\n             with: -\u003e(id) { User.find_by(id: id) }\n```\n\nMold it to fit your application.\n\n```ruby\nimpersonates :account,\n             method: :authenticated_account,\n             with: -\u003e(id) { EnterpriseAccount.find_by(id: id) }\n```\n\nThis creates three methods:\n\n```ruby\ntrue_account\nimpersonate_account\nstop_impersonating_account\n```\n\n## History\n\nView the [changelog](https://github.com/ankane/pretender/blob/master/CHANGELOG.md)\n\n## Contributing\n\nEveryone is encouraged to help improve this project. Here are a few ways you can help:\n\n- [Report bugs](https://github.com/ankane/pretender/issues)\n- Fix bugs and [submit pull requests](https://github.com/ankane/pretender/pulls)\n- Write, clarify, or fix documentation\n- Suggest or add new features\n\nTo get started with development:\n\n```sh\ngit clone https://github.com/ankane/pretender.git\ncd pretender\nbundle install\nbundle exec rake test\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fankane%2Fpretender","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fankane%2Fpretender","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fankane%2Fpretender/lists"}