简体   繁体   English

如何将Asp.Net身份与Azure AD授权结合在一起

[英]How to combine Asp.Net Identity with Azure AD Authorization

How to integrate Asp.Net Identity with Azure AD Authorization 如何将Asp.Net身份与Azure AD授权集成

Is it possible to integrate Asp.Net Identity with Azure AD Authorization by means of OpenIdConnect? 是否可以通过OpenIdConnect将Asp.Net Identity与Azure AD授权集成在一起? I'd like to have a both authorization providers one for local authorization ( by means of standart Asp.net core Identity and second by means of Azure AD 我想同时拥有两个授权提供程序,一个用于本地授权(通过standart Asp.net核心身份,另一个通过Azure AD)

        _services
            .AddAuthentication(options =>
            {
                options.DefaultAuthenticateScheme = CookieAuthenticationDefaults.AuthenticationScheme;
                options.DefaultChallengeScheme = OpenIdConnectDefaults.AuthenticationScheme;
                options.DefaultScheme = CookieAuthenticationDefaults.AuthenticationScheme;
            })
            .AddOpenIdConnect(OpenIdConnectDefaults.AuthenticationScheme, options =>
            {
                options.SignInScheme = CookieAuthenticationDefaults.AuthenticationScheme;
                options.ClientId = clientId;
                options.ClientSecret = clientSecret;
                options.Authority = $"{baseAuthorityUrl}/{tenantId}/v2.0";
                options.CallbackPath = new PathString(callBackPath);
                options.Scope.Add("email");
                options.Scope.Add("profile");
                options.ResponseType = "code id_token";

                options.SaveTokens = true;
                options.GetClaimsFromUserInfoEndpoint = true;
                options.TokenValidationParameters = new TokenValidationParameters
                {
                    NameClaimType = "name"
                };
            })

This works for Azure AD Authorization, but i can't change authorization method from Azure AD to ASp.Net Identity. 这适用于Azure AD授权,但是我无法将授权方法从Azure AD更改为ASp.Net Identity。 Any help is much appreciated 任何帮助深表感谢

I'd suggest using the default ASP.NET Identity template to start the project : 我建议使用默认的ASP.NET Identity模板启动项目:

  1. Create new application with ASP.NET Identity (Individual User Accounts template). 使用ASP.NET标识(​​“个人用户帐户”模板)创建新的应用程序。

  2. Seed the database with Migrations Add-Migration Name , Update-Database . 使用Migrations Add-Migration Name Update-Database为数据库设置种子。

  3. Add your OIDC provider : 添加您的OIDC提供者:

     services .AddAuthentication(options => { options.DefaultChallengeScheme = OpenIdConnectDefaults.AuthenticationScheme; options.DefaultScheme = CookieAuthenticationDefaults.AuthenticationScheme; }).AddCookie() .AddOpenIdConnect(OpenIdConnectDefaults.AuthenticationScheme, options => { options.SignInScheme = IdentityConstants.ExternalScheme; options.ClientId = ClientId; options.ClientSecret = ClientSecret; options.Authority = $"{baseAuthorityUrl}/{tenantId}/v2.0"; options.CallbackPath = new PathString("/signin-oidc"); options.Scope.Add("email"); options.Scope.Add("profile"); options.ResponseType = "code id_token"; options.SaveTokens = true; options.GetClaimsFromUserInfoEndpoint = true; options.TokenValidationParameters = new TokenValidationParameters { NameClaimType = "name" }; }); 

Make sure using IdentityConstants.ExternalScheme for SignInScheme otherwise the Identity won't accept external login information correctly . 确保对SignInScheme使用IdentityConstants.ExternalScheme ,否则Identity将无法正确接受外部登录信息。

Asp.net will create a local account that associates your external account , so that you can perform authorization with your local identity system . Asp.net将创建一个与您的外部帐户关联的本地帐户,以便您可以使用本地身份系统执行授权。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 ASP.NET MVC如何将应用程序从ASP.NET身份转换为Azure AD - ASP.NET MVC How to convert application from ASP.NET Identity to Azure AD Azure AD 身份验证与 ASP.Net Core 6 中的自定义授权 - Azure AD Authentication with Custom Authorization in ASP.Net Core 6 使用 asp.net Identity 进行 Azure AD 身份验证以进行授权 - Azure AD authentication with asp.net Identity for authorisation Azure AD 身份验证对现有 ASP.NET 核心身份应用程序 - Azure AD authentication to existing ASP.NET Core Identity application Azure AD 与 ASP.NET 核心 MVC 中的标识 - Azure AD with Identity in ASP.NET Core MVC 如何在 ASP.NET Core 3 上同时使用 Azure AD 身份验证和标识? - How to use both Azure AD authentication and Identity on ASP.NET Core 3? 如何在 ASP.net core Identity 中实现基于权限的授权? - How to implement permission based authorization in ASP.net core Identity? ASP.NET身份动态角色授权 - ASP.NET Identity Dynamic Role Authorization 带有 ASP.NET 标识的自定义授权属性 - Custom Authorization attribute with ASP.NET Identity ASP.NET Core 2.0 Web API Azure Ad v2令牌授权无效 - ASP.NET Core 2.0 Web API Azure Ad v2 Token Authorization not working
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM