Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

[Security] Add documentation for programmatic login#17284

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged
wouterj merged 1 commit intosymfony:6.2fromjohnkrovitch:docs/programmatic-login
Oct 1, 2022
Merged
Changes fromall commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 46 additions & 0 deletionssecurity.rst
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -1599,6 +1599,52 @@ and set the ``limiter`` option to its service ID:
;
};

Login Programmatically
----------------------

.. versionadded:: 6.2

The :class:`Symfony\Bundle\SecurityBundle\Security\Security <Symfony\\Bundle\\SecurityBundle\\Security\\Security>`
class was introduced in Symfony 6.2. Prior to 6.2, it was called
``Symfony\Component\Security\Core\Security``.

.. versionadded:: 6.2

The :method:`Symfony\\Bundle\\SecurityBundle\\Security\\Security::login`
method was introduced in Symfony 6.2.

You can log in a user programmatically using the `login()` method of the
:class:`Symfony\\Bundle\\SecurityBundle\\Security\\Security` helper::

// src/Controller/SecurityController.php
namespace App\Controller\SecurityController;

use App\Security\Authenticator\ExampleAuthenticator;
use Symfony\Bundle\SecurityBundle\Security\Security;

class SecurityController
{
public function someAction(Security $security): Response
{
// get the user to be authenticated
$user = ...;

// log the user in on the current firewall
$this->security->login($user);

// if the firewall has more than one authenticator, you must pass it explicitly
// by using the name of built-in authenticators...
$this->security->login($user, 'form_login');
// ...or the service id of custom authenticators
$this->security->login($user, ExampleAuthenticator::class);

// you can also log in on a different firewall
$this->security->login($user, 'form_login', 'other_firewall');

// ... redirect the user to its account page for instance
}
}

.. _security-logging-out:

Logging Out
Expand Down

[8]ページ先頭

©2009-2025 Movatter.jp