question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Unable to use temporary access tokens to interact with Mapbox

See original GitHub issue

Describe 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:closed
  • Created 2 years ago
  • Comments:7 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
andersonvomcommented, Sep 24, 2021

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:

// notice the token starts with the `tk.` prefix
{"token":"tk.**********"}

I just tested it again on master and this is the error I see (screenshot):

ERROR  Mapbox error {mapboxglexample}[Setup]: loading style failed: A valid access token parameter is required when using a Mapbox service.
Please see https://www.mapbox.com/help/create-api-access-token/ to learn how to create one.
More information in this guide https://www.mapbox.com/help/first-steps-android-sdk/#access-tokens.
Currently provided token is: tk.******.****** {"level": "error", "message": "{mapboxglexample}[Setup]: loading style failed: A valid access token parameter is required when using a Mapbox service.

Everything works as expected if I use a public token (e.g. pk.*****).

0reactions
RicardoDolNLcommented, Aug 22, 2022

So… when will this be finally fixed?

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found