当从SSO Azure B2C msal.net的iFrame生成令牌时,为什么Request.IsAuthated为FALSE [英] Why Request.IsAuthenticated is false when token generated from iframe for SSO azure B2C msal .net

查看:18
本文介绍了当从SSO Azure B2C msal.net的iFrame生成令牌时,为什么Request.IsAuthated为FALSE的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有两个应用程序,一个是MVC Web应用程序,使用Msal.Net代码进行Azure ad B2C登录,第二个应用程序是使用相同Azure广告B2C登录的Power应用程序门户。我已经将iframe添加到这两个应用程序中,如果用户登录到任何一个应用程序中,都可以静默登录,在POWER应用程序门户上,它可以在所有浏览器上运行,如Chrome、Firefox、EDGE、OPERA。但对于MVC应用程序,它只能在Firefox浏览器上运行,除了Firefox之外,它的请求不会得到身份验证。当我调试iFrame请求时,能够看到获取令牌

IConfidentialClientApplication confidentialClient = MsalAppBuilder.BuildConfidentialClientApplication(new ClaimsPrincipal(notification.AuthenticationTicket.Identity));
Globals.ClientInfo = confidentialClient;
// Upon successful sign in, get & cache a token using MSAL
AuthenticationResult result = await confidentialClient.AcquireTokenByAuthorizationCode(Globals.Scopes, notification.Code).ExecuteAsync();
Globals.AuthenticationResult = result;
Globals.Claims = notification.AuthenticationTicket.Identity.Claims;
Globals.EncryptedClaim = notification.JwtSecurityToken.RawData;

但Into回调函数Request.IsAuthenticated为FALSE。

我的Web应用程序使用的是.Net框架4.7.1和Microsoft.Identity.Client版本4.29.0,请帮助我解决此问题。
另外,我在Chrome和Edge上的B2C回调方法出现以下错误,自动响应cookie被设置松懈而不是,这是否会导致为iframe设置cookie的问题。

谢谢,
桑迪

处理<authentication mode="Forms">时推荐答案为False,处理<authentication mode="Windows" />时为True。

因此,要解决此问题,请检查您的web.config中的身份验证模式。在您的web.config中添加以下代码:

<authentication mode="Forms">
  <forms loginUrl="~/_Login/Login" timeout="30" />
</authentication>

<system.webServer>
  <modules>
     <remove name="FormsAuthentication" />
     <add name="FormsAuthentication" type="System.Web.Security.FormsAuthenticationModule" />
  </modules>
<system.webServer>

在注册和配置中将答复URL设置为您的主主页URL,并确保应用程序ID和客户端ID匹配。

有关更多信息,请参阅以下链接:

如果您在成功登录后被重定向至登录页面,则需要更改CookieManger:

var cookieOptions = new CookieAuthenticationOptions();
cookieOptions.CookieManager = new SystemWebCookieManager(); 
app.UseCookieAuthentication(cookieOptions);

有关详细信息,请查看此document

这篇关于当从SSO Azure B2C msal.net的iFrame生成令牌时,为什么Request.IsAuthated为FALSE的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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