🛂 Fix authorization while mapping APNS tokens to FCM #1002
Merged
+15
−9
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
FCM is doubling down on the "I'm going to change my API and break everything" approach. We made one round of fixes in: e-mission/e-mission-docs#1094 (comment)
at which time the mapping to convert APNS tokens to FCM was working
However, in the ~ 2 months since, that has also regressed, and we are now getting a 401 error with the old code.
The new requirements include:
"access_token_auth": "true"
as a headerhttps://developers.google.com/instance-id/reference/server
The current headers don't match these requirements
We already use an OAuth2 token to log in and actually send the messages
So it seems like it would be best to just reuse it for this call as well. However, that token is retrieved from within the pyfcm library and is not easily exposed outside the library.
The token is retrieved using in `_get_access_token`
which is called automatically in `requests_session`
However, the
requests_session
only caches a property on when the token expires, it does not cache the token itself.It does cache the headers and update them periodically, so instead of retrieving the token, this change retrieves the entire authorization header. This header includes the token, but is also formatted correctly with the
Bearer
prefix, so we can use it directly.With this change, the mapping is successful and both silent and visible push notification are sent to iOS phones.
Please see testing details in
400f9fa