@@ -21,14 +21,8 @@ this is not yet the case.
21
21
1) Configure the Access Token Authenticator
22
22
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
23
23
24
- The access token authenticator can be configured using three different options:
25
-
26
- * ``header_token ``: the token is sent through the request header. Usually ``Authorization `` with the ``Bearer `` scheme.
27
- * ``query_token ``: the token is part of the query string. Usually ``access_token ``.
28
- * ``body_token ``: the token is part of the request body during a POST request. Usually ``access_token ``.
29
-
30
- You must configure a ``token_handler `` when enabling this authenticator.
31
- The token handler is a service that is able to load and verify the token (e.g. expiration, digital signature...)
24
+ To use the access token authenticator, you must configure a ``token_handler ``.
25
+ The token handler is a service that is able to load and verify the access token (e.g. expiration, digital signature...)
32
26
and return the associated user identifier.
33
27
34
28
.. configuration-block ::
@@ -42,16 +36,10 @@ and return the associated user identifier.
42
36
header_token :
43
37
token_handler : App\Security\AccessTokenHandler
44
38
45
- 2) Create your Access Token Handler
46
- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
47
-
48
- Now that the authenticator is able to check the access tokens, you must
49
- create your access token handler.
50
-
51
39
This handler shall implement the interface
52
40
:class: `Symfony\\ Component\\ Security\\ Http\\ Authenticator\\ AccessTokenHandlerInterface `.
53
41
In the following example, the handler will retrieve the token from a database
54
- using a fictive Doctrine repository.
42
+ using a fictive repository.
55
43
56
44
.. configuration-block ::
57
45
@@ -101,13 +89,54 @@ where participating browsers do not have access to the "Authorization" request h
101
89
102
90
In other words: ``query_token `` and ``body_token` authenticators are not recommended.
103
91
104
- Customizing the Authenticators
105
- ------------------------------
92
+ Customizing the Authenticator
93
+ -----------------------------
94
+
95
+ 1) Access Token Extractors
96
+
97
+ By default, the access token is read from the request header parameter ``Authorization `` with the scheme `Bearer``.
98
+ You can change the behavior and send the access token through different ways.
99
+
100
+ This authenticator provides services able to extract the access token as per the RFC6750:
101
+
102
+ - ``security.access_token_extractor.header ``: the token is sent through the request header. Usually ``Authorization `` with the ``Bearer `` scheme.
103
+ - ``security.access_token_extractor.query_string ``: the token is part of the query string. Usually ``access_token ``.
104
+ - ``security.access_token_extractor.request_body ``: the token is part of the request body during a POST request. Usually ``access_token ``.
105
+
106
+ You can also create a custom extractor. The class shall implement the interface
107
+ :class: `Symfony\\ Component\\ Security\\ Http\\ Authenticator\\ AccessToken\\ AccessTokenExtractorInterface `.
108
+
109
+ .. configuration-block ::
110
+
111
+ .. code-block :: yaml
112
+
113
+ # config/packages/security.yaml
114
+ security :
115
+ firewalls :
116
+ main :
117
+ header_token :
118
+ token_handler : App\Security\AccessTokenHandler
119
+ token_extractors : ' my_custom_access_token_extractor'
120
+
121
+ It is possible to set multiple extractors.
122
+ In this case, the order is important: the first in the list is called first.
106
123
124
+ .. configuration-block ::
107
125
126
+ .. code-block :: yaml
127
+
128
+ # config/packages/security.yaml
129
+ security :
130
+ firewalls :
131
+ main :
132
+ header_token :
133
+ token_handler : App\Security\AccessTokenHandler
134
+ token_extractors :
135
+ - ' security.access_token_extractor.header'
136
+ - ' security.access_token_extractor.request_body'
137
+ - ' security.access_token_extractor.query_string'
108
138
109
- Customizing the Success Handler
110
- -------------------------------
139
+ 2) Customizing the Success Handler
111
140
112
141
Sometimes, the default success handling does not fit your use-case (e.g.
113
142
when you need to generate and return additional response header parameters).
0 commit comments