You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: articles/static-web-apps/assign-roles-microsoft-graph.md
+2-2Lines changed: 2 additions & 2 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -19,10 +19,10 @@ In this tutorial, you learn to:
19
19
- Deploy a static web app.
20
20
- Create an Azure Active Directory app registration.
21
21
- Set up custom authentication with Azure Active Directory.
22
-
- Configure a [serverless function](authentication-authorization.md?tabs=function#role-management) that queries the user's Active Directory group membership and returns a list of custom roles.
22
+
- Configure a [serverless function](authentication-custom.md#manage-roles) that queries the user's Active Directory group membership and returns a list of custom roles.
23
23
24
24
> [!NOTE]
25
-
> This tutorial requires you to [use a function to assign roles](authentication-authorization.md?tabs=function#role-management). Function-based role management is currently in preview.
25
+
> This tutorial requires you to [use a function to assign roles](authentication-custom.md#manage-roles). Function-based role management is currently in preview.
Copy file name to clipboardExpand all lines: articles/static-web-apps/authentication-custom.md
+182Lines changed: 182 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -317,6 +317,188 @@ To use a custom identity provider, use the following URL patterns.
317
317
318
318
If you are using Azure Active Directory, use `aad` as the value for the `<PROVIDER_NAME_IN_CONFIG>` placeholder.
319
319
320
+
## Manage roles
321
+
322
+
Every user who accesses a static web app belongs to one or more roles. There are two built-in roles that users can belong to:
323
+
324
+
-**anonymous**: All users automatically belong to the _anonymous_ role.
325
+
-**authenticated**: All users who are signed in belong to the _authenticated_ role.
326
+
327
+
Beyond the built-in roles, you can assign custom roles to users, and reference them in the _staticwebapp.config.json_ file.
328
+
329
+
# [Invitations](#tab/invitations)
330
+
331
+
### Add a user to a role
332
+
333
+
To add a user to a role, you generate invitations that allow you to associate users to specific roles. Roles are defined and maintained in the _staticwebapp.config.json_ file.
334
+
335
+
<aname="invitations"id="invitations"></a>
336
+
337
+
#### Create an invitation
338
+
339
+
Invitations are specific to individual authorization-providers, so consider the needs of your app as you select which providers to support. Some providers expose a user's email address, while others only provide the site's username.
1. Go to a Static Web Apps resource in the [Azure portal](https://portal.azure.com).
352
+
2. Under _Settings_, select **Role Management**.
353
+
3. Select **Invite**.
354
+
4. Select an _Authorization provider_ from the list of options.
355
+
5. Add either the username or email address of the recipient in the _Invitee details_ box.
356
+
- For GitHub and Twitter, enter the username. For all others, enter the recipient's email address.
357
+
6. Select the domain of your static site from the _Domain_ drop-down menu.
358
+
- The domain you select is the domain that appears in the invitation. If you have a custom domain associated with your site, choose the custom domain.
359
+
7. Add a comma-separated list of role names in the _Role_ box.
360
+
8. Enter the maximum number of hours you want the invitation to remain valid.
361
+
- The maximum possible limit is 168 hours, which is seven days.
362
+
9. Select **Generate**.
363
+
10. Copy the link from the _Invite link_ box.
364
+
11. Email the invitation link to the user that you're granting access to.
365
+
366
+
When the user selects the link in the invitation, they're prompted to sign in with their corresponding account. Once successfully signed in, the user is associated with the selected roles.
367
+
368
+
> [!CAUTION]
369
+
> Make sure your route rules don't conflict with your selected authentication providers. Blocking a provider with a route rule prevents users from accepting invitations.
370
+
371
+
### Update role assignments
372
+
373
+
1. Go to a Static Web Apps resource in the [Azure portal](https://portal.azure.com).
374
+
1. Under _Settings_, select **Role Management**.
375
+
2. Select the user in the list.
376
+
3. Edit the list of roles in the _Role_ box.
377
+
4. Select **Update**.
378
+
379
+
### Remove user
380
+
381
+
1. Go to a Static Web Apps resource in the [Azure portal](https://portal.azure.com).
382
+
1. Under _Settings_, select **Role Management**.
383
+
1. Locate the user in the list.
384
+
1. Check the checkbox on the user's row.
385
+
2. Select **Delete**.
386
+
387
+
As you remove a user, keep in mind the following items:
388
+
389
+
- Removing a user invalidates their permissions.
390
+
- Worldwide propagation may take a few minutes.
391
+
- If the user is added back to the app, the [`userId` changes](user-information.md).
392
+
393
+
# [Function (preview)](#tab/function)
394
+
395
+
Instead of using the built-in invitations system, you can use a serverless function to programmatically assign roles to users when they sign in.
396
+
397
+
To assign custom roles in a function, you can define an API function that is automatically called after each time a user successfully authenticates with an identity provider. The function is passed the user's information from the provider. It must return a list of custom roles that are assigned to the user.
398
+
399
+
Example uses of this function include:
400
+
401
+
- Query a database to determine which roles a user should be assigned
402
+
- Call the [Microsoft Graph API](https://developer.microsoft.com/graph) to determine a user's roles based on their Active Directory group membership
403
+
- Determine a user's roles based on claims returned by the identity provider
404
+
405
+
> [!NOTE]
406
+
> The ability to assign roles via a function is only available when [custom authentication](authentication-custom.md) is configured.
407
+
>
408
+
> When this feature is enabled, any roles assigned via the built-in invitations system are ignored.
409
+
410
+
### Configure a function for assigning roles
411
+
412
+
To configure Static Web Apps to use an API function as the role assignment function, add a `rolesSource` property to the `auth` section of your app's [configuration file](configuration.md). The value of the `rolesSource` property is the path to the API function.
413
+
414
+
```json
415
+
{
416
+
"auth": {
417
+
"rolesSource": "/api/GetRoles",
418
+
"identityProviders": {
419
+
// ...
420
+
}
421
+
}
422
+
}
423
+
```
424
+
425
+
> [!NOTE]
426
+
> Once configured, the role assignment function can no longer be accessed by external HTTP requests.
427
+
428
+
### Create a function for assigning roles
429
+
430
+
After you define the `rolesSource` property in your app's configuration, add an [API function](apis-functions.md) in your static web app at the specified path. You can use a managed function app or [bring your own function app](functions-bring-your-own.md).
431
+
432
+
Each time a user successfully authenticates with an identity provider, the POST method calls the specified function. The function passes a JSON object in the request body that contains the user's information from the provider. For some identity providers, the user information also includes an `accessToken` that the function can use to make API calls using the user's identity.
The function can use the user's information to determine which roles to assign to the user. It must return an HTTP 200 response with a JSON body containing a list of custom role names to assign to the user.
484
+
485
+
For example, to assign the user to the `Reader` and `Contributor` roles, return the following response:
486
+
487
+
```json
488
+
{
489
+
"roles": [
490
+
"Reader",
491
+
"Contributor"
492
+
]
493
+
}
494
+
```
495
+
496
+
If you don't want to assign any other roles to the user, return an empty `roles` array.
497
+
498
+
To learn more, see [Tutorial: Assign custom roles with a function and Microsoft Graph](assign-roles-microsoft-graph.md).
Copy file name to clipboardExpand all lines: articles/static-web-apps/faq.yml
+2-2Lines changed: 2 additions & 2 deletions
Original file line number
Diff line number
Diff line change
@@ -157,12 +157,12 @@ sections:
157
157
- question: |
158
158
How many users can log in to my static web app?
159
159
answer:
160
-
Static Web Apps doesn't have a limit on the number of users that can log in to your app. You can assign custom roles to up to 25 users using the built-in invitations system. If you need to assign custom roles to more users, you can use an [API function to programmatically assign roles](authentication-authorization.md?tabs=function#role-management).
160
+
Static Web Apps doesn't have a limit on the number of users that can log in to your app. You can assign custom roles to up to 25 users using the built-in invitations system. If you need to assign custom roles to more users, you can use an [API function to programmatically assign roles](authentication-custom.md#manage-roles).
161
161
162
162
- question: |
163
163
How do I use the retrieve a user's access token or claims from the identity provider?
164
164
answer: |
165
-
You can retrieve the user's access token and claims when you use an [API function for role management](authentication-authorization.md?tabs=function#role-management).
165
+
You can retrieve the user's access token and claims when you use an [API function for role management](authentication-custom.md#manage-roles).
Copy file name to clipboardExpand all lines: articles/static-web-apps/quotas.md
+1-1Lines changed: 1 addition & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -24,7 +24,7 @@ The following quotas exist for Azure Static Web Apps.
24
24
| Custom domains | 2 per app | 5 per app |
25
25
| Allowed IP ranges | Unavailable | 25 |
26
26
| Authorization (built-in roles) | Unlimited end-users that may authenticate with built-in `authenticated` role | Unlimited end-users that may authenticate with built-in `authenticated` role |
27
-
| Authorization (custom roles) | Maximum of 25 end-users that may belong to custom roles via [invitations](authentication-authorization.md?tabs=invitations#role-management)| Maximum of 25 end-users that may belong to custom roles via [invitations](authentication-authorization.md?tabs=invitations#role-management), or unlimited end-users that may be assigned custom roles via [serverless function](authentication-authorization.md?tabs=function#role-management)|
27
+
| Authorization (custom roles) | Maximum of 25 end-users that may belong to custom roles via [invitations](authentication-custom.md#manage-roles)| Maximum of 25 end-users that may belong to custom roles via [invitations](authentication-custom.md#manage-roles), or unlimited end-users that may be assigned custom roles via [serverless function](authentication-custom.md#manage-roles)|
0 commit comments