|
8 | 8 | "\n", |
9 | 9 | "Sets up a more sophisticate authentication (authN) and authorization (authZ) combination for role-based access control (RBAC) to a mock API and its operations. \n", |
10 | 10 | "\n", |
11 | | - "This sample, compared to the simpler _AuthX_, introduces use of API Management Product and policy fragments to simplify and consolidate shared logic. When considering scaling, consider this as your starting point.\n", |
12 | | - "\n", |
13 | 11 | "⚙️ **Supported infrastructures**: All infrastructures\n", |
14 | 12 | "\n", |
15 | 13 | "⌚ **Expected *Run All* runtime (excl. infrastructure prerequisite): ~2-3 minutes**\n", |
|
23 | 21 | "1. Experience how API Management policy fragments simplify shared logic.\n", |
24 | 22 | "\n", |
25 | 23 | "## 📝 Scenario\n", |
| 24 | + "This sample, compared to the simpler _AuthX_, introduces use of API Management Product and policy fragments to simplify and consolidate shared logic. When considering scaling, consider this as your starting point.\n", |
26 | 25 | "\n", |
27 | | - "This sample combines _authentication (authN)_ and _authorization (authZ)_ into _authX_. This scenario focuses on a Human Resources API that requires privileged role-based access to GET and to POST data. This is simplistic but shows the combination of authN and authZ.\n", |
28 | | - "\n", |
29 | | - "There are two personas at play:\n", |
| 26 | + "The same two personas from _AuthX_ are at play:\n", |
30 | 27 | "\n", |
31 | 28 | "- `HR Administrator` - holds broad rights to the API\n", |
32 | 29 | "- `HR Associate` - has read-only permissions\n", |
33 | 30 | "\n", |
| 31 | + "The API hierarchy is as follows:\n", |
| 32 | + "\n", |
| 33 | + "1. All APIs / global\n", |
| 34 | + " This is a great place to do authentication, but we refrain from doing it in the sample as to not affect other samples. \n", |
| 35 | + "1. HR Product\n", |
| 36 | + " Perform authentication and authorization for HR_Member in the JWT claims. Continue on success; otherwise, return 401.\n", |
| 37 | + "1. HR Employee & Benefits APIs\n", |
| 38 | + " Both APIs are associated with the HR Product. The API must be called in a product context.\n", |
| 39 | + "1. API Operations\n", |
| 40 | + " GET authorization must either satisfy an HR Administrator or HR Associate role\n", |
| 41 | + " POST authorization must satisfy an HR Administrator role..\n", |
| 42 | + "\n", |
34 | 43 | "Both personas are part of an HR_Members group and may access the HR API Management Product. Subsequent access to the APIs and their operations must be granular.\n", |
35 | 44 | "\n", |
36 | 45 | "### 💡 Notes\n", |
|
128 | 137 | "\n", |
129 | 138 | "hr_product_name = 'hr'\n", |
130 | 139 | "products: List[Product] = [\n", |
131 | | - " Product(hr_product_name, 'Human Resources', 'Product for Human Resources APIs providing access to employee data, organizational structure, benefits information, and HR management services. Includes JWT-based authentication for HR members.', 'published', False, False, hr_product_xml)\n", |
| 140 | + " Product(hr_product_name, 'Human Resources', \n", |
| 141 | + " 'Product for Human Resources APIs providing access to employee data, organizational structure, benefits information, and HR management services. Includes JWT-based authentication for HR members.', \n", |
| 142 | + " 'published', False, False, hr_product_xml)\n", |
132 | 143 | "]\n", |
133 | 144 | "\n", |
134 | 145 | "# 6) Define the APIs and their operations and policies\n", |
|
137 | 148 | "hremployees_api_path = f'/{api_prefix}employees'\n", |
138 | 149 | "hremployees_get = GET_APIOperation('Gets the employees', utils.read_policy_xml('./hr_get.xml'))\n", |
139 | 150 | "hremployees_post = POST_APIOperation('Creates a new employee', utils.read_policy_xml('./hr_post.xml'))\n", |
140 | | - "hremployees = API(f'{api_prefix}Employees', 'Employees Pro', hremployees_api_path, 'This is a Human Resources API for employee information', utils.read_policy_xml(DEFAULT_XML_POLICY_PATH), operations = [hremployees_get, hremployees_post], tags = tags, productNames = [hr_product_name])\n", |
| 151 | + "hremployees = API(f'{api_prefix}Employees', 'Employees Pro', hremployees_api_path, 'This is a Human Resources API for employee information', utils.read_policy_xml(DEFAULT_XML_POLICY_PATH), \n", |
| 152 | + " operations = [hremployees_get, hremployees_post], tags = tags, productNames = [hr_product_name], subscriptionRequired = True)\n", |
141 | 153 | "\n", |
142 | 154 | "# Benefits (HR)\n", |
143 | 155 | "hrbenefits_api_path = f'/{api_prefix}benefits'\n", |
144 | 156 | "hrbenefits_get = GET_APIOperation('Gets employee benefits', utils.read_policy_xml('./hr_get.xml'))\n", |
145 | 157 | "hrbenefits_post = POST_APIOperation('Creates employee benefits', utils.read_policy_xml('./hr_post.xml'))\n", |
146 | | - "hrbenefits = API(f'{api_prefix}Benefits', 'Benefits Pro', hrbenefits_api_path, 'This is a Human Resources API for employee benefits', utils.read_policy_xml(DEFAULT_XML_POLICY_PATH), operations = [hrbenefits_get, hrbenefits_post], tags = tags, productNames = [hr_product_name])\n", |
| 158 | + "hrbenefits = API(f'{api_prefix}Benefits', 'Benefits Pro', hrbenefits_api_path, 'This is a Human Resources API for employee benefits', utils.read_policy_xml(DEFAULT_XML_POLICY_PATH), \n", |
| 159 | + " operations = [hrbenefits_get, hrbenefits_post], tags = tags, productNames = [hr_product_name], subscriptionRequired = True)\n", |
147 | 160 | "\n", |
148 | 161 | "# APIs Array\n", |
149 | 162 | "apis: List[API] = [hremployees, hrbenefits]\n", |
|
0 commit comments