Skip to content

Commit 75ea2a8

Browse files
Feature/add afd support for authx (#17)
1 parent 7eb59aa commit 75ea2a8

File tree

2 files changed

+18
-7
lines changed

2 files changed

+18
-7
lines changed

infrastructure/simple-apim/create.ipynb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -74,8 +74,8 @@
7474
"\n",
7575
"# 1) Define the Bicep parameters with serialized APIs\n",
7676
"bicep_parameters = {\n",
77-
" 'apimSku': {'value': apim_sku.value},\n",
78-
" 'apis': {'value': [api.to_dict() for api in apis]}\n",
77+
" 'apimSku' : {'value': apim_sku.value},\n",
78+
" 'apis' : {'value': [api.to_dict() for api in apis]}\n",
7979
"}\n",
8080
"\n",
8181
"# 2) Run the deployment\n",

samples/authX/create.ipynb

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
"\n",
1111
"⚙️ **Supported infrastructures**: All infrastructures\n",
1212
"\n",
13-
"⌚ **Expected *Run All* runtime (excl. infrastructure prerequisite): ~[NOTEBOOK RUNTIME] minute**\n",
13+
"⌚ **Expected *Run All* runtime (excl. infrastructure prerequisite): ~2-3 minutes**\n",
1414
"\n",
1515
"## Objectives\n",
1616
"\n",
@@ -190,14 +190,25 @@
190190
"from apimjwt import JwtPayload, SymmetricJwtToken\n",
191191
"from apimtypes import HR_MEMBER_ROLE_ID, HR_ADMINISTRATOR_ROLE_ID, HR_ASSOCIATE_ROLE_ID\n",
192192
"\n",
193+
"# Preflight: Check if the infrastructure architecture deployment uses Azure Front Door. If so, assume that APIM is not directly accessible and use the Front Door URL instead.\n",
194+
"endpoint_url = apim_gateway_url\n",
195+
"utils.print_message('Checking if the infrastructure architecture deployment uses Azure Front Door.', blank_above = True)\n",
196+
"afd_endpoint_url = utils.get_frontdoor_url(deployment, rg_name)\n",
197+
"\n",
198+
"if afd_endpoint_url:\n",
199+
" endpoint_url = afd_endpoint_url\n",
200+
" utils.print_message(f'Using Azure Front Door URL: {afd_endpoint_url}', blank_above = True)\n",
201+
"else:\n",
202+
" utils.print_message(f'Using APIM Gateway URL: {apim_gateway_url}', blank_above = True)\n",
203+
"\n",
193204
"# 1) HR Administrator\n",
194205
"# Create a JSON Web Token with a payload and sign it with the symmetric key from above.\n",
195206
"jwt_payload_hr_admin = JwtPayload(subject = 'user123', name = 'Angie Administrator', roles = [HR_MEMBER_ROLE_ID, HR_ADMINISTRATOR_ROLE_ID])\n",
196207
"encoded_jwt_token_hr_admin = SymmetricJwtToken(jwt_key_value, jwt_payload_hr_admin).encode()\n",
197-
"print(f'JWT token HR Admin: {encoded_jwt_token_hr_admin}') # this value is used to call the APIs via APIM\n",
208+
"print(f'\\nJWT token HR Admin: {encoded_jwt_token_hr_admin}') # this value is used to call the APIs via APIM\n",
198209
"\n",
199210
"# Set up an APIM requests object with the JWT token\n",
200-
"reqsApimAdmin = ApimRequests(apim_gateway_url)\n",
211+
"reqsApimAdmin = ApimRequests(endpoint_url)\n",
201212
"reqsApimAdmin.headers['Authorization'] = f'Bearer {encoded_jwt_token_hr_admin}'\n",
202213
"\n",
203214
"# Call APIM\n",
@@ -208,10 +219,10 @@
208219
"# Create a JSON Web Token with a payload and sign it with the symmetric key from above.\n",
209220
"jwt_payload_hr_associate = JwtPayload(subject = 'user789', name = 'Aaron Associate', roles = [HR_MEMBER_ROLE_ID, HR_ASSOCIATE_ROLE_ID])\n",
210221
"encoded_jwt_token_hr_associate = SymmetricJwtToken(jwt_key_value, jwt_payload_hr_associate).encode()\n",
211-
"print(f'\\n\\nJWT token HR Associate: {encoded_jwt_token_hr_associate}') # this value is used to call the APIs via APIM\n",
222+
"print(f'\\nJWT token HR Associate: {encoded_jwt_token_hr_associate}') # this value is used to call the APIs via APIM\n",
212223
"\n",
213224
"# Set up an APIM requests object with the JWT token\n",
214-
"reqsApimAssociate = ApimRequests(apim_gateway_url)\n",
225+
"reqsApimAssociate = ApimRequests(endpoint_url)\n",
215226
"reqsApimAssociate.headers['Authorization'] = f'Bearer {encoded_jwt_token_hr_associate}'\n",
216227
"\n",
217228
"# Call APIM\n",

0 commit comments

Comments
 (0)