Skip to content

Commit 3b45d9e

Browse files
authored
update signalr howto-authorize-application
1 parent b204038 commit 3b45d9e

File tree

1 file changed

+51
-63
lines changed

1 file changed

+51
-63
lines changed

articles/azure-signalr/signalr-howto-authorize-application.md

Lines changed: 51 additions & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -10,54 +10,28 @@ ms.devlang: csharp
1010
ms.custom: subject-rbac-steps
1111
---
1212

13-
# Authorize requests to Azure SignalR Service resources with Microsoft Entra applications
13+
# Authorize requests to Azure SignalR Service resources with Azure applications
1414

15-
Azure SignalR Service supports Microsoft Entra ID for authorizing requests from [Microsoft Entra applications](../active-directory/develop/app-objects-and-service-principals.md).
15+
Azure SignalR Service supports Microsoft Entra ID for authorizing requests from [Microsoft Entra applications](../entra/identity-platform/app-objects-and-service-principals.md).
1616

1717
This article shows how to configure your Azure SignalR Service resource and codes to authorize requests to the resource from a Microsoft Entra application.
1818

19-
## Register an application
19+
## Register an application in Microsoft Entra ID
2020

21-
The first step is to register a Microsoft Entra application:
22-
23-
1. In the [Azure portal](https://portal.azure.com/), search for and select **Microsoft Entra ID**.
24-
2. Under **Manage**, select **App registrations**.
25-
3. Select **New registration**. The **Register an application** pane opens.
26-
27-
![Screenshot of the pane for registering an application.](./media/signalr-howto-authorize-application/register-an-application.png)
28-
5. For **Name**, enter a display name for your application.
29-
6. Select **Register** to confirm the registration.
21+
The first step is to [Register an application in Microsoft Entra ID](../entra/identity-platform/quickstart-register-app?tabs=certificate%2Cexpose-a-web-api):
3022

3123
After you register your application, you can find the **Application (client) ID** and **Directory (tenant) ID** values on the application's overview page. These GUIDs can be useful in the following steps.
3224

3325
![Screenshot of overview information for a registered application.](./media/signalr-howto-authorize-application/application-overview.png)
3426

35-
To learn more about registering an application, see [Quickstart: Register an application with the Microsoft identity platform](../active-directory/develop/quickstart-register-app.md).
36-
3727
## Add credentials
3828

39-
You can add both certificates and client secrets (a string) as credentials to your confidential client app registration.
40-
41-
### Client secret
42-
43-
The application requires a client secret to prove its identity when it's requesting a token. To create a client secret, follow these steps:
44-
45-
1. Under **Manage**, select **Certificates & secrets**.
46-
1. On the **Client secrets** tab, select **New client secret**.
47-
48-
![Screenshot of selections for creating a client secret.](./media/signalr-howto-authorize-application/new-client-secret.png)
49-
1. Enter a description for the client secret, and choose an expiration time.
50-
1. Copy the value of the client secret and then paste it in a secure location.
51-
> [!NOTE]
52-
> The secret appears only once.
29+
After registering an app, you can add **certificates, client secrets (a string), or federated identity credentials** as credentials to your confidential client app registration. Credentials allow your application to authenticate as itself, requiring no interaction from a user at runtime, and are used by confidential client applications that access a web API.
5330

54-
### Certificate
31+
- [Add a certificate](../entra/identity-platform/quickstart-register-app?tabs=certificate%2Cexpose-a-web-api)
32+
- [Add a client secret](../entra/identity-platform/quickstart-register-app?tabs=client-secret%2Cexpose-a-web-api)
33+
- [Add a federated credential](../entra/identity-platform/quickstart-register-app?tabs=federated-credential%2Cexpose-a-web-api)
5534

56-
You can upload a certificate instead of creating a client secret.
57-
58-
![Screenshot of selections for uploading a certificate.](./media/signalr-howto-authorize-application/upload-certificate.png)
59-
60-
To learn more about adding credentials, see [Add credentials](../active-directory/develop/quickstart-register-app.md#add-credentials).
6135

6236
## Add role assignments in the Azure portal
6337

@@ -93,58 +67,72 @@ To learn more about how to assign and manage Azure roles, see these articles:
9367
- [Assign Azure roles using the Azure CLI](../role-based-access-control/role-assignments-cli.md)
9468
- [Assign Azure roles using Azure Resource Manager templates](../role-based-access-control/role-assignments-template.md)
9569

96-
## Configure your app
70+
## Microsoft.Azure.SignalR app server SDK for C#
9771

98-
### App server
72+
[Azure SignalR server SDK for C#](https://github.com/Azure/azure-signalr)
9973

100-
The best practice is to configure identity and credentials in your environment variables:
74+
### Use Microsoft Entra application with certificate
75+
```csharp
76+
services.AddSignalR().AddAzureSignalR(option =>
77+
{
78+
var credential = new ClientCertificateCredential("tenantId", "clientId", "path-to-cert");
10179

102-
| Variable | Description |
103-
| ------------------------------- | --------------------------------------------------------------------------------------------------------------- |
104-
| `AZURE_TENANT_ID` | The Microsoft Entra tenant ID. |
105-
| `AZURE_CLIENT_ID` | The client (application) ID of an app registration in the tenant. |
106-
| `AZURE_CLIENT_SECRET` | A client secret that was generated for the app registration. |
107-
| `AZURE_CLIENT_CERTIFICATE_PATH` | A path to a certificate and private key pair in PEM or PFX format, which can authenticate the app registration. |
108-
| `AZURE_USERNAME` | The username, also known as User Principal Name (UPN), of a Microsoft Entra user account. |
109-
| `AZURE_PASSWORD` | The password of the Microsoft Entra user account. A password isn't supported for accounts with multifactor authentication enabled. |
80+
option.Endpoints = [
81+
new ServiceEndpoint(new Uri(), "https://<resource>.service.signalr.net"), credential);
82+
];
83+
});
84+
```
11085

111-
You can use either [DefaultAzureCredential](/dotnet/api/azure.identity.defaultazurecredential) or [EnvironmentCredential](/dotnet/api/azure.identity.environmentcredential) to configure your Azure SignalR Service endpoints. Here's the code for `DefaultAzureCredential`:
86+
### Use Microsoft Entra application with client secret
11287

113-
```C#
88+
```csharp
11489
services.AddSignalR().AddAzureSignalR(option =>
11590
{
116-
option.Endpoints = new ServiceEndpoint[]
117-
{
118-
new ServiceEndpoint(new Uri("https://<resource-name>.service.signalr.net"), new DefaultAzureCredential())
119-
};
91+
var credential = new ClientSecretCredential("tenantId", "clientId", "clientSecret");
92+
93+
option.Endpoints = [
94+
new ServiceEndpoint(new Uri(), "https://<resource>.service.signalr.net"), credential);
95+
];
12096
});
12197
```
12298

123-
Here's the code for `EnvironmentCredential`:
99+
### Use Microsoft Entra application with Federated identity
124100

125-
```C#
101+
> [!NOTE]
102+
> Configure an application to trust a managed identity is a preview feature.
103+
> To learn more about it, see [Configure an application to trust a managed identity (preview)](../entra/workload-id/workload-identity-federation-config-app-trust-managed-identity).
104+
105+
```csharp
126106
services.AddSignalR().AddAzureSignalR(option =>
127107
{
128-
option.Endpoints = new ServiceEndpoint[]
108+
var msiCredential = new ManagedIdentityCredential("msiClientId");
109+
110+
var credential = new ClientAssertionCredential("tenantId", "appClientId", async (ctoken) =>
129111
{
130-
new ServiceEndpoint(new Uri("https://<resource-name>.service.signalr.net"), new EnvironmentCredential())
131-
};
112+
// Entra ID US Government: api://AzureADTokenExchangeUSGov
113+
// Entra ID China operated by 21Vianet: api://AzureADTokenExchangeChina
114+
var request = new TokenRequestContext([$"api://AzureADTokenExchange/.default"]);
115+
var response = await msiCredential.GetTokenAsync(request, ctoken).ConfigureAwait(false);
116+
return response.Token;
117+
});
118+
119+
option.Endpoints = [
120+
new ServiceEndpoint(new Uri(), "https://<resource>.service.signalr.net"), credential);
121+
];
132122
});
133123
```
134124

135-
To learn how `DefaultAzureCredential` works, see [DefaultAzureCredential class](/dotnet/api/overview/azure/identity-readme#defaultazurecredential).
136-
137-
#### Use endpoint-specific credentials
125+
### Use multiple endpoints
138126

139-
In your organization, you might want to use different credentials for different endpoints.
127+
Credentials can be different for different endpoints.
140128

141-
In this scenario, you can use [ClientSecretCredential](/dotnet/api/azure.identity.clientsecretcredential) or [ClientCertificateCredential](/dotnet/api/azure.identity.clientcertificatecredential):
129+
In this sample, the Azure SignalR SDK will connect to `resource1` with client secret and connect to `resource2` with certificate.
142130

143131
```csharp
144132
services.AddSignalR().AddAzureSignalR(option =>
145133
{
146134
var credential1 = new ClientSecretCredential("tenantId", "clientId", "clientSecret");
147-
var credential2 = new ClientCertificateCredential("tenantId", "clientId", "pathToCert");
135+
var credential2 = new ClientCertificateCredential("tenantId", "clientId", "path-to-cert");
148136

149137
option.Endpoints = new ServiceEndpoint[]
150138
{
@@ -154,7 +142,7 @@ services.AddSignalR().AddAzureSignalR(option =>
154142
});
155143
```
156144

157-
### Azure SignalR Service bindings in Azure Functions
145+
## Azure SignalR Service bindings in Azure Functions
158146

159147
Azure SignalR Service bindings in Azure Functions use [application settings](../azure-functions/functions-how-to-use-azure-function-app-settings.md) in the portal or [local.settings.json](../azure-functions/functions-develop-local.md#local-settings-file) locally to configure Microsoft Entra application identities to access your Azure SignalR Service resources.
160148

0 commit comments

Comments
 (0)