{"id":16750010,"url":"https://github.com/hakobyansen/laravel-usub","last_synced_at":"2025-07-20T00:33:32.427Z","repository":{"id":42945956,"uuid":"166865324","full_name":"hakobyansen/laravel-usub","owner":"hakobyansen","description":"Laravel package for authenticated user substitution to login as another user","archived":false,"fork":false,"pushed_at":"2023-02-02T05:52:01.000Z","size":137,"stargazers_count":1,"open_issues_count":1,"forks_count":1,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-06-17T02:18:07.832Z","etag":null,"topics":["authentication","laravel","php7"],"latest_commit_sha":null,"homepage":"","language":"PHP","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/hakobyansen.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2019-01-21T19:04:11.000Z","updated_at":"2022-01-29T20:40:23.000Z","dependencies_parsed_at":"2023-02-17T14:45:48.611Z","dependency_job_id":null,"html_url":"https://github.com/hakobyansen/laravel-usub","commit_stats":null,"previous_names":[],"tags_count":7,"template":false,"template_full_name":null,"purl":"pkg:github/hakobyansen/laravel-usub","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hakobyansen%2Flaravel-usub","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hakobyansen%2Flaravel-usub/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hakobyansen%2Flaravel-usub/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hakobyansen%2Flaravel-usub/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/hakobyansen","download_url":"https://codeload.github.com/hakobyansen/laravel-usub/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hakobyansen%2Flaravel-usub/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":266048676,"owners_count":23868743,"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","laravel","php7"],"created_at":"2024-10-13T02:26:44.433Z","updated_at":"2025-07-20T00:33:32.403Z","avatar_url":"https://github.com/hakobyansen.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"[![Build Status](https://travis-ci.com/c0d3b0t/laravel-usub.svg?branch=master)](https://travis-ci.com/c0d3b0t/laravel-usub)\n\n# About laravel-usub\nLaravel package for authenticated user substitution to login as other users. You will find this package useful when your client says \"As an admin I want to be authenticated and act as chosen user without typing password, and want to back to my admin dashboard by single click.\".\n\n# Installation\n\n* Install the package using composer - run command `composer require codebot/laravel-usub:0.1.*`\n\n* Publish vendors using `php artisan vendor:publish --tag=laravel-usub` command. \nYou will get published config file **config/usub.php**, \nmiddleware **app/Http/Middleware/UsubSignIn.php**,\ncommand **app/Console/Commands/ClearUsubTokens.php**,\ndirectory **views/vendor/usub** \nand migration to create usub_tokens table.\n\n* Run `php artisan migrate` to create usub_tokens table.\n\n* If auto-discovery doesn't work for you then register service provider by adding \n`Usub\\Core\\UsubServiceProvider::class` to providers in config/app.php file.\n\n* Add the `UsubSignIn` middleware to the `$routeMiddleware` array in the `App\\Http\\Kernel.php` class.\n \n**_You need complete UsubSignIn middleware to implement permissions. For example:_**\n```php\n    public function handle( $request, Closure $next )\n    {\n        if ( !$request-\u003euser()-\u003ehasRole( 'admin' ) )\n        {\n            abort( 401 );\n        }\n\n        return $next( $request );\n    }\n```\n\n## Configuration\n\n*expiration* - Usub token expiration time in minutes. \n \n*length* - Length of generated usub token.\n\n*redirect_to_on_sign_in* - Default URL where user will be redirected on sign in whenever it's not overridden by redirect_to_on_sign_in key in request, e.g. by hidden input field.  \n\n*redirect_to_on_sign_out* - Default URL where user will be redirected on sign out whenever it's not overridden by redirect_to_on_sign_out key in request, e.g. by hidden input field.  \n\n*redirect_to_on_cookie_expiration* - URL where user will be redirected when token cookie expired.\n\n*forget_cookies_on_sign_out* - **Array** of cookie names that will be removed from browser on sign out and usub token expiration.\n\nYou can change the configuration in your .env file if you need to.\n\n```\nUSUB_TOKEN_EXPIRATION=120\nUSUB_TOKEN_LENGTH=100\nUSUB_REDIRECT_TO_ON_SIGN_IN=\"/\"\nUSUB_REDIRECT_TO_ON_SIGN_OUT=\"/\"\nUSUB_REDIRECT_TO_ON_COOKIE_EXPIRATION=\"/\"\n```\n\n## Usage\n\nOnce you have package installed, following routes are registered:  \n* `POST /usub/sign-in` - used to sign up as given user id.    \n  - Fields\n    - **user2** *(required)*  \n    - **redirect_to_on_sign_in** (optional, once set - overrides redirect_to_on_sign_in config variable )  \n    - **redirect_to_on_sign_out** (optional, once set - overrides redirect_to_on_sign_out config variable )  \n      \n* `POST /usub/sign-out` - used to \"sign up back\" to administrator account.  \n  - No field needs to be specified.  \n  \nAn example of html form that can be used to sign in as specific user:  \n```php\n@if( \\Auth::user()-\u003ehasRole('admin') )\n    @include('vendor.usub.partials.sign_in', [\n        'user_id' =\u003e $user-\u003eid,\n        'on_sign_in' =\u003e route('home'),\n        'on_sign_out' =\u003e route('backend.user.index')\n    ])\n@endif\n```\nIf you won't specify `on_sign_in` and `on_sign_out` values, then it will use defaults from the `config/usub.php` config file.  \n\nAn example of html form that can be used to sign out and back to admin dashboard (or whatever page you need):  \n```php\n@if( \\Illuminate\\Support\\Facades\\Cookie::get('usub_token') )\n    \u003cli class=\"nav-item\"\u003e\n        \u003cform action=\"{{ route('usub.sign_out') }}\" method=\"post\"\u003e\n            @csrf\n            \u003cbutton type=\"submit\" class=\"btn btn-primary\"\u003eBack to Admin\u003c/button\u003e\n        \u003c/form\u003e\n    \u003c/li\u003e\n@endif\n```\n\n## Cleanup\n\nTo delete expired tokens from the `usub_tokens` database table, you can use `php artisan usub:clear` command.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fhakobyansen%2Flaravel-usub","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fhakobyansen%2Flaravel-usub","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fhakobyansen%2Flaravel-usub/lists"}