Skip to content

Commit 9fbbe7f

Browse files
authored
SignalR: Cross tenant authorization with Microsoft Entra
1 parent 960e3ec commit 9fbbe7f

File tree

4 files changed

+219
-17
lines changed

4 files changed

+219
-17
lines changed

articles/azure-signalr/signalr-concept-authorize-azure-active-directory.md

Lines changed: 18 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
---
22
title: Authorize access with Microsoft Entra ID for Azure SignalR Service
3-
description: This article provides information on authorizing access to Azure SignalR Service resources by using Microsoft Entra ID.
4-
author: vicancy
5-
ms.author: lianwei
6-
ms.date: 09/06/2021
3+
description: This article explains how to authorize requests to Azure SignalR Service resources using Microsoft Entra ID.
4+
author: terencefan
5+
ms.author: tefa
6+
ms.date: 03/12/2025
77
ms.service: azure-signalr-service
88
ms.topic: conceptual
99
---
1010

11-
# Authorize access with Microsoft Entra ID for Azure SignalR Service
11+
# Microsoft Entra ID for Azure SignalR Service
1212

1313
Azure SignalR Service supports Microsoft Entra ID for authorizing requests to its resources. With Microsoft Entra ID, you can use role-based access control (RBAC) to grant permissions to a *security principal*. A security principal is a user/resource group, an application, or a service principal such as system-assigned identities and user-assigned identities.
1414

@@ -86,12 +86,20 @@ You can scope access to Azure SignalR Service resources at the following levels,
8686

8787
## Next steps
8888

89-
- To learn how to create an Azure application and use Microsoft Entra authorization, see [Authorize requests to Azure SignalR Service resources with Microsoft Entra applications](./signalr-howto-authorize-application.md).
89+
- To learn how to configure Microsoft Entra authorization, see:
9090

91-
- To learn how to configure a managed identity and use Microsoft Entra authorization, see [Authorize requests to Azure SignalR Service resources with Microsoft Entra managed identities](./signalr-howto-authorize-managed-identity.md).
91+
- [Authorize requests to Azure SignalR Service resources with Microsoft Entra applications](./signalr-howto-authorize-application.md).
92+
- [Authorize requests to Azure SignalR Service resources with Managed identities for Azure resources](./signalr-howto-authorize-managed-identity.md).
9293

93-
- To learn more about roles and role assignments, see [What is Azure role-based access control (Azure RBAC)?](../role-based-access-control/overview.md).
94+
- To learn more about roles-based access control and role, see:
9495

95-
- To learn how to create custom roles, see [Steps to create a custom role](../role-based-access-control/custom-roles.md#steps-to-create-a-custom-role).
96+
- [What is Azure role-based access control (Azure RBAC)?](../role-based-access-control/overview.md).
97+
- [Steps to create a custom role](../role-based-access-control/custom-roles.md#steps-to-create-a-custom-role).
9698

97-
- To learn how to use only Microsoft Entra authentication, see [Disable local authentication](./howto-disable-local-auth.md).
99+
- To learn how to configure cross tenant authorization with Microsoft Entra, see:
100+
101+
- [How to configure cross tenant authorization with Microsoft Entra](signalr-howto-authorize-cross-tenant.md)
102+
103+
- To learn how to disable connection string and use only Microsoft Entra authentication, see:
104+
105+
- [How to disable local authentication](./howto-disable-local-auth.md).

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

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ title: Authorize requests to Azure SignalR Service resources with Microsoft Entr
33
description: This article provides information about authorizing requests to Azure SignalR Service resources by using Microsoft Entra applications.
44
author: terencefan
55
ms.author: tefa
6-
ms.date: 03/14/2023
6+
ms.date: 03/12/2023
77
ms.service: azure-signalr-service
88
ms.topic: how-to
99
ms.devlang: csharp
@@ -195,6 +195,7 @@ In the Azure portal, add settings as follows:
195195

196196
See the following related articles:
197197

198-
- [Authorize access with Microsoft Entra ID for Azure SignalR Service](signalr-concept-authorize-azure-active-directory.md)
199-
- [Authorize requests to Azure SignalR Service resources with Microsoft Entra managed identities](signalr-howto-authorize-managed-identity.md)
200-
- [Disable local authentication](./howto-disable-local-auth.md)
198+
- [Microsoft Entra ID for Azure SignalR Service](signalr-concept-authorize-azure-active-directory.md)
199+
- [Authorize requests to Azure SignalR Service resources with Managed identities for Azure resources](./signalr-howto-authorize-managed-identity.md).
200+
- [How to configure cross tenant authorization with Microsoft Entra](signalr-howto-authorize-cross-tenant.md)
201+
- [How to disable local authentication](./howto-disable-local-auth.md)
Lines changed: 192 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,192 @@
1+
---
2+
title: Cross tenant authorization with Microsoft Entra
3+
description: This article provides information about building multitenant applications and configure authorization in SignalR.
4+
author: terencefan
5+
ms.author: tefa
6+
ms.date: 03/12/2023
7+
ms.service: azure-signalr-service
8+
ms.topic: how-to
9+
ms.devlang: csharp
10+
ms.custom: subject-rbac-steps
11+
---
12+
13+
# Cross tenant authorization with Microsoft Entra
14+
15+
For security reasons, your server may host in a independent tenant from your Azure SignalR resource.
16+
17+
Since managed identity can not be used across tenants, you'll need to register an application in `tenantA` and then provision it as an enterprise application in `tenantB`.
18+
19+
This doc will help you create an application in `tenantA` and use it to connect to a SignalR resource in `tenantB`.
20+
21+
## Register a multitenant application in tenant A
22+
23+
The first step is to create a multitenant application.
24+
25+
> In the case that you've already have a single tenant application.
26+
>
27+
> [Convert single-tenant app to multitenant on Microsoft Entra ID](/entra/identity-platform/howto-convert-app-to-be-multi-tenant)
28+
29+
[Quickstart: Register an application in Microsoft Entra ID](/entra/identity-platform/quickstart-register-app)
30+
31+
There will be 4 account types:
32+
33+
1. Accounts in this organizational directory
34+
2. Accounts in any organizational directory
35+
3. Accounts in any organizational directory and personal Microsoft accounts
36+
4. Personal Microsoft accounts
37+
38+
Be sure to select either 2 or 3 when creating the application.
39+
40+
![Screenshot of overview information for a registered application.](./media/signalr-howto-authorize-application/application-overview.png)
41+
42+
Note down the **Application (client) ID** and **Directory (tenant) ID**, they can be useful in the following steps.
43+
44+
## Provision the application in tenant B
45+
46+
The role cannot be assigned to the application registered in other tenants. We have to provision it as an external enterprise application in the tenant B.
47+
48+
Click to learn [differences between App registration and Enterprise applications](/answers/questions/270680/app-registration-vs-enterprise-applications).
49+
50+
For short, the enterprise application is a service principal, while the app registration is not. The enterprise application will inherit certain properties from the application object, such as **Application (client) ID**.
51+
52+
A default service principal will be created in the tenant where the app is registered. For other tenants, you'll need to provision the app to get an enterprice application service principal, see:
53+
54+
[Create an enterprise application from a multitenant application in Microsoft Entra ID](/entra/identity/enterprise-apps/create-service-principal-cross-tenant)
55+
56+
Enterprise applications in different tenant will have different **Directory (tenant) ID**, but share the same **Application (client) ID**.
57+
58+
## Assign roles to the enterprise application
59+
60+
Once you have the enterprise application provisioned in your tenant B. You will be able to assign roles to it.
61+
62+
[!INCLUDE [add role assignments](includes/signalr-add-role-assignments.md)]
63+
64+
## Configure SignalR SDK to use the enterprise application
65+
66+
There are 3 different types of credentials for an application to authenticate itself:
67+
68+
- Certificates
69+
- Client secrets
70+
- Federated identity
71+
72+
We strongly recommend you to use the first 2 ways to make cross tenant requests.
73+
74+
### Use Certificates or Client secrets
75+
76+
- `tenantId` should be the ID of your **Tenant B**.
77+
- `clientId` in both tenants are equal.
78+
- `clientSecret` and `clientCert` should be configured in **Tenant A**, see [Add credentials](/entra/identity-platform/quickstart-register-app?tabs=certificate%2Cexpose-a-web-api#add-credentials)
79+
80+
If you are not sure about your tenant ID, see [Find your Microsoft Entra tenant](/azure/azure-portal/get-subscription-tenant-id#find-your-microsoft-entra-tenant)
81+
82+
```csharp
83+
services.AddSignalR().AddAzureSignalR(option =>
84+
{
85+
var credential1 = new ClientSecretCredential("tenantId", "clientId", "clientSecret");
86+
var credential2 = new ClientCertificateCredential("tenantId", "clientId", "path-to-cert");
87+
88+
option.Endpoints = new ServiceEndpoint[]
89+
{
90+
new ServiceEndpoint(new Uri("https://<resource1>.service.signalr.net"), credential1),
91+
new ServiceEndpoint(new Uri("https://<resource2>.service.signalr.net"), credential2),
92+
};
93+
});
94+
```
95+
96+
### Use Federated identity
97+
98+
However, for security reasons, certificates and client secrets might be disabled in your subscription. In this case, you'll need to either use an external identity providor or try the preview support for managed identity.
99+
100+
- [Configure an app to trust an external identity provider](/entra/workload-id/workload-identity-federation-create-trust)
101+
- [Configure an application to trust a managed identity (preview)](/entra/workload-id/workload-identity-federation-config-app-trust-managed-identity)
102+
103+
You can check this repo: [Entra Cross-Tenant Application Federated Identity Credential (FIC)](https://github.com/arsenvlad/entra-cross-tenant-app-fic-managed-identity) for detailed info and video guide.
104+
105+
When using managed identity as an identity provider, the code should look like this:
106+
107+
- `tenantId` should be the ID of your **Tenant B**.
108+
- `clientId` in both tenants are equal.
109+
110+
```csharp
111+
services.AddSignalR().AddAzureSignalR(option =>
112+
{
113+
var msiCredential = new ManagedIdentityCredential("msiClientId");
114+
115+
var credential = new ClientAssertionCredential("tenantId", "appClientId", async (ctoken) =>
116+
{
117+
// Entra ID US Government: api://AzureADTokenExchangeUSGov
118+
// Entra ID China operated by 21Vianet: api://AzureADTokenExchangeChina
119+
var request = new TokenRequestContext([$"api://AzureADTokenExchange/.default"]);
120+
var response = await msiCredential.GetTokenAsync(request, ctoken).ConfigureAwait(false);
121+
return response.Token;
122+
});
123+
124+
option.Endpoints = [
125+
new ServiceEndpoint(new Uri(), "https://<resource>.service.signalr.net"), credential);
126+
];
127+
});
128+
```
129+
130+
When using enternal identity providers, the code should look like this:
131+
132+
```csharp
133+
services.AddSignalR().AddAzureSignalR(option =>
134+
{
135+
var credential = new ClientAssertionCredential("tenantId", "appClientId", async (ctoken) =>
136+
{
137+
// Find your own way to get a token from the external identity provider.
138+
// The audience of the token should be "api://AzureADTokenExchange", as it is the recommended value.
139+
return "TheTokenYouGetFromYourExternalIdentityProvider";
140+
});
141+
142+
option.Endpoints = [
143+
new ServiceEndpoint(new Uri(), "https://<resource>.service.signalr.net"), credential);
144+
];
145+
});
146+
```
147+
148+
Debugging token acquisition with the SignalR SDK can be challenging since it depends on the token results.
149+
We recommend testing the token acquisition process locally before integrating with the SignalR SDK.
150+
151+
```csharp
152+
var assertion = new ClientAssertionCredential("tenantId", "appClientId", async (ctoken) =>
153+
{
154+
// Find your own way to get a token from the external identity provider.
155+
// The audience of the token should be "api://AzureADTokenExchange", as it is the recommended value.
156+
return TheTokenYouGetFromYourExternalIdentityProvider;
157+
});
158+
159+
var request = new TokenRequestContext(["https://signalr.azure.com/.default");
160+
var token = await assertion.GetTokenAsync(assertion);
161+
Console.log(token.Token);
162+
```
163+
164+
The key point is to use an inner credential to get a `clientAssertion` from `api://AzureADTokenExchange` or other trusted identity platforms. Then use it to exchange for a token with `https://signalr.azure.com/.default` audience to access your resource.
165+
166+
Your goal is to get a token with following claims. Use [jwt.io](https://jwt.io/) to help you decode the token:
167+
168+
- **oid**
169+
170+
This should be equal to your enterprise application object ID.
171+
172+
If you don't know where to get it, see [How Retrieve Enterprise Object Id](/answers/questions/1007608/how-retrieve-enterprise-object-id-from-azure-activ)
173+
174+
- **tid**
175+
176+
This should be equal to the Directory ID of your tenant B.
177+
178+
If you are not sure about your tenant ID, see [Find your Microsoft Entra tenant](/azure/azure-portal/get-subscription-tenant-id#find-your-microsoft-entra-tenant)
179+
180+
- **audience**
181+
182+
Has to be `https://signalr.azure.com/.default` to access SignalR resources.
183+
184+
Good luck :)
185+
186+
## Next steps
187+
188+
See the following related articles:
189+
190+
- [Microsoft Entra ID for Azure SignalR Service](signalr-concept-authorize-azure-active-directory.md)
191+
- [Authorize requests to Azure SignalR Service resources with Microsoft Entra applications](signalr-howto-authorize-application.md)
192+
- [Authorize requests to Azure SignalR Service resources with Managed identities for Azure resources](./signalr-howto-authorize-managed-identity.md).

articles/azure-signalr/signalr-howto-authorize-managed-identity.md

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ title: Authorize requests to Azure SignalR Service resources with Microsoft Entr
33
description: This article provides information about authorizing requests to Azure SignalR Service resources by using Microsoft Entra managed identities.
44
author: terencefan
55
ms.author: tefa
6-
ms.date: 03/14/2025
6+
ms.date: 03/12/2023
77
ms.service: azure-signalr-service
88
ms.topic: how-to
99
ms.devlang: csharp
@@ -130,6 +130,7 @@ If you want to use a user-assigned identity, you need to assign `clientId` in ad
130130

131131
See the following related articles:
132132

133-
- [Authorize access with Microsoft Entra ID for Azure SignalR Service](signalr-concept-authorize-azure-active-directory.md)
133+
- [Microsoft Entra ID for Azure SignalR Service](signalr-concept-authorize-azure-active-directory.md)
134134
- [Authorize requests to Azure SignalR Service resources with Microsoft Entra applications](signalr-howto-authorize-application.md)
135-
- [Disable local authentication](./howto-disable-local-auth.md)
135+
- [How to configure cross tenant authorization with Microsoft Entra](signalr-howto-authorize-cross-tenant.md)
136+
- [How to disable local authentication](./howto-disable-local-auth.md)

0 commit comments

Comments
 (0)