ushahidi / platform-mobile

Hybrid Mobile UI for Ushahidi Platform V3+
GNU Affero General Public License v3.0
3 stars 1 forks source link

MapBox Tiles Sometimes Not Working #13

Open dalezak opened 7 years ago

dalezak commented 7 years ago

For some reason, the MapBox tiles and static images aren't working for some deployments.

Bad https://api.mapbox.com/styles/v1/mapbox/streets-v9/static/url-https%3A%2F%2Fapi.mapbox.com%2Fv4%2Fmarker%2Fpin-m%2B207AC9.png%3Faccess_token%3Dpk.eyJ1IjoidXNoYWhpZGkiLCJhIjoiY2lxaXRrbmF5MDdxNmZubmUyN2p6bms5biJ9.o7pmKDIN1EtwMBp1VIzITQ(-81.711777,30.102261)/-81.711777,30.102261,14/400x300?access_token=pk.eyJ1IjoidXNoYWhpZGkiLCJhIjoiY2lxaXRrbmF5MDdxNmZubmUyN2p6bms5biJ9.o7pmKDIN1EtwMBp1VIzITQ

Good https://api.mapbox.com/styles/v1/mapbox/streets-v9/static/url-https%3A%2F%2Fapi.mapbox.com%2Fv4%2Fmarker%2Fpin-m%2B207AC9.png%3Faccess_token%3Dpk.eyJ1IjoiZGFsZXphayIsImEiOiJjaXp5N3dvODgwMmE4MnFxcjg1Zm45cnNiIn0.GbIYV1o_hACky6UUU2IS3A(-122.031219,37.332331)/-122.031219,37.332331,14/400x300?access_token=pk.eyJ1IjoiZGFsZXphayIsImEiOiJjaXp5N3dvODgwMmE4MnFxcjg1Zm45cnNiIn0.GbIYV1o_hACky6UUU2IS3A

Bad https://api.mapbox.com/styles/v1/mapbox/streets-v9/tiles/256/{z}/{x}/{y}?access_token=pk.eyJ1IjoidXNoYWhpZGkiLCJhIjoiY2lxaXRrbmF5MDdxNmZubmUyN2p6bms5biJ9.o7pmKDIN1EtwMBp1VIzITQ

Good https://api.mapbox.com/styles/v1/mapbox/streets-v9/tiles/256/{z}/{x}/{y}?access_token=pk.eyJ1IjoiZGFsZXphayIsImEiOiJjaXp5N3dvODgwMmE4MnFxcjg1Zm45cnNiIn0.GbIYV1o_hACky6UUU2IS3A

dalezak commented 7 years ago

Ah-ha!

The app currently is using the mapbox_api_key defined in the deployments config.json.

However the issue is that mapbox_api_key might not have the necessary scopes, in particault styles:tiles needed to render static map images.

dalezak commented 7 years ago

Ok, I've figured a few things out (one step forward, two steps back!).

To be able to obtain the scopes for an access token, I need to know the username.

Luckily you can do a lookup of username from access token like https://api.mapbox.com/tokens/v2?access_token=pk.eyJ1IjoidXNoYWhpZGkiLCJhIjoiY2lxaXRrbmF5MDdxNmZubmUyN2p6bms5biJ9.o7pmKDIN1EtwMBp1VIzITQ

With the username, you can now find the scope https://api.mapbox.com/scopes/v1/ushahidi/?access_token=pk.eyJ1IjoidXNoYWhpZGkiLCJhIjoiY2lxaXRrbmF5MDdxNmZubmUyN2p6bms5biJ9.o7pmKDIN1EtwMBp1VIzITQ

However that request requires scopes:list, otherwise it simply returns "message": "Not Found" error.

So this doesn't get us very far, and probably means I can not reliably determine the scopes from an access token provided in the config.json.

dalezak commented 7 years ago

Still need to figure out how best to handle this scenario, moving this back to next Milestone.