Commit 242ea1f
committed
bug #252 Unlink cleaned up access tokens from refresh tokens (frankdekker)
This PR was squashed before being merged into the 1.x-dev branch.
Discussion
----------
Unlink cleaned up access tokens from refresh tokens
Fixes issue: #247
Breaking changes: no
Changes `AccessTokenManager::clearExpiredTokens` to:
- Find all access token identifiers that have expired.
- Execute query to unlink these identifiers from possible refresh tokens.
- Thirdly delete the access tokens with those ids.
This order ensures that at no point in time there's a refresh token with an invalid access token reference.
## Testing
There was already an existing unit test testing the above scenario but didn't trigger the issue because the entity manager wasn't cleared (and the test ran against the EntityManager memory instead of the database). As soon as I added the `$em->clear()` to the test the scenario above occurred. As the original object compare doesn't work anymore as the refresh tokens are actually retrieved from the db instead of the entity manager memory, the DateTime values and object references differ. The test now should find all unlinked refresh tokens.
## Technical choices
Looking at the relation between RefreshToken and AccessToken, the relation is defined as `SET TO NULL` when the access token is deleted. However as the access tokens aren't deleted through the EntityManager this `SET TO NULL` is never triggered. An alternative implementation would be to retrieve all the expired AccessTokens and delete them through the EntityManager. However I think performance wise this will not be quick.
Commits
-------
f1b5c20 Unlink cleaned up access tokens from refresh tokensFile tree
2 files changed
+34
-7
lines changed- src/Manager/Doctrine
- tests/Acceptance
2 files changed
+34
-7
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
8 | 8 | | |
9 | 9 | | |
10 | 10 | | |
| 11 | + | |
11 | 12 | | |
12 | 13 | | |
13 | 14 | | |
| |||
50 | 51 | | |
51 | 52 | | |
52 | 53 | | |
53 | | - | |
54 | | - | |
55 | | - | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
56 | 58 | | |
57 | 59 | | |
58 | 60 | | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
59 | 77 | | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
60 | 88 | | |
61 | 89 | | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
123 | 123 | | |
124 | 124 | | |
125 | 125 | | |
126 | | - | |
127 | | - | |
128 | | - | |
129 | | - | |
| 126 | + | |
| 127 | + | |
| 128 | + | |
130 | 129 | | |
131 | 130 | | |
132 | 131 | | |
| |||
0 commit comments