{"action":"opened","issue":{"url":"https://api.github.com/repos/jghibiki/mopey/issues/59","labels_url":"https://api.github.com/repos/jghibiki/mopey/issues/59/labels{/name}","comments_url":"https://api.github.com/repos/jghibiki/mopey/issues/59/comments","events_url":"https://api.github.com/repos/jghibiki/mopey/issues/59/events","html_url":"https://github.com/jghibiki/mopey/issues/59","id":102159721,"number":59,"title":"Api token expiration timing issue","user":{"login":"jghibiki","id":6537066,"avatar_url":"https://avatars.githubusercontent.com/u/6537066?v=3","gravatar_id":"","url":"https://api.github.com/users/jghibiki","html_url":"https://github.com/jghibiki","followers_url":"https://api.github.com/users/jghibiki/followers","following_url":"https://api.github.com/users/jghibiki/following{/other_user}","gists_url":"https://api.github.com/users/jghibiki/gists{/gist_id}","starred_url":"https://api.github.com/users/jghibiki/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/jghibiki/subscriptions","organizations_url":"https://api.github.com/users/jghibiki/orgs","repos_url":"https://api.github.com/users/jghibiki/repos","events_url":"https://api.github.com/users/jghibiki/events{/privacy}","received_events_url":"https://api.github.com/users/jghibiki/received_events","type":"User","site_admin":false},"labels":[{"url":"https://api.github.com/repos/jghibiki/mopey/labels/bug","name":"bug","color":"fc2929"},{"url":"https://api.github.com/repos/jghibiki/mopey/labels/Service","name":"Service","color":"fef2c0"}],"state":"open","locked":false,"assignee":{"login":"JPisaBrony","id":3083689,"avatar_url":"https://avatars.githubusercontent.com/u/3083689?v=3","gravatar_id":"","url":"https://api.github.com/users/JPisaBrony","html_url":"https://github.com/JPisaBrony","followers_url":"https://api.github.com/users/JPisaBrony/followers","following_url":"https://api.github.com/users/JPisaBrony/following{/other_user}","gists_url":"https://api.github.com/users/JPisaBrony/gists{/gist_id}","starred_url":"https://api.github.com/users/JPisaBrony/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/JPisaBrony/subscriptions","organizations_url":"https://api.github.com/users/JPisaBrony/orgs","repos_url":"https://api.github.com/users/JPisaBrony/repos","events_url":"https://api.github.com/users/JPisaBrony/events{/privacy}","received_events_url":"https://api.github.com/users/JPisaBrony/received_events","type":"User","site_admin":false},"milestone":null,"comments":0,"created_at":"2015-08-20T15:01:05Z","updated_at":"2015-08-20T15:01:05Z","closed_at":null,"body":"If Service's user token expires after the verify call but before any other api calls, the service will break. Fix this by adding a verify call before any other calls. If the verification fails then relogin and verify again before continuing.\r\n\r\nHere is an example script of how to use a callback structure to wrap api calls in a preCall verification\r\n```python\r\n\r\nuser = None\r\n\r\ndef preCall(callback):\r\n    if(user is not None):\r\n        token = {\"token\": user[\"access_token\"]}\r\n        verify = requests.post(baseUrl + \"/authenticate/verify/admin\", data=json.dumps(token), headers=header)\r\n        verify = verify.json()\r\n        if verify[\"result\"]:\r\n            callback()\r\n        else:\r\n            login()\r\n            preCall(callback)\r\n          \r\ndef login():\r\n    credentials = {\"username\":\"SYSTEM\", \"password\": \"121\"}\r\n    response = requests.post(baseUrl + \"/authenticate\", data=json.dumps(credentials), headers=header)\r\n     return response.json()\r\n\r\n\r\ndef makeApiCall():\r\n    pass #does stuff\r\n\r\nif __name__ == \"__main__\":\r\n    preCall(makeApiCall)\r\n    \r\n```"}}