Skip to content
This repository was archived by the owner on Dec 2, 2021. It is now read-only.

Commit 613dcb9

Browse files
committed
Extend API docs
1 parent beb7aca commit 613dcb9

File tree

1 file changed

+26
-4
lines changed

1 file changed

+26
-4
lines changed

Resources/doc/api.md

Lines changed: 26 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,13 @@ To make two-factor authentication work in an API, your **API has to be stateful*
1010
session which is passed by the client on every call. The session is necessary for two-factor authentication to store the
1111
state of the login - if the user has already completed two-factor authentication or not.
1212

13+
If you use a custom authenticator (you may have followed Symfony's guide
14+
[Custom Authentication System with Guard (API Token Example)](https://symfony.com/doc/current/security/guard_authentication.html)),
15+
please make sure your authenticator doesn't authenticate on every request, but only when the
16+
authentication route is called. For an example, have a look at the
17+
[Avoid Authenticating the Browser on Every Request](https://symfony.com/doc/current/security/guard_authentication.html#avoid-authenticating-the-browser-on-every-request)
18+
section in the Symfony guide.
19+
1320
## Setup
1421

1522
ℹ️ For simplicity of this guide, it is assumed that you're building a JSON API and you're using the `json_login`
@@ -23,6 +30,21 @@ You need to implement 4 classes:
2330
3) A custom success handler for the two-factor authentication
2431
4) A custom failure handler for the two-factor authentication
2532

33+
### Configuration
34+
35+
Please make sure the following configuration options are set on your firewall:
36+
37+
```
38+
# config/packages/security.yaml
39+
security:
40+
firewalls:
41+
your_firewall_name:
42+
# ...
43+
two_factor:
44+
prepare_on_login: true
45+
prepare_on_access_denied: true
46+
```
47+
2648
### 1) Response on login
2749

2850
This first response is returned after the user logged in. Without two-factor authentication, it would either return
@@ -74,7 +96,7 @@ security:
7496
7597
### 2) Response to require two-factor authentication
7698
77-
Configure a response that is returned when the user requests a path, but it is not accessible (yet), because the user
99+
You need a response that is returned when the user requests a path, but it is not accessible (yet), because the user
78100
has to complete two-factor authentication first. This could be the same as your "access denied" response.
79101
80102
Create a class which implements `Scheb\TwoFactorBundle\Security\Http\Authentication\AuthenticationRequiredHandlerInterface`
@@ -114,8 +136,8 @@ security:
114136

115137
### 3) Response when two-factor authentication was successful
116138

117-
Configure a response that is returned when two-factor authentication was completed successfully and the user is now
118-
fully authentication. Implement another success handler for it:
139+
You need a response that is returned when two-factor authentication was completed successfully and the user is now
140+
fully authenticated. Implement another success handler for it:
119141

120142
```php
121143
<?php
@@ -151,7 +173,7 @@ security:
151173

152174
### 4) Response when two-factor authentication failed
153175

154-
Configure a response that is returned when two-factor authentication was tried, but authentication failed for some
176+
You need a response that is returned when two-factor authentication was tried, but authentication failed for some
155177
reason. Implement a failure handler for it:
156178

157179
```php

0 commit comments

Comments
 (0)