Download the PHP package agednerd/laravel-masquerade without Composer

On this page you can find all versions of the php package agednerd/laravel-masquerade. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.

FAQ

After the download, you have to make one include require_once('vendor/autoload.php');. After that you have to import the classes with use statements.

Example:
If you use only one package a project is not needed. But if you use more then one package, without a project it is not possible to import the classes with use statements.

In general, it is recommended to use always a project to download your libraries. In an application normally there is more than one library needed.
Some PHP packages are not free to download and because of that hosted in private repositories. In this case some credentials are needed to access such packages. Please use the auth.json textarea to insert credentials, if a package is coming from a private repository. You can look here for more information.

  • Some hosting areas are not accessible by a terminal or SSH. Then it is not possible to use Composer.
  • To use Composer is sometimes complicated. Especially for beginners.
  • Composer needs much resources. Sometimes they are not available on a simple webspace.
  • If you are using private repositories you don't need to share your credentials. You can set up everything on our site and then you provide a simple download link to your team member.
  • Simplify your Composer build process. Use our own command line tool to download the vendor folder as binary. This makes your build process faster and you don't need to expose your credentials for private repositories.
Please rate this library. Is it a good library?

Informations about the package laravel-masquerade

Laravel Masquerade

Tests

Securely assume another user's identity.

Laravel Masquerade provides secure, nested, remembered, and multi-guard user switching for Laravel 13. It uses Laravel's normal session guards and does not replace the framework's authentication driver.

Features

Requirements

Sanctum SPA authentication is supported through its underlying web guard. Personal access token masquerades are not synthesized: bearer-token exchange, revocation, and audit behavior should be implemented by an application-specific token broker.

Installation

Install the package after its first stable release is published:

Laravel discovers the service provider and Masquerade facade automatically. Publishing the configuration is optional:

Before a stable tag exists, the development branch can be installed explicitly:

Model setup and authorization

Add Masqueradable to every authenticatable model that can initiate or become the subject of a masquerade:

canMasquerade() returns false by default. canBeMasqueraded() returns true by default. The built-in controller and masqueradeAs() require both checks to pass. Keep authorization decisions on the server; never rely on hiding a button.

Registering routes

Register the route macro in routes/web.php. The web middleware is required for sessions, encrypted cookies, and CSRF protection:

This registers:

Method URI Name Purpose
POST /masquerade/{id}/{guardName?} masquerade.take Start a masquerade
DELETE /masquerade masquerade.leave Leave one level

id must be the value returned by the subject's getAuthIdentifier(). It is not implicit route-model binding.

Starting and leaving

For another target guard, pass its name as the second route parameter:

The optional request fields are:

Model API

The model API evaluates both authorization hooks:

Nested calls add frames to the stack. leaveMasquerade() unwinds only the latest frame.

Manager and facade

Resolve the request-scoped manager when you need stack or guard details:

The auto-discovered facade proxies the same manager:

MasqueradeManager::take() is a low-level transition primitive and does not evaluate model authorization hooks. Prefer $actor->masqueradeAs($subject) or the built-in controller for user-driven actions.

Configuration

The published config/masquerade.php contains:

Key Default Meaning
session_key masquerade.stack Session key containing the nested stack
cookie_key masquerade_stack Encrypted stack-cookie name
default_guard web Default subject guard
remember inherit false, true, or inherit from a remembered source
remember_cookie_minutes 43200 Stack-cookie lifetime in minutes
take_redirect_to / Default redirect after starting
leave_redirect_to / Default redirect after leaving
allow_external_redirects false Whether absolute external redirect URLs are accepted
legacy_get_routes false Enables legacy state-changing GET routes

Keep legacy_get_routes disabled. GET requests should not change authentication state.

Redirects

Redirect values may be relative paths, back, or Laravel route names. Invalid route names and disallowed external URLs safely fall back to /.

Request-specific resolver callbacks can be installed on the current manager instance:

Remembered and nested masquerades

With remember set to inherit, the subject receives a normal Laravel recaller when the source was restored via remember-me or has a remember token. The nested stack is also queued in an encrypted, HTTP-only, SameSite=Lax cookie.

Cookie recovery occurs only when Laravel's recaller restores the same subject represented by the top stack frame. Clearing or leaving the final frame removes both session and cookie state.

Blade conditions and helpers

Equivalent helpers are available:

Events and audit logging

MasqueradeStarted and MasqueradeEnded expose:

Example listener:

Protecting sensitive routes

Apply masquerade.protect to billing, credentials, destructive operations, or other sensitive routes. It returns HTTP 403 while a masquerade is active:

Recommended safeguards:

Local development

Use a Composer path repository before the package is available on Packagist:

Then run:

Testing

The CI matrix tests PHP 8.3, 8.4, and 8.5 against the lowest and current stable Laravel 13 dependency sets.

Maintainer release checklist

  1. Update CHANGELOG.md, run composer validate --strict, and run the test suite.
  2. Commit and push the release-ready source.
  3. Create and push a semantic version tag, for example:

  4. The Release GitHub Actions workflow validates the full PHP/dependency matrix, confirms that the changelog contains a dated heading matching the tag, and creates the GitHub Release with generated notes. A v1.0.0 tag therefore requires a heading such as ## 1.0.0 - 2026-06-28.
  5. Submit https://github.com/agednerd/laravel-masquerade at Packagist.
  6. Connect Packagist to GitHub or configure its webhook so pushes and new tags are synchronized automatically.
  7. Verify the release:

Do not add a version field to composer.json; Composer derives release versions from Git tags.

License

Laravel Masquerade is open-source software licensed under the MIT license.


All versions of laravel-masquerade with dependencies

PHP Build Version
Package Version
Requires php Version ^8.3
illuminate/auth Version ^13.0
illuminate/contracts Version ^13.0
illuminate/http Version ^13.0
illuminate/routing Version ^13.0
illuminate/session Version ^13.0
illuminate/support Version ^13.0
illuminate/view Version ^13.0
Composer command for our command line client (download client) This client runs in each environment. You don't need a specific PHP version etc. The first 20 API calls are free. Standard composer command

The package agednerd/laravel-masquerade contains the following files

Loading the files please wait ...