Skip to content

Commit dfc63bb

Browse files
[LoginLink] Add technical details
1 parent dd459c2 commit dfc63bb

File tree

1 file changed

+25
-2
lines changed

1 file changed

+25
-2
lines changed

security/login_link.rst

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -111,9 +111,9 @@ intercept requests to this route:
111111
throw new \LogicException('This code should never be reached');
112112
}
113113
}
114-
114+
115115
.. code-block:: php-attributes
116-
116+
117117
// src/Controller/SecurityController.php
118118
namespace App\Controller;
119119
@@ -428,6 +428,12 @@ The signed URL contains 3 parameters:
428428
properties. Whenever these change, the hash changes and previous login
429429
links are invalidated.
430430

431+
For a user that returns ``user@example.com`` on ``$user->getUserIdentifier()``
432+
call, the generated login link looks like this:
433+
434+
.. code-block:: text
435+
http://example.com/login_check?user=user@example.com&expires=1675707377&hash=f0Jbda56Y...A5sUCI~TQF701fwJ...7m2n4A~
436+
431437
You can add more properties to the ``hash`` by using the
432438
``signature_properties`` option:
433439

@@ -673,6 +679,23 @@ user create this POST request (e.g. by clicking a button)::
673679
</form>
674680
{% endblock %}
675681

682+
Hashing Strategy
683+
~~~~~~~~~~~~~~~~
684+
685+
Internally, the :class:`Symfony\\Component\\Security\\Http\\LoginLink\\LoginLinkHandler`
686+
implementation uses the
687+
:class:`Symfony\\Component\\Security\\Core\\Signature\\SignatureHasher` to create the
688+
hash contained in the login link.
689+
690+
This hasher creates a first hash with the expiration
691+
date of the link, the values of the configured signature properties and the
692+
user identifier. The used hashing algorithm is SHA-256.
693+
694+
Once this first hash is processed and encoded in Base64, a new one is created
695+
from the first hash value and the ``kernel.secret`` container parameter. This
696+
allows Symfony to sign this final hash, which is contained in the login URL.
697+
The final hash is also a Base64 encoded SHA-256 hash.
698+
676699
Customizing the Success Handler
677700
-------------------------------
678701

0 commit comments

Comments
 (0)