Credentials¶
OneBoxMap relies on two independent credential mechanisms. Understanding which
one drives which feature is the key to reasoning about degraded states.
Mechanism |
Source |
Consumed by |
Failure impact |
|---|---|---|---|
API key |
|
HERE map tiles; Logging window |
Map falls back to non-HERE tiles |
OAuth2 token |
access key id/secret → token endpoint |
|
Requests cannot be authorized |
The two are resolved and stored by here_search_demo.auth.Credentials, then wired into
the widget by here_search_demo.widgets.app.OneBoxMap.
Files: src/here_search_demo/auth.py, src/here_search_demo/widgets/app.py,
src/here_search_demo/widgets/credentials.py, src/here_search_demo/api.py,
src/here_search_demo/widgets/input_map.py.
1. Credentials: where values come from¶
Credentials() resolves values once at construction (_config()), from environment
variables and/or a credentials file. Environment variables take precedence over file
values.
API key resolution order:
API_KEYHERE_API_KEYfile key
here.api.key(or legacyapikey)
OAuth2 values:
Purpose |
Env var |
File key |
|---|---|---|
Token endpoint |
|
|
Access key id |
|
|
Access key secret |
|
|
Scope (optional) |
|
|
Credentials files are matched by name (credentials.properties.txt,
credentials.properties, .credentials.properties) in this directory order:
/drive → cwd → . → home → ~/.here/.
The API key and the OAuth2 pair are independent. A config can yield a working API key with no OAuth2 token, or vice versa.
_config()records whichever it finds.
3. Runtime wiring in OneBoxMap¶
At construction, OneBoxMap:
accepts a
Credentialsinstance (or creates one).builds the map and the search widgets; the search box starts hidden.
creates a
CredentialsLoaderwidget and, ifCredentials.active_configis already complete, seeds the loader with it.subscribes to loader changes via
_on_credentials_properties_change.calls
_apply_credentials_properties(...)for the initial config, then_schedule_search_box_visibility().
Whenever credentials change (initial load or a widget upload),
_apply_credentials_properties runs:
# src/here_search_demo/widgets/app.py
def _apply_credentials_properties(self, properties):
if not properties:
return
self.credentials.apply_active_config(properties) # update in-memory Credentials
self.map_w.refresh_base_layer() # re-pick HERE vs Positron tiles
self._schedule_search_box_visibility() # re-evaluate search box gating
active_config is all-or-nothing¶
Credentials.active_config only returns a non-empty mapping when the token endpoint,
access key id, access key secret and API key are all present and not placeholders
("..."). Consequently the loader is only pre-seeded from a complete config; a partial
one leaves the loader empty.
4. The CredentialsLoader widget does not touch files¶
When a user uploads a .properties file through the widget:
the frontend validates the text (
credentials_loader.mjs);the raw content is stored in the browser’s IndexedDB under the logical key
credentials.properties;the parsed values are pushed into the widget model and up to Python (
CredentialsLoader.active_config);OneBoxMapapplies them to the in-memoryCredentialsfor the current session.
The widget overrides the effective runtime credentials only. It does not rewrite
credentials.properties*on disk (repository, working directory, or~/.here/).
5. The search box is credential-gated¶
The search UI (query_box_w, query_terms_w, buttons_box_w, result_buttons_w) is
hidden until both hold:
credentials.api_keyis set, andcredentials.atokensuccessfully returns a token.
The check runs asynchronously (_credentials_are_valid → _update_search_box_visibility),
scheduled on the running event loop by _schedule_search_box_visibility. If no loop is
running (e.g. plain construction in tests) or token retrieval raises, the box stays hidden.
6. Behavior matrix¶
API key |
OAuth2 token retrievable |
Map tiles |
Search UI |
Search requests |
|---|---|---|---|---|
✅ |
✅ |
HERE tiles |
shown |
authorized |
✅ |
❌ |
HERE tiles |
hidden |
unauthorized (no valid Bearer token) |
❌ |
✅ |
CARTO Positron fallback |
hidden |
authorized, but UI to trigger them is hidden |
❌ |
❌ |
CARTO Positron fallback |
hidden |
unauthorized |
Takeaways:
A missing API key never breaks the map — it only downgrades tiles to the Positron fallback (and hides the search UI, because gating also requires the API key).
Missing/invalid OAuth2 does not break tile rendering, but it hides the search UI and leaves backend requests unauthorized.
7. Providing credentials¶
For the full experience, provide both:
an API key —
HERE_API_KEY(orAPI_KEY, orhere.api.keyin a file);OAuth2 credentials —
HERE_ACCESS_KEY_ID,HERE_ACCESS_KEY_SECRET, and optionallyHERE_TOKEN_ENDPOINT_URL/HERE_TOKEN_SCOPE.
Either supply them via environment variables / a credentials.properties file before
constructing OneBoxMap, or upload a .properties file at runtime through the loader
widget in the map’s top-right corner.
API¶
The class-level API for Credentials and the CredentialsLoader widget is documented
in the API Reference.