e-mission / cordova-server-communication Goto Github PK
View Code? Open in Web Editor NEWWrappers for native code to make authenticated calls to the server
License: BSD 3-Clause "New" or "Revised" License
Wrappers for native code to make authenticated calls to the server
License: BSD 3-Clause "New" or "Revised" License
When run in the background, the GTM Auth code returns expired tokens even in the auth callback.
Here's a sample set of logs from xcode while leaving the phone plugged in overnight.
First, we get callbacks from (the previous set of) failed refreshes. But these tokens are identical to the unrefreshed tokens and are still expired.
2016-03-01 04:00:17.277 emission[643:318185] Refresh completion block called, refreshed token is GTMOAuth2Authentication 0x158273e30: {accessToken="ya29.mAJbeo7McSGashSMyo-mqgYwD4xK142EUjKH81Voc2UZ5cM7nNSV9HNQ5sbICUft-Ys", refreshToken="1/nePqCavtbE8WRQUT45XCn-sFYaCMHQdSMBVB9kMqGzY", expirationDate="2016-03-01 08:00:18 +0000"}2016-03-01 04:00:17.293 emission[643:318185] Auth token GTMOAuth2Authentication 0x158273e30: {accessToken="ya29.mAJbeo7McSGashSMyo-mqgYwD4xK142EUjKH81Voc2UZ5cM7nNSV9HNQ5sbICUft-Ys", refreshToken="1/nePqCavtbE8WRQUT45XCn-sFYaCMHQdSMBVB9kMqGzY", expirationDate="2016-03-01 08:00:18 +0000"} still expired after first refresh attempt (expiry date = 2016-03-01 08:00:18 +0000, now = 2016-03-01 12:00:17 +0000), notifying user2016-03-01 04:00:17.295 emission[643:318225] CFNetwork SSLHandshake failed (-9810)2016-03-01 04:00:17.298 emission[643:318225] NSURLSession/NSURLConnection HTTP load failed (kCFStreamErrorDomainSSL, -9810)2016-03-01 04:00:17.311 emission[643:318185] Error Error Domain=e-mission-domain Code=-100 "Refresh token still expired" UserInfo={NSLocalizedRecoverySuggestion=Sign out and Sign in again., NSLocalizedDescription=Refresh token still expired, NSLocalizedFailureReason=Unknown.} while refreshing token in background2016-03-01 04:00:17.328 emission[643:318185] Refresh completion block called, refreshed token is GTMOAuth2Authentication 0x158273e30: {accessToken="ya29.mAJbeo7McSGashSMyo-mqgYwD4xK142EUjKH81Voc2UZ5cM7nNSV9HNQ5sbICUft-Ys", refreshToken="1/nePqCavtbE8WRQUT45XCn-sFYaCMHQdSMBVB9kMqGzY", expirationDate="2016-03-01 08:00:18 +0000"}2016-03-01 04:00:17.342 emission[643:318185] Auth token GTMOAuth2Authentication 0x158273e30: {accessToken="ya29.mAJbeo7McSGashSMyo-mqgYwD4xK142EUjKH81Voc2UZ5cM7nNSV9HNQ5sbICUft-Ys", refreshToken="1/nePqCavtbE8WRQUT45XCn-sFYaCMHQdSMBVB9kMqGzY", expirationDate="2016-03-01 08:00:18 +0000"} still expired after first refresh attempt (expiry date = 2016-03-01 08:00:18 +0000, now = 2016-03-01 12:00:17 +0000), notifying user2016-03-01 04:00:17.358 emission[643:318185] received response for server_to_phone2016-03-01 04:00:17.378 emission[643:318185] Got error Error Domain=e-mission-domain Code=-100 "Refresh token still expired" UserInfo={NSLocalizedRecoverySuggestion=Sign out and Sign in again., NSLocalizedDescription=Refresh token still expired, NSLocalizedFailureReason=Unknown.} while retrieving data
2016-03-01 04:00:17.395 emission[643:318185] Please sign in
So all the remote calls fail
2016-03-01 04:00:17.342 emission[643:318185] Auth token GTMOAuth2Authentication 0x158273e30: {accessToken="ya29.mAJbeo7McSGashSMyo-mqgYwD4xK142EUjKH81Voc2UZ5cM7nNSV9HNQ5sbICUft-Ys", refreshToken="1/nePqCavtbE8WRQUT45XCn-sFYaCMHQdSMBVB9kMqGzY", expirationDate="2016-03-01 08:00:18 +0000"} still expired after first refresh attempt (expiry date = 2016-03-01 08:00:18 +0000, now = 2016-03-01 12:00:17 +0000), notifying user
2016-03-01 04:00:17.358 emission[643:318185] received response for server_to_phone2016-03-01 04:00:17.378 emission[643:318185] Got error Error Domain=e-mission-domain Code=-100 "Refresh token still expired" UserInfo={NSLocalizedRecoverySuggestion=Sign out and Sign in again., NSLocalizedDescription=Refresh token still expired, NSLocalizedFailureReason=Unknown.} while retrieving data
and then we generate the NOP transition for the previous push
2016-03-01 04:00:17.583 emission[643:318185] Received notification T_NOP while processing silent push notification
2016-03-01 04:00:17.622 emission[643:318185] Remote push state machine ignored the silent push, fetch result = new data
Now, we check whether the tokens are valid - they are not, so we start refreshing them again.
2016-03-01 04:00:18.184 emission[643:318185] About to check whether a trip has ended
2016-03-01 04:00:18.192 emission[643:318185] currAuth != null, nothing to do
2016-03-01 04:00:18.218 emission[643:318185] currAuth = GTMOAuth2Authentication 0x158273e30: {accessToken="ya29.mAJbeo7McSGashSMyo-mqgYwD4xK142EUjKH81Voc2UZ5cM7nNSV9HNQ5sbICUft-Ys", refreshToken="1/nePqCavtbE8WRQUT45XCn-sFYaCMHQdSMBVB9kMqGzY", expirationDate="2016-03-01 08:00:18 +0000"}, canAuthorize = YES, expiresIn = 3600, expirationDate = 2016-03-01 08:00:18 +0000, expired = YES
2016-03-01 04:00:18.232 emission[643:318185] token has expired, refreshing it
2016-03-01 04:00:18.273 emission[643:318185] beginning refresh of token GTMOAuth2Authentication 0x158273e30: {accessToken="ya29.mAJbeo7McSGashSMyo-mqgYwD4xK142EUjKH81Voc2UZ5cM7nNSV9HNQ5sbICUft-Ys", refreshToken="1/nePqCavtbE8WRQUT45XCn-sFYaCMHQdSMBVB9kMqGzY", expirationDate="2016-03-01 08:00:18 +0000"}
We don't receive the callbacks now, and the system terminates our application with a warning.
2016-03-01 04:00:18.814 emission[643:318185] Warning: Application delegate received call to -application:didReceiveRemoteNotification:fetchCompletionHandler: but the completion handler was never called.
We get the callbacks for this set of refreshes at the next remote push. As before, they are still the exact same token, and are expired.
2016-03-01 05:00:15.927 emission[643:318185] Refresh completion block called, refreshed token is GTMOAuth2Authentication 0x158273e30: {accessToken="ya29.mAJbeo7McSGashSMyo-mqgYwD4xK142EUjKH81Voc2UZ5cM7nNSV9HNQ5sbICUft-Ys", refreshToken="1/nePqCavtbE8WRQUT45XCn-sFYaCMHQdSMBVB9kMqGzY", expirationDate="2016-03-01 08:00:18 +0000"}
2016-03-01 05:00:15.945 emission[643:318185] Auth token GTMOAuth2Authentication 0x158273e30: {accessToken="ya29.mAJbeo7McSGashSMyo-mqgYwD4xK142EUjKH81Voc2UZ5cM7nNSV9HNQ5sbICUft-Ys", refreshToken="1/nePqCavtbE8WRQUT45XCn-sFYaCMHQdSMBVB9kMqGzY", expirationDate="2016-03-01 08:00:18 +0000"} still expired after first refresh attempt (expiry date = 2016-03-01 08:00:18 +0000, now = 2016-03-01 13:00:15 +0000), notifying user
2016-03-01 05:00:15.961 emission[643:318185] Error Error Domain=e-mission-domain Code=-100 "Refresh token still expired" UserInfo={NSLocalizedRecoverySuggestion=Sign out and Sign in again., NSLocalizedDescription=Refresh token still expired, NSLocalizedFailureReason=Unknown.} while refreshing token in background
So we start another set of refreshes.
2016-03-01 05:00:16.686 emission[643:318185] pullIntoUserCache called
2016-03-01 05:00:16.762 emission[643:318185] about to launch remote call for server_to_phone
2016-03-01 05:00:16.791 emission[643:318185] CommunicationHelper.server_to_phone called!
2016-03-01 05:00:16.791 emission[643:318185] CommunicationHelper.execute called!
2016-03-01 05:00:16.821 emission[643:318185] currAuth != null, nothing to do
2016-03-01 05:00:16.836 emission[643:318185] currAuth = GTMOAuth2Authentication 0x158273e30: {accessToken="ya29.mAJbeo7McSGashSMyo-mqgYwD4xK142EUjKH81Voc2UZ5cM7nNSV9HNQ5sbICUft-Ys", refreshToken="1/nePqCavtbE8WRQUT45XCn-sFYaCMHQdSMBVB9kMqGzY", expirationDate="2016-03-01 08:00:18 +0000"}, canAuthorize = YES, expiresIn = 3600, expirationDate = 2016-03-01 08:00:18 +0000, expired = YES
2016-03-01 05:00:16.856 emission[643:318185] token has expired, refreshing it
2016-03-01 05:00:16.879 emission[643:318185] beginning refresh of token GTMOAuth2Authentication 0x158273e30: {accessToken="ya29.mAJbeo7McSGashSMyo-mqgYwD4xK142EUjKH81Voc2UZ5cM7nNSV9HNQ5sbICUft-Ys", refreshToken="1/nePqCavtbE8WRQUT45XCn-sFYaCMHQdSMBVB9kMqGzY", expirationDate="2016-03-01 08:00:18 +0000"}
Don't get callbacks for those, so ends again with a warning.
2016-03-01 05:00:17.009 emission[643:318185] Warning: Application delegate received call to -application:didReceiveRemoteNotification:fetchCompletionHandler: but the completion handler was never called.
And then finally when I do unlock the phone, we get a properly refreshed token and all the pushes succeed. Note that the expirationDate on the token jumped from 8:00 to 16:00. That is because all the intermediate pushes failed.
2016-03-01 07:10:43.577 emission[643:318185] Application will enter the background
2016-03-01 07:10:43.937 emission[643:318185] Refresh completion block called, refreshed token is GTMOAuth2Authentication 0x158273e30: {accessToken="ya29.mALyRdZkzc_Zc2B81T2fhJpooyKB-6XbDpiZt2-gGrY9HLNcVIAzvua83FVeOEZrqYQ", refreshToken="1/nePqCavtbE8WRQUT45XCn-sFYaCMHQdSMBVB9kMqGzY", expirationDate="2016-03-01 16:10:43 +0000"}
2016-03-01 07:10:43.951 emission[643:318185] Refresh is really done, returning refreshed token
2016-03-01 07:10:43.968 emission[643:318185] Finished refreshing token in background, new instance is GTMOAuth2Authentication 0x158273e30: {accessToken="ya29.mALyRdZkzc_Zc2B81T2fhJpooyKB-6XbDpiZt2-gGrY9HLNcVIAzvua83FVeOEZrqYQ", refreshToken="1/nePqCavtbE8WRQUT45XCn-sFYaCMHQdSMBVB9kMqGzY", expirationDate="2016-03-01 16:10:43 +0000"}
2016-03-01 07:10:47.651 emission[643:318185] Retrieved 2 documents
2016-03-01 07:10:47.679 emission[643:318185] In TripDiaryStateMachine, received transition T_NOP in state STATE_WAITING_FOR_TRIP_START
2016-03-01 07:10:47.691 emission[643:318185] data has 65 bytes, str has size 65
2016-03-01 07:10:47.708 emission[643:318185] Got unexpected transition T_NOP in state STATE_WAITING_FOR_TRIP_START, ignoring
2016-03-01 07:10:47.708 emission[643:318185] Received notification T_NOP while processing silent push notification
2016-03-01 07:10:47.724 emission[643:318185] Remote push state machine ignored the silent push, fetch result = new data
2016-03-01 07:11:32.471 emission[643:318185] Application went to the background
We now know the issues related to the bad JWTs earlier:
Now that these issues have been resolved, we can move back to the original plan with the non-hardcoded JWTs. Need to think about whether that is better (involves more native calls but gives us XHR functionality which can give us nice progress bars like
http://github.hubspot.com/pace/docs/welcome/
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.