Unable to use temporary access tokens to interact with Mapbox
See original GitHub issueDescribe the bug
Using temporary access tokens (created via the create token API) leads to an invalid token alert: A valid access token parameter is required when using a Mapbox service.
To Reproduce
- Try to start the example app with a temporary token created via the create token API.
# create a temporary token with:
secret_token="<secret-token-here>"
curl \
-H "Content-Type: application/json" \
-X POST \
-d '{"expires": "2021-09-17T11:20:00.000-04:00","scopes": ["styles:read", "fonts:read"]}' \
"https://api.mapbox.com/tokens/v2/amesquita-dataminr?access_token=${secret_token}"
# The token is valid to load tiles
curl --head "https://api.mapbox.com/v4/mapbox.mapbox-streets-v8/1/0/0.png?access_token=tk.eyJ1IjoiYW1lc3F1aXRhLWRhdGFtaW5yIiwiZXhwIjoxNjMxODkzODAwLCJpYXQiOjE2MzE4OTA3NjIsInNjb3BlcyI6WyJzdHlsZXM6cmVhZCIsImZvbnRzOnJlYWQiXSwiY2xpZW50IjoiYXBpIn0.zgRENhgfiRargyOPQ0l4iA"
HTTP/1.1 200 OK
Content-Type: image/png
Content-Length: 19522
Connection: keep-alive
Date: Fri, 17 Sep 2021 15:43:21 GMT
# however the app says the token is invalid
# adding all public scopes does not solve the problem either
Expected behavior
The temporary token should be valid to interact with the mapbox
Actual behavior
An invalid token alert is displayed: A valid access token parameter is required when using a Mapbox service.
Versions (please complete the following information):
- Platform: Android
- Platform OS: Android 11 and 12
- Device: Pixel 3a XL
- Emulator/ Simulator: yes (also happens on emulator)
- Dev OS: OSX 11.6
- react-native-mapbox-gl Version 8.3.0
- Mapbox GL version default
- React Native Version 0.64
Issue Analytics
- State:
- Created 2 years ago
- Comments:7 (3 by maintainers)
Top Results From Across the Web
Unable to use temporary access tokens to interact with Mapbox
Using temporary access tokens (created via the create token API) leads to an invalid token alert: A valid access token parameter is required ......
Read more >Access tokens | Help - Mapbox docs
Mapbox uses access tokens to associate API requests with your account. You can find your access tokens, create new ones, or delete existing...
Read more >Token management | Accounts and pricing - Mapbox docs
Your Tokens page is where you can manage access tokens for your Mapbox account. To access the Tokens page, log into your account...
Read more >Creating access tokens with the Tokens API | Help | Mapbox
Walk through creating permanent and temporary access tokens using the Tokens API.
Read more >How to use Mapbox securely | Help
Each access token you create will have a set of permissions that allow you to make certain types of requests to Mapbox APIs...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Hi @ferdicus, thanks for reaching back!
I ended up linking the wrong page in the docs 😔; this is the relevant page: Create a temporary token. The issue I’m seeing happens when using temporary tokens, not just any token. When creating tokens, you can pass an optional
expires
attribute allowing you to create a token that expires up to 1 hour in the future. If this attribute is not present, a public or secret token (depending on the specific scopes) is created instead.You can get a temporary token with the curl command I mentioned above (i.e. by adding
"expires": "2021-09-17T10:00:00.000-04:00"
to the request payload (the actual date/time needs to be within the hour of issuing the curl command). The response you get from this new request contains only one attribute (token
) and looks similar to:I just tested it again on
master
and this is the error I see (screenshot):Everything works as expected if I use a public token (e.g.
pk.*****
).So… when will this be finally fixed?