当前位置: 首页 > 知识库问答 >
问题:

正在向现有.NET MVC应用程序添加Azure AD身份验证:id_token未验证

任昊阳
2023-03-14
app.SetDefaultSignInAsAuthenticationType(CookieAuthenticationDefaults.AuthenticationType);

// app.UseCookieAuthentication(new CookieAuthenticationOptions());
app.UseOpenIdConnectAuthentication(
                new OpenIdConnectAuthenticationOptions
                {
                    // Sets the ClientId, authority, RedirectUri as obtained from web.config
                    ClientId = clientId,
                    Authority = authority,
                    RedirectUri = redirectUri,
                    // PostLogoutRedirectUri is the page that users will be redirected to after sign-out. In this case, it is using the home page
                    PostLogoutRedirectUri = redirectUri,
                    Scope = OpenIdConnectScope.OpenIdProfile,
                    // ResponseType is set to request the id_token - which contains basic information about the signed-in user
                    ResponseType = OpenIdConnectResponseType.IdToken,
                    // ValidateIssuer set to false to allow personal and work accounts from any organization to sign in to your application
                    // To only allow users from a single organizations, set ValidateIssuer to true and 'tenant' setting in web.config to the tenant name
                    // To allow users from only a list of specific organizations, set ValidateIssuer to true and use ValidIssuers parameter
                    TokenValidationParameters = new TokenValidationParameters()
                    {
                        ValidateIssuer = true // Simplification (see note below)
                    },
                    // OpenIdConnectAuthenticationNotifications configures OWIN to send notification of failed authentications to OnAuthenticationFailed method
                    Notifications = new OpenIdConnectAuthenticationNotifications
                    {
                        AuthenticationFailed = OnAuthenticationFailed
                    }
                }
            );
<authentication mode="None"/>
if (!Request.IsAuthenticated)
{
    HttpContext.GetOwinContext().Authentication.Challenge(
                new AuthenticationProperties { RedirectUri = "http://localhost:54465" },
                OpenIdConnectAuthenticationDefaults.AuthenticationType);
}

我知道这应该在OpenID Connect中间件中自动发生,但是还有其他需要设置的吗?

共有1个答案

李星辰
2023-03-14

记住设置redirecturi,这与在azure AD中注册的应用程序相同。

我用你的代码测试,可以在应用程序中验证。在Azure ad应用注册中,单击身份验证并选择ID令牌

您可以参考本文并下载有关将Microsoft identity platform sign-in添加到ASP.NET web App的示例。

 类似资料:
  • 我想添加只允许经过身份验证的用户在Jitsi会议中创建会议的功能。我看到了外部API的jwt参数、config.tokenAuthUrl和lib-jitsi-met令牌文档,但我对如何将它们放在一起感到非常困惑。 现在,我的工作流程如下: 用户通过自定义应用程序登录谷歌。 用户被重定向到一个新的Jitsi会议,使用从Google登录信息派生的jwt参数。 我遇到的问题是验证这个令牌,以及如何设置它

  • 我有一个Spring应用程序,它使用Kafka实例而没有任何身份验证。 现在故事发生了变化,Kafka离开了应用程序并作为集群运行。我收到了Kafka凭据用户名和密码以及主机名:端口信息。 其他信息,我需要连接到Kafka集群。 是否需要进行任何代码更改?还是我只需要在应用程序配置文件.yaml文件中添加一些信息? 我尝试了Google中建议的不同方法,但似乎对我没有任何效果,我一直收到: 错误:

  • 在使用带有Keycloak的REST身份验证时,我的id_token为null(服务器端)。要连接到应用程序,我使用文档中提供的以下URI:(带有适当的表单参数grant_type、username、password,...请参阅此处)。作为响应(客户端),我可以检索access_token和id_token。然后,我正在使用HTTP头中的“承载”授权与服务器进行讨论。在使用我的自定义客户端时,服

  • 我已经安装了OpenLDAP服务器。 如何在LDAP服务器中添加用户(条目)?以及如何打开该服务器的命令窗口,以便在其上运行ldap命令: :我的要求是:在我的应用程序中,我想对Openldap服务器中添加的用户进行身份验证,但我只能在windows os上安装Openldap服务器,但如何添加用户我无法获得方法。在Windows7操作系统上安装openLDAP whic时添加用户的方法是什么?这

  • 我有一个使用Kafka Streams API的应用程序。我在当地工作时没有问题。我想连接到远程Kafka代理进行阶段测试。远程Kafka代理设置为使用GSSAPI sasl机制并使用Kerberos。我运行用java编写的Streams应用程序时出错。在我查找错误消息后,我找到了答案,但仍然有问题。 错误消息;获取相关id为3的元数据时出错:{[APPID]-KTABLE-AGGREGATE-S

  • 我需要在我们的Web应用程序中使用LDAP/AD服务器实现SSO身份验证和验证用户。Web应用程序是使用Spring(Java)/Hibernate制作的,应用程序服务器是UAT中的Jboss和生产中的Webphere。 我正在寻找一些好的简单的解决方案,可以帮助我实现它,从几个朋友那里听说华夫饼是一个很好的解决方案,但是在网上搜索并尝试了几天之后,我不确定我是否朝着正确的方向前进。我在这方面很幼