Chaitanya
Chaitanya

Reputation: 41

How to use Azure AD B2C with Xamarin Forms and SignalR Core

I'm trying to authorize a Xamarin Forms app to communicate with a SignalR hub in a ASP.NET Core Blazor Server app with Azure AD B2C configured. Login functionality in Xamarin Forms as well as in ASP.NET Core Blazor Server app is working fine with Azure AD B2C, but I'm not able to use [Authorize] on SignalR hub. I have tried to pass access token received from Azure AD B2C to HubConnectionBuilder as follows.

connection = new HubConnectionBuilder().
            WithAutomaticReconnect().
            WithUrl(Location + Name, options => { options.AccessTokenProvider = () => Task.FromResult(AccessToken); }).
            Build();

Upvotes: 1

Views: 287

Answers (1)

Chaitanya
Chaitanya

Reputation: 41

Adding following to Startup.cs in ASP.NET Core Blazor app solved the issue. I also used this authentication scheme to authorize the SignalR hub.

.AddAzureADB2CBearer(options => Configuration.Bind("AzureAdB2C", options));

Upvotes: 1

Related Questions