WARNING: THIS SITE IS A MIRROR OF GITHUB.COM / IT CANNOT LOGIN OR REGISTER ACCOUNTS / THE CONTENTS ARE PROVIDED AS-IS / THIS SITE ASSUMES NO RESPONSIBILITY FOR ANY DISPLAYED CONTENT OR LINKS / IF YOU FOUND SOMETHING MAY NOT GOOD FOR EVERYONE, CONTACT ADMIN AT ilovescratch@foxmail.com
You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
if ($accessToken === null || !$accessToken->isValid()) {
98
+
throw new BadCredentialsException('Invalid credentials.');
70
99
}
100
+
101
+
// and return the user identifier from the found token
102
+
return $accessToken->getUserId();
71
103
}
104
+
}
105
+
106
+
The access token authenticator will use the returned user identifier to
107
+
load the user using the :ref:`user provider <security-user-providers>`.
72
108
73
109
.. caution::
74
110
75
-
It is important to check the token is valid.
76
-
For instance, in the example we verify the token has not expired.
77
-
With self-contained access tokens such as JWT, the handler is required to
78
-
verify the digital signature and understand all claims,
79
-
especially ``sub``, ``iat``, ``nbf`` and ``exp``.
111
+
It is important to check the token if is valid. For instance, the
112
+
example above verifies whether the token has not expired. With
113
+
self-contained access tokens such as JWT, the handler is required to
114
+
verify the digital signature and understand all claims, especially
115
+
``sub``, ``iat``, ``nbf`` and ``exp``.
80
116
81
-
Customizing the Authenticator
82
-
-----------------------------
117
+
2) Configure the Token Extractor (Optional)
118
+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
83
119
84
-
1) Access Token Extractors
120
+
The application is now ready to handle incoming tokens. A *token extractor*
121
+
retrieves the token from the request (e.g. a header or request body).
85
122
86
-
By default, the access token is read from the request header parameter ``Authorization`` with the scheme ``Bearer``.
87
-
You can change the behavior and send the access token through different ways.
123
+
By default, the access token is read from the request header parameter
124
+
``Authorization`` with the scheme ``Bearer`` (e.g. ``Authorization: Bearer
125
+
the-token-value``).
88
126
89
-
This authenticator provides services able to extract the access token as per the RFC6750:
127
+
Symfony provides other extractors as per the `RFC6750`_:
90
128
91
-
- ``header`` or ``security.access_token_extractor.header``: the token is sent through the request header. Usually ``Authorization`` with the ``Bearer`` scheme.
92
-
- ``query_string`` or ``security.access_token_extractor.query_string``: the token is part of the query string. Usually ``access_token``.
93
-
- ``request_body`` or ``security.access_token_extractor.request_body``: the token is part of the request body during a POST request. Usually ``access_token``.
129
+
``header`` (default)
130
+
The token is sent through the request header. Usually ``Authorization``
131
+
with the ``Bearer`` scheme.
132
+
``query_string``
133
+
The token is part of the request query string. Usually ``access_token``.
134
+
``request_body``
135
+
The token is part of the request body during a POST request. Usually
136
+
``access_token``.
94
137
95
138
.. caution::
96
139
97
140
Because of the security weaknesses associated with the URI method,
98
-
including the high likelihood that the URL or the request body containing the access token will be logged,
99
-
methods ``query_string`` and ``request_body`` **SHOULD NOT** be used unless it is impossible
100
-
to transport the access token in the request header field.
141
+
including the high likelihood that the URL or the request body
142
+
containing the access token will be logged, methods ``query_string``
143
+
and ``request_body`` **SHOULD NOT** be used unless it is impossible to
144
+
transport the access token in the request header field.
101
145
102
-
Also, you can also create a custom extractor. The class shall implement the interface
146
+
You can also create a custom extractor. The class must implement
0 commit comments