{"action":"created","issue":{"url":"https://api.github.com/repos/thephpleague/oauth2-server/issues/785","repository_url":"https://api.github.com/repos/thephpleague/oauth2-server","labels_url":"https://api.github.com/repos/thephpleague/oauth2-server/issues/785/labels{/name}","comments_url":"https://api.github.com/repos/thephpleague/oauth2-server/issues/785/comments","events_url":"https://api.github.com/repos/thephpleague/oauth2-server/issues/785/events","html_url":"https://github.com/thephpleague/oauth2-server/issues/785","id":259294731,"number":785,"title":"RefreshTokenGrant - Revoking old tokens doesn't respect foreign keys.","user":{"login":"LuisMejiaF","id":3083715,"avatar_url":"https://avatars2.githubusercontent.com/u/3083715?v=4","gravatar_id":"","url":"https://api.github.com/users/LuisMejiaF","html_url":"https://github.com/LuisMejiaF","followers_url":"https://api.github.com/users/LuisMejiaF/followers","following_url":"https://api.github.com/users/LuisMejiaF/following{/other_user}","gists_url":"https://api.github.com/users/LuisMejiaF/gists{/gist_id}","starred_url":"https://api.github.com/users/LuisMejiaF/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/LuisMejiaF/subscriptions","organizations_url":"https://api.github.com/users/LuisMejiaF/orgs","repos_url":"https://api.github.com/users/LuisMejiaF/repos","events_url":"https://api.github.com/users/LuisMejiaF/events{/privacy}","received_events_url":"https://api.github.com/users/LuisMejiaF/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":0,"created_at":"2017-09-20T20:39:36Z","updated_at":"2017-09-24T16:50:24Z","closed_at":null,"author_association":"NONE","body":"I have my own MySQL Scheme to persist tokens. Two of the tables, are the ones that store the accessTokens and the refreshTokens.\r\n\r\nCorrect me if I'm wrong, but I think the relationship between both tables should be:\r\n**accessToken** --has-one-> **refreshToken**\r\n-- OR --\r\n**refreshToken** --belongs-to-> **accessToken** \r\n\r\nThat means that the accessToken record should be deleted before the refreshToken, right?\r\nThe problem is, that the `RefreshTokenGrant` class, [tries to delete](https://github.com/thephpleague/oauth2-server/blob/master/src/Grant/RefreshTokenGrant.php#L73) the accessToken first, throwing a `Integrity constraint violation: 1451 Cannot delete or update a parent row`.\r\n\r\nThe current code is this:\r\n```php\r\n// Expire old tokens\r\n$this->accessTokenRepository->revokeAccessToken($oldRefreshToken['access_token_id']);\r\n$this->refreshTokenRepository->revokeRefreshToken($oldRefreshToken['refresh_token_id']);\r\n```\r\nBut should be:\r\n```php\r\n// Expire old tokens\r\n$this->refreshTokenRepository->revokeRefreshToken($oldRefreshToken['refresh_token_id']);\r\n$this->accessTokenRepository->revokeAccessToken($oldRefreshToken['access_token_id']);\r\n```\r\n"},"comment":{"url":"https://api.github.com/repos/thephpleague/oauth2-server/issues/comments/331723021","html_url":"https://github.com/thephpleague/oauth2-server/issues/785#issuecomment-331723021","issue_url":"https://api.github.com/repos/thephpleague/oauth2-server/issues/785","id":331723021,"user":{"login":"sgomez","id":580701,"avatar_url":"https://avatars1.githubusercontent.com/u/580701?v=4","gravatar_id":"","url":"https://api.github.com/users/sgomez","html_url":"https://github.com/sgomez","followers_url":"https://api.github.com/users/sgomez/followers","following_url":"https://api.github.com/users/sgomez/following{/other_user}","gists_url":"https://api.github.com/users/sgomez/gists{/gist_id}","starred_url":"https://api.github.com/users/sgomez/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/sgomez/subscriptions","organizations_url":"https://api.github.com/users/sgomez/orgs","repos_url":"https://api.github.com/users/sgomez/repos","events_url":"https://api.github.com/users/sgomez/events{/privacy}","received_events_url":"https://api.github.com/users/sgomez/received_events","type":"User","site_admin":false},"created_at":"2017-09-24T16:50:24Z","updated_at":"2017-09-24T16:50:24Z","author_association":"NONE","body":"You can configure your schema to do an 'ON DELETE CASCADE' or 'ON DELETE SET NULL'."}}
{"actor":{"display_login":"sgomez"}}