|
1 | 1 | ---
|
2 |
| -title: Authorize request to Web PubSub resources with Microsoft Entra ID from applications |
3 |
| -description: This article provides information about authorizing request to Web PubSub resources with Microsoft Entra ID from applications |
| 2 | +title: Authorize an application request by using Microsoft Entra ID |
| 3 | +description: Learn how to authorize an application request to Web PubSub resources by using Microsoft Entra ID. |
4 | 4 | author: terencefan
|
5 |
| - |
6 | 5 | ms.author: tefa
|
7 |
| -ms.date: 11/08/2021 |
| 6 | +ms.date: 08/16/2024 |
8 | 7 | ms.service: azure-web-pubsub
|
9 | 8 | ms.topic: conceptual
|
10 | 9 | ---
|
11 | 10 |
|
12 |
| -# Authorize request to Web PubSub resources with Microsoft Entra ID from Azure applications |
| 11 | +# Authorize an application request by using Microsoft Entra ID |
13 | 12 |
|
14 |
| -Azure Web PubSub Service supports Microsoft Entra ID for authorizing requests from [applications](../active-directory/develop/app-objects-and-service-principals.md). |
| 13 | +Azure Web PubSub supports Microsoft Entra ID for authorizing requests from [applications](../active-directory/develop/app-objects-and-service-principals.md). |
15 | 14 |
|
16 |
| -This article shows how to configure your Web PubSub resource and codes to authorize the request to a Web PubSub resource from an Azure application. |
| 15 | +This article shows you how to configure your Web PubSub resource and code to authorize a request to a Web PubSub resource from an Azure application. |
17 | 16 |
|
18 | 17 | ## Register an application
|
19 | 18 |
|
20 | 19 | The first step is to register an Azure application.
|
21 | 20 |
|
22 |
| -1. On the [Azure portal](https://portal.azure.com/), search for and select **Microsoft Entra ID** |
23 |
| -2. Under **Manage** section, select **App registrations**. |
24 |
| -3. Click **New registration**. |
25 |
| - |
26 |
| -  |
| 21 | +1. In the [Azure portal](https://portal.azure.com/), search for and then select **Microsoft Entra ID**. |
| 22 | +1. On the left menu under **Manage**, select **App registrations**. |
| 23 | +1. Select **New registration**. |
| 24 | +1. For **Name**, enter a name to use for your application. |
| 25 | +1. Select **Register** to confirm the application registration. |
27 | 26 |
|
28 |
| -4. Enter a display **Name** for your application. |
29 |
| -5. Click **Register** to confirm the register. |
| 27 | +:::image type="content" source="media/howto-authorize-from-application/register-an-application.png" alt-text="Screenshot that shows registering an application."::: |
30 | 28 |
|
31 |
| -Once you have your application registered, you can find the **Application (client) ID** and **Directory (tenant) ID** under its Overview page. These GUIDs can be useful in the following steps. |
| 29 | +When your application is registered, go to the application overview to view the values for **Application (client) ID** and **Directory (tenant) ID**. You use these values in the following sections. |
32 | 30 |
|
33 |
| - |
| 31 | +:::image type="content" source="media/howto-authorize-from-application/application-overview.png" alt-text="Screenshot that shows an application."::: |
34 | 32 |
|
35 |
| -To learn more about registering an application, see |
36 |
| - |
37 |
| -- [Quickstart: Register an application with the Microsoft identity platform](../active-directory/develop/quickstart-register-app.md). |
| 33 | +For more information about registering an application, see the quickstart [Register an application by using the Microsoft identity platform](../active-directory/develop/quickstart-register-app.md). |
38 | 34 |
|
39 | 35 | ## Add credentials
|
40 | 36 |
|
41 | 37 | You can add both certificates and client secrets (a string) as credentials to your confidential client app registration.
|
42 | 38 |
|
43 |
| -### Client secret |
| 39 | +For more information about adding credentials, see [Add credentials](../active-directory/develop/quickstart-register-app.md#add-credentials). |
44 | 40 |
|
45 |
| -The application requires a client secret to prove its identity when requesting a token. To create a client secret, follow these steps. |
| 41 | +### Add a client secret |
46 | 42 |
|
47 |
| -1. Under **Manage** section, select **Certificates & secrets** |
48 |
| -1. On the **Client secrets** tab, click **New client secret**. |
49 |
| -  |
50 |
| -1. Enter a **description** for the client secret, and choose a **expire time**. |
51 |
| -1. Copy the value of the **client secret** and then paste it to a secure location. |
52 |
| - > [!NOTE] |
53 |
| - > The secret will display only once. |
| 43 | +The application requires a client secret for a client to prove its identity when it requests a token. |
54 | 44 |
|
55 |
| -### Certificate |
| 45 | +To create a client secret: |
56 | 46 |
|
57 |
| -You can also upload a certification instead of creating a client secret. |
| 47 | +1. On the left menu under **Manage**, select **Certificates & secrets**. |
| 48 | +1. On the **Client secrets** tab, select **New client secret**. |
58 | 49 |
|
59 |
| - |
| 50 | + :::image type="content" source="media/howto-authorize-from-application/new-client-secret.png" alt-text="Screenshot that shows creating a client secret."::: |
| 51 | + |
| 52 | +1. Enter a description for the client secret, and then choose an **Expires** time for the secret. |
| 53 | +1. Copy the value of the client secret, and then paste it to a secure location to save for later use. |
| 54 | + |
| 55 | + > [!NOTE] |
| 56 | + > The secret is visible only when you create the secret. You can't view the client secret in the portal later. |
60 | 57 |
|
61 |
| -To learn more about adding credentials, see |
| 58 | +### Add a certificate |
62 | 59 |
|
63 |
| -- [Add credentials](../active-directory/develop/quickstart-register-app.md#add-credentials) |
| 60 | +You can upload a certificate instead of creating a client secret. |
64 | 61 |
|
65 |
| -## Add role assignments on Azure portal |
| 62 | +:::image type="content" source="media/howto-authorize-from-application/upload-certificate.png" alt-text="Screenshot that shows uploading a certificate."::: |
66 | 63 |
|
67 |
| -This sample shows how to assign a `Web PubSub Service Owner` role to a service principal (application) over a Web PubSub resource. |
| 64 | +## Add a role assignment in the Azure portal |
| 65 | + |
| 66 | +This section demonstrates how to assign a Web PubSub Service Owner role to a service principal (application) for a Web PubSub resource. |
68 | 67 |
|
69 | 68 | > [!NOTE]
|
70 |
| -> A role can be assigned to any scope, including management group, subscription, resource group or a single resource. To learn more about scope, see [Understand scope for Azure RBAC](../role-based-access-control/scope-overview.md) |
| 69 | +> You can assign a role to any scope, including management group, subscription, resource group, and single resource. For more information about scope, see [Understand scope for Azure role-based access control](../role-based-access-control/scope-overview.md). |
71 | 70 |
|
72 |
| -1. On the [Azure portal](https://portal.azure.com/), navigate to your Web PubSub resource. |
| 71 | +1. In the [Azure portal](https://portal.azure.com/), go to your Web PubSub resource. |
73 | 72 |
|
74 |
| -1. Click **Access Control (IAM)** to display access control settings for the Azure Web PubSub. |
| 73 | +1. On the left menu, select **Access control (IAM)** to display access control settings for the resource. |
75 | 74 |
|
76 |
| -1. Click the **Role assignments** tab to view the role assignments at this scope. |
| 75 | +1. Select the **Role assignments** tab and view the role assignments at this scope. |
77 | 76 |
|
78 |
| - The following screenshot shows an example of the Access control (IAM) page for a Web PubSub resource. |
| 77 | + The following figure shows an example of the **Access control (IAM)** pane for a Web PubSub resource: |
79 | 78 |
|
80 |
| -  |
| 79 | + :::image type="content" source="media/howto-authorize-from-application/access-control.png" alt-text="Screenshot that shows an example of the Access control (IAM) pane."::: |
81 | 80 |
|
82 |
| -1. Click **Add > Add role assignment**. |
| 81 | +1. Select **Add** > **Add role assignment**. |
83 | 82 |
|
84 |
| -1. On the **Roles** tab, select `Web PubSub Service Owner`. |
| 83 | +1. Select the **Roles** tab, and then select **Web PubSub Service Owner**. |
85 | 84 |
|
86 |
| -1. Click **Next**. |
| 85 | +1. Select **Next**. |
87 | 86 |
|
88 |
| -  |
| 87 | + :::image type="content" source="media/howto-authorize-from-application/add-role-assignment.png" alt-text="Screenshot that shows adding a role assignment."::: |
89 | 88 |
|
90 |
| -1. On the **Members** tab, under **Assign access to** section, select **User, group, or service principal**. |
| 89 | +1. Select the **Members** tab. Under **Assign access to**, select **User, group, or service principal**. |
91 | 90 |
|
92 |
| -1. Click **Select Members** |
| 91 | +1. Choose **Select members**. |
93 | 92 |
|
94 |
| -1. Search for and select the application that you would like to assign the role to. |
| 93 | +1. Search for and select the application to assign the role to. |
95 | 94 |
|
96 |
| -1. Click **Select** to confirm the selection. |
| 95 | +1. Choose **Select** to confirm the selection. |
97 | 96 |
|
98 |
| -1. Click **Next**. |
| 97 | +1. Select **Next**. |
99 | 98 |
|
100 |
| -  |
| 99 | + :::image type="content" source="media/howto-authorize-from-application/assign-role-to-service-principals.png" alt-text="Screenshot that shows assigning a role to service principals."::: |
101 | 100 |
|
102 |
| -1. Click **Review + assign** to confirm the change. |
| 101 | +1. Select **Review + assign** to confirm the change. |
103 | 102 |
|
104 | 103 | > [!IMPORTANT]
|
105 |
| -> Azure role assignments may take up to 30 minutes to propagate. |
106 |
| -> To learn more about how to assign and manage Azure role assignments, see these articles: |
| 104 | +> Azure role assignments might take up to 30 minutes to propagate. |
| 105 | +
|
| 106 | +To learn more about how to assign and manage Azure role assignments, see these articles: |
107 | 107 |
|
108 |
| -- [Assign Azure roles using the Azure portal](../role-based-access-control/role-assignments-portal.yml) |
109 |
| -- [Assign Azure roles using the REST API](../role-based-access-control/role-assignments-rest.md) |
110 |
| -- [Assign Azure roles using Azure PowerShell](../role-based-access-control/role-assignments-powershell.md) |
111 |
| -- [Assign Azure roles using Azure CLI](../role-based-access-control/role-assignments-cli.md) |
112 |
| -- [Assign Azure roles using Azure Resource Manager templates](../role-based-access-control/role-assignments-template.md) |
| 108 | +- [Assign Azure roles by using the Azure portal](../role-based-access-control/role-assignments-portal.yml) |
| 109 | +- [Assign Azure roles by using REST API](../role-based-access-control/role-assignments-rest.md) |
| 110 | +- [Assign Azure roles by using Azure PowerShell](../role-based-access-control/role-assignments-powershell.md) |
| 111 | +- [Assign Azure roles by using the Azure CLI](../role-based-access-control/role-assignments-cli.md) |
| 112 | +- [Assign Azure roles by using an Azure Resource Manager template](../role-based-access-control/role-assignments-template.md) |
113 | 113 |
|
114 | 114 | ## Use Postman to get the Microsoft Entra token
|
115 | 115 |
|
116 |
| -1. Launch Postman |
| 116 | +1. Open Postman. |
117 | 117 |
|
118 |
| -2. For the method, select **GET**. |
| 118 | +1. For **Method**, select **GET**. |
119 | 119 |
|
120 |
| -3. For the **URI**, enter `https://login.microsoftonline.com/<TENANT ID>/oauth2/token`. Replace `<TENANT ID>` with the **Directory (tenant) ID** value in the **Overview** tab of the application you created earlier. |
| 120 | +1. For **URI**, enter `https://login.microsoftonline.com/<TENANT ID>/oauth2/token`. Replace `<TENANT ID>` with the value for **Directory (tenant) ID** on the **Overview** pane of the application you created. |
121 | 121 |
|
122 |
| -4. On the **Headers** tab, add **Content-Type** key and `application/x-www-form-urlencoded` for the value. |
| 122 | +1. Select the **Headers** tab, and then add the following keys and values: |
123 | 123 |
|
124 |
| -  |
| 124 | + 1. For **Key**, select **Content-Type**. |
| 125 | + 1. For **Value**, enter `application/x-www-form-urlencoded`. |
125 | 126 |
|
126 |
| -5. Switch to the **Body** tab, and add the following keys and values. |
127 |
| - 1. Select **x-www-form-urlencoded**. |
128 |
| - 2. Add `grant_type` key, and type `client_credentials` for the value. |
129 |
| - 3. Add `client_id` key, and paste the value of **Application (client) ID** in the **Overview** tab of the application you created earlier. |
130 |
| - 4. Add `client_secret` key, and paste the value of client secret you noted down earlier. |
131 |
| - 5. Add `resource` key, and type `https://webpubsub.azure.com` for the value. |
| 127 | + :::image type="content" source="media/howto-authorize-from-application/get-azure-ad-token-using-postman.png" alt-text="Screenshot that shows information on the Basic tab when you use Postman to get the token."::: |
132 | 128 |
|
133 |
| -  |
| 129 | +1. Select the **Body** tab. |
| 130 | +1. Select the body type **x-www-form-urlencoded**. |
| 131 | +1. Under **Key**, add the following keys and values: |
134 | 132 |
|
135 |
| -6. Select **Send** to send the request to get the token. You see the token in the `access_token` field. |
| 133 | + 1. Select **grant_type**, and then select the value **client_credentials**. |
| 134 | + 1. Select **client_id**, and then paste the value of **Application (client) ID** from the **Overview** pane of the application you created. |
| 135 | + 1. Select **client_secret**, and then paste the value of the client secret you saved. |
| 136 | + 1. Select **resource**, and then enter `https://webpubsub.azure.com` for the value. |
136 | 137 |
|
137 |
| -  |
| 138 | + :::image type="content" source="media/howto-authorize-from-application/get-azure-ad-token-using-postman-body.png" alt-text="Screenshot that shows the Body tab parameters when you use Postman to get the token."::: |
138 | 139 |
|
139 |
| -7. For oauth2/v2.0/token endpoint, pass the 'scope' instead of 'resource' |
| 140 | + For an OAuth2/v2.0/token endpoint, pass the value for `scope` instead of the value for `resource`: |
140 | 141 |
|
141 |
| - ``` |
142 |
| - client_id: *your client id* |
| 142 | + ```json |
| 143 | + client_id: *your client ID* |
143 | 144 | client_secret: *your client secret*
|
144 | 145 | grant_type: client_credentials
|
145 | 146 | scope: https://webpubsub.azure.com/.default
|
146 | 147 | ```
|
147 | 148 |
|
148 |
| -## Sample codes using Microsoft Entra authorization |
| 149 | +1. Select **Send** to send the request to get the token. The value for `access_token` is the access token. |
149 | 150 |
|
150 |
| -We officially support 4 programming languages: |
| 151 | + :::image type="content" source="media/howto-authorize-from-application/get-azure-ad-token-using-postman-response.png" alt-text="Screenshot that shows the response token when you use Postman to get the token."::: |
| 152 | + |
| 153 | +## Code samples that use Microsoft Entra authorization |
| 154 | + |
| 155 | +Get samples that use Microsoft Entra authorization in our four officially supported programming languages: |
151 | 156 |
|
152 | 157 | - [C#](./howto-create-serviceclient-with-net-and-azure-identity.md)
|
153 | 158 | - [Python](./howto-create-serviceclient-with-python-and-azure-identity.md)
|
154 | 159 | - [Java](./howto-create-serviceclient-with-java-and-azure-identity.md)
|
155 | 160 | - [JavaScript](./howto-create-serviceclient-with-javascript-and-azure-identity.md)
|
156 | 161 |
|
157 |
| -## Next steps |
158 |
| - |
159 |
| -See the following related articles: |
| 162 | +## Related content |
160 | 163 |
|
161 | 164 | - [Overview of Microsoft Entra ID for Web PubSub](concept-azure-ad-authorization.md)
|
162 |
| -- [Authorize request to Web PubSub resources with Microsoft Entra ID from managed identities](howto-authorize-from-managed-identity.md) |
| 165 | +- [Use Microsoft Entra ID to authorize a request from a managed identity to Web PubSub resources](howto-authorize-from-managed-identity.md) |
163 | 166 | - [Disable local authentication](./howto-disable-local-auth.md)
|
0 commit comments