如何将 Azure AD B2C 与 Xamarin Forms 和 SignalR Core 结合使用 [英] How to use Azure AD B2C with Xamarin Forms and SignalR Core

查看:23
本文介绍了如何将 Azure AD B2C 与 Xamarin Forms 和 SignalR Core 结合使用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试授权 Xamarin Forms 应用与配置了 Azure AD B2C 的 ASP.NET Core Blazor 服务器应用中的 SignalR 中心进行通信.Xamarin Forms 以及 ASP.NET Core Blazor Server 应用程序中的登录功能在 Azure AD B2C 中运行良好,但我无法在 SignalR 集线器上使用 [授权].我已尝试将从 Azure AD B2C 收到的访问令牌传递给 HubConnectionBuilder,如下所示.

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();

推荐答案

将以下内容添加到 ASP.NET Core Blazor 应用程序中的 Startup.cs 解决了该问题.我还使用此身份验证方案来授权 SignalR 集线器.

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));

这篇关于如何将 Azure AD B2C 与 Xamarin Forms 和 SignalR Core 结合使用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆