Skip to content

Commit 1b87223

Browse files
authored
use sharedkey mechanism for authenticating to AzMaps (#507)
* use sharedkey mechanism for authenticating to AzMaps * Add Azure Maps subscription key configuration to environment files * Add escape key functionality to close import dialog in explorer tests
1 parent 7af53b0 commit 1b87223

File tree

8 files changed

+25
-14
lines changed

8 files changed

+25
-14
lines changed

.env.sample

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,5 +16,8 @@ REACT_APP_IMAGE_API_ROOT=https://planetarycomputer-staging.microsoft.com/api/f
1616
# Client Id for Azure Maps
1717
REACT_APP_AZMAPS_CLIENT_ID=8f49b6d6-5845-4e20-9015-9630df1ca8d2
1818

19+
# Subscription Key for Azure Maps
20+
REACT_APP_AZMAPS_KEY=
21+
1922
# URL for JHub cloned repo launch (including 'git-pull')
2023
REACT_APP_HUB_URL=

.github/workflows/azure-static-web-apps-icy-meadow-0fc35e30f.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ jobs:
2525
REACT_APP_AZMAPS_CLIENT_ID: ${{ secrets.AZMAPS_CLIENT_ID }}
2626
REACT_APP_ONEDS_TENANT_KEY: ${{ secrets.ONEDS_TENANT_KEY }}
2727
REACT_APP_HUB_URL: ${{ secrets.HUB_URL }}
28+
REACT_APP_AZMAPS_KEY: ${{ secrets.AZMAPS_KEY }}
2829
steps:
2930
- uses: actions/checkout@v3
3031
with:

.github/workflows/azure-static-web-apps-thankful-sand-0ed34c70f.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ jobs:
2525
REACT_APP_AZMAPS_CLIENT_ID: ${{ secrets.AZMAPS_CLIENT_ID }}
2626
REACT_APP_ONEDS_TENANT_KEY: ${{ secrets.ONEDS_TENANT_KEY }}
2727
REACT_APP_HUB_URL: ${{ secrets.HUB_URL }}
28+
REACT_APP_AZMAPS_KEY: ${{ secrets.AZMAPS_KEY }}
2829
steps:
2930
- uses: actions/checkout@v3
3031
with:

.github/workflows/azure-static-web-apps-wonderful-stone-06c70c70f.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ jobs:
2525
REACT_APP_AZMAPS_CLIENT_ID: ${{ secrets.AZMAPS_CLIENT_ID }}
2626
REACT_APP_ONEDS_TENANT_KEY: ${{ secrets.ONEDS_TENANT_KEY }}
2727
REACT_APP_HUB_URL: ${{ secrets.HUB_URL }}
28+
REACT_APP_AZMAPS_KEY: ${{ secrets.AZMAPS_KEY }}
2829
steps:
2930
- uses: actions/checkout@v3
3031
with:

api/map-token/__init__.py

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -25,14 +25,17 @@ class TokenResponse(TypedDict):
2525
def main(req: func.HttpRequest) -> func.HttpResponse:
2626

2727
logger.debug("Python HTTP trigger function processed a request.")
28-
try:
29-
logger.debug("Getting azure maps token")
30-
token = credential.get_token("https://atlas.microsoft.com/.default")
31-
logger.debug("Token acquired")
32-
33-
resp: TokenResponse = {"token": token.token, "expires_on": token.expires_on}
34-
35-
return func.HttpResponse(status_code=200, body=json.dumps(resp))
36-
except ClientAuthenticationError:
37-
logger.exception(f"Error getting azure maps token")
38-
return func.HttpResponse("Error getting token", status_code=500)
28+
# Comment out the implementation below and fail this call forcibly
29+
return func.HttpResponse("This API is not implemented yet", status_code=501)
30+
# Uncomment the implementation below to enable token retrieval
31+
# try:
32+
# logger.debug("Getting azure maps token")
33+
# token = credential.get_token("https://atlas.microsoft.com/.default")
34+
# logger.debug("Token acquired")
35+
36+
# resp: TokenResponse = {"token": token.token, "expires_on": token.expires_on}
37+
38+
# return func.HttpResponse(status_code=200, body=json.dumps(resp))
39+
# except ClientAuthenticationError:
40+
# logger.exception(f"Error getting azure maps token")
41+
# return func.HttpResponse("Error getting token", status_code=500)

cypress/e2e/explorer/selector.cy.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,8 @@ describe("Explorer selector tests", () => {
7575
cy.contains("import planetary_computer");
7676
cy.contains("Copy");
7777

78+
// Close the dialog with escape
79+
cy.get("body").type("{esc}");
7880
// Typing escape has closed the dialog
7981
cy.contains("import planetary_computer").should("not.exist");
8082

docker-compose.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ services:
1717
- REACT_APP_AZMAPS_CLIENT_ID
1818
- REACT_APP_ONEDS_TENANT_KEY
1919
- REACT_APP_HUB_URL
20+
- REACT_APP_AZMAPS_KEY
2021
volumes:
2122
- .:/usr/src
2223
- ~/.npm:/root/.npm

src/pages/Explore/components/Map/index.tsx

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -59,9 +59,8 @@ const ExploreMap = () => {
5959
style: DEFAULT_MAP_STYLE,
6060
renderWorldCopies: true,
6161
authOptions: {
62-
authType: atlas.AuthenticationType.anonymous,
63-
clientId: AZMAPS_CLIENT_ID,
64-
getToken: fetchMapToken,
62+
authType: atlas.AuthenticationType.subscriptionKey,
63+
subscriptionKey: process.env.REACT_APP_AZMAPS_KEY,
6564
},
6665
transformRequest: addEntityHeader,
6766
});

0 commit comments

Comments
 (0)