{"action":"created","issue":{"url":"https://api.github.com/repos/cloudfoundry/uaa/issues/223","labels_url":"https://api.github.com/repos/cloudfoundry/uaa/issues/223/labels{/name}","comments_url":"https://api.github.com/repos/cloudfoundry/uaa/issues/223/comments","events_url":"https://api.github.com/repos/cloudfoundry/uaa/issues/223/events","html_url":"https://github.com/cloudfoundry/uaa/issues/223","id":106394747,"number":223,"title":"Token in oauth_code is being deleted immediately","user":{"login":"amhuber","id":3358001,"avatar_url":"https://avatars.githubusercontent.com/u/3358001?v=3","gravatar_id":"","url":"https://api.github.com/users/amhuber","html_url":"https://github.com/amhuber","followers_url":"https://api.github.com/users/amhuber/followers","following_url":"https://api.github.com/users/amhuber/following{/other_user}","gists_url":"https://api.github.com/users/amhuber/gists{/gist_id}","starred_url":"https://api.github.com/users/amhuber/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/amhuber/subscriptions","organizations_url":"https://api.github.com/users/amhuber/orgs","repos_url":"https://api.github.com/users/amhuber/repos","events_url":"https://api.github.com/users/amhuber/events{/privacy}","received_events_url":"https://api.github.com/users/amhuber/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":14,"created_at":"2015-09-14T17:52:44Z","updated_at":"2015-09-30T20:38:48Z","closed_at":null,"body":"I've updated a test environment to CF v215 and I'm having trouble using the AdminUI tool from the incubator.  When I try to login to the UI I get a scope error and if I look in the UAA logs I see this error:\r\n\r\n     Invalid authorization code: KnHCWu\r\n\r\nInteresting, that appears immediately after this log entry:\r\n\r\n     UaaTokenStore: [oauth_code] Removed 1 old entries.\r\n\r\nLooking at the SQL queries, I can see that it's trying to delete any token that was created 5 minutes before current time (login occurred at 17:40 UTC):\r\n\r\n     delete from oauth_code where.created < '2015-09-14.17:35:06.356'\r\n\r\nLooking at this line of code, shouldn't the query be for \"current time PLUS expiration\", and not MINUS?\r\n\r\nhttps://github.com/cloudfoundry/uaa/blob/master/common/src/main/java/org/cloudfoundry/identity/uaa/oauth/token/UaaTokenStore.java#L212"},"comment":{"url":"https://api.github.com/repos/cloudfoundry/uaa/issues/comments/144536349","html_url":"https://github.com/cloudfoundry/uaa/issues/223#issuecomment-144536349","issue_url":"https://api.github.com/repos/cloudfoundry/uaa/issues/223","id":144536349,"user":{"login":"fhanik","id":607429,"avatar_url":"https://avatars.githubusercontent.com/u/607429?v=3","gravatar_id":"","url":"https://api.github.com/users/fhanik","html_url":"https://github.com/fhanik","followers_url":"https://api.github.com/users/fhanik/followers","following_url":"https://api.github.com/users/fhanik/following{/other_user}","gists_url":"https://api.github.com/users/fhanik/gists{/gist_id}","starred_url":"https://api.github.com/users/fhanik/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/fhanik/subscriptions","organizations_url":"https://api.github.com/users/fhanik/orgs","repos_url":"https://api.github.com/users/fhanik/repos","events_url":"https://api.github.com/users/fhanik/events{/privacy}","received_events_url":"https://api.github.com/users/fhanik/received_events","type":"User","site_admin":false},"created_at":"2015-09-30T20:38:48Z","updated_at":"2015-09-30T20:38:48Z","body":"The `oauth_code` table underwent an improvement. The old table wasn't deleting non claimed codes and the table grew forever.\r\nSo we added an `expiresat` column so that we could expire new entries. This column represents epoch time in milliseconds, so it wont matter what timezone UAA or DB is. \r\n\r\nWe added in a `cleanup` for legacy entries that were marked with `expiresat=0` and used the `created` timestamp. Unfortunately the bug is that the cleanup statement didnt have `where expiresat=0` in it, or this issue would have never happened.\r\n\r\nGoing forward there should be zero entries with `expiresat=0` as those have long been removed. Should there still be some left, they will be deleted after sitting there for 2-3 days depending on timezone.\r\n"}}