Last active
July 19, 2021 21:04
-
-
Save MoaidHathot/cd5707698351c7956206226c05f288b5 to your computer and use it in GitHub Desktop.
SignalR Aad Managed Identity Auth issue
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using Microsoft.AspNetCore.SignalR.Client; | |
using Microsoft.Extensions.Logging; | |
using System; | |
using System.Threading.Tasks; | |
namespace SignalRConsoleClient | |
{ | |
public static class Program | |
{ | |
public static async Task Main(string[] args) | |
{ | |
string endpoint = "https://<server-url>.azurewebsites.net/notifications"; | |
var connection = new HubConnectionBuilder() | |
.WithUrl(endpoint) | |
.ConfigureLogging(logging => logging.AddConsole()) | |
.WithAutomaticReconnect() | |
.Build(); | |
Console.WriteLine("Connecting..."); | |
await connection.StartAsync().ConfigureAwait(false); | |
Console.WriteLine("Connected."); | |
} | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using Microsoft.AspNetCore.Builder; | |
using Microsoft.AspNetCore.Hosting; | |
using Microsoft.AspNetCore.SignalR; | |
using Microsoft.Extensions.DependencyInjection; | |
using System; | |
using System.Threading.Tasks; | |
namespace SignalRRbacTest | |
{ | |
public class Startup | |
{ | |
public void ConfigureServices(IServiceCollection services) | |
{ | |
services.AddControllers(); | |
services | |
.AddSignalR() | |
.AddAzureSignalR(serviceOptions => | |
{ | |
//Don't work | |
//serviceOptions.ConnectionString = "Endpoint = https://<name>.service.signalr.net;AuthType=aad;Version=1.0;"; | |
//serviceOptions.ConnectionString = "Endpoint = https://<name>.service.signalr.net;AuthType=aad;ClientId=<clientId>;Version=1.0"; | |
//Works | |
//serviceOptions.ConnectionString = "Endpoint=https://<name>.service.signalr.net;AccessKey=<access-key>;Version=1.0;"; | |
}); | |
} | |
public void Configure(IApplicationBuilder app, IWebHostEnvironment env) | |
{ | |
app.UseDeveloperExceptionPage(); | |
app.UseHttpsRedirection(); | |
app.UseRouting(); | |
app.UseEndpoints(endpoints => | |
{ | |
endpoints.MapHub<ClientNotificationsHub>("/notifications"); | |
}); | |
} | |
} | |
public class ClientNotificationsHub : Hub | |
{ | |
public override async Task OnConnectedAsync() | |
{ | |
await Groups.AddToGroupAsync(Context.ConnectionId, "test-group").ConfigureAwait(false); | |
await base.OnConnectedAsync().ConfigureAwait(false); | |
} | |
public override async Task OnDisconnectedAsync(Exception? exception) | |
{ | |
await Groups.RemoveFromGroupAsync(Context.ConnectionId, "test-group").ConfigureAwait(false); | |
await base.OnDisconnectedAsync(exception).ConfigureAwait(false); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment