现有 Asp.Net 核心应用程序中缺少 Azure Active Directory 连接服务的身份验证

Authentication with Azure Active Directory connected services missing in existing Asp.Net core application(现有 Asp.Net 核心应用程序中缺少 Azure Active Directory 连接服务的身份验证)
本文介绍了现有 Asp.Net 核心应用程序中缺少 Azure Active Directory 连接服务的身份验证的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

问题描述

我有现有的 Asp.net core 2.0 应用程序.我正在尝试向其添加使用 Azure Active Directory 连接服务的身份验证.当我尝试右键单击连接的服务并检查使用 Azure Active Directory 连接的服务进行身份验证时,我没有找到该选项.我在网上搜索,发现对于现有的 asp.net 核心应用程序,没有连接服务选项.在这种情况下会有什么解决方法?有什么提示吗?

I have existing Asp.net core 2.0 application. I am trying to add Authentication with Azure Active Directory connected service to it. When I tried to right click on connected services and checked for Authentication with Azure Active Directory connected service, I did not find the option. I searched online and found that for existing asp.net core applications there is not connected service option. What will be the work around in this case? any hints?

推荐答案

您可以尝试以下步骤:

  1. 安装包:Microsoft.AspNetCore.Authentication.AzureAD.UI

修改 Startup.cs 以启用 Azure AD 身份验证:

Modify the Startup.cs to enable Azure AD Authentication:

services.Configure<CookiePolicyOptions>(options =>
{
    // This lambda determines whether user consent for non-essential cookies is needed for a given request.
    options.CheckConsentNeeded = context => true;
    options.MinimumSameSitePolicy = SameSiteMode.None;
});

services.AddAuthentication(AzureADDefaults.AuthenticationScheme)
    .AddAzureAD(options => Configuration.Bind("AzureAd", options));

services.AddMvc().SetCompatibilityVersion(CompatibilityVersion.Version_2_1);

  • 将认证中间件添加到配置中:

  • Add the authentication middleware to Configure :

    app.UseAuthentication();
    

  • 修改 appsettings.json 以添加 Azure AD 应用设置

  • Modify the appsettings.json to add the Azure AD app settings

    {
    "AzureAd": {
        "Instance": "https://login.microsoftonline.com/",
        "Domain": "xxxxxxx.onmicrosoft.com",
        "TenantId": "xxxxxx-e83b-4099-93c2-8ae86358d05c",
        "ClientId": "xxxxxxxx-80c5-4bd4-ad6a-a967ea0066d6",
        "CallbackPath": "/signin-oidc"
    },
    "Logging": {
        "LogLevel": {
        "Default": "Warning"
        }
    },
    "AllowedHosts": "*"
    }
    

  • 另一种方法是手动配置 OpenId Connect Middlerware,您可以参考以下文章:

    Another way is to config the OpenId Connect Middlerware manually , you can refer to below article :

    https://joonasw.net/view/aspnet-core-2-azure-ad-authentication

    这篇关于现有 Asp.Net 核心应用程序中缺少 Azure Active Directory 连接服务的身份验证的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

    本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

    相关文档推荐

    MSBuild cannot find a reference(MSBuild 找不到参考)
    The reference assemblies for framework .NETCore, Version=v5.0 were not found(未找到框架 .NETCore,Version=v5.0 的参考程序集)
    quot;File has a different computed hash than specified in manifestquot; error when signing the EXE(“文件的计算哈希值与清单中指定的不同签署EXE时出错)
    MS-Build BeforeBuild not firing(MS-Build BeforeBuild 未触发)
    Using C# 7.1 with MSBuild(将 C# 7.1 与 MSBuild 结合使用)
    Build project with Microsoft.Build API(使用 Microsoft.Build API 构建项目)