Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/asp.net-core/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Asp.net core 将Azure AD电子邮件记录到ASP.NET标识表中_Asp.net Core_Azure Active Directory_Asp.net Identity - Fatal编程技术网

Asp.net core 将Azure AD电子邮件记录到ASP.NET标识表中

Asp.net core 将Azure AD电子邮件记录到ASP.NET标识表中,asp.net-core,azure-active-directory,asp.net-identity,Asp.net Core,Azure Active Directory,Asp.net Identity,我正在制作一个报告系统,允许用户使用Azure凭据登录,然后他们将订阅/取消订阅报告 它目前正在使用ASP.NET Identity,它工作得很好,但需要更多的It支持,因为人们会忘记他们的凭据等 如何将Azure凭据保存到ASP.NET标识中?与其他外部提供商(如Facebook等)一样,或者您是否会避免同时使用ASP.NET标识并将电子邮件地址保存到表中,并引用该表而不是ASP.NET标识版本 Startup.cs services.AddAuthentication

我正在制作一个报告系统,允许用户使用Azure凭据登录,然后他们将订阅/取消订阅报告

它目前正在使用ASP.NET Identity,它工作得很好,但需要更多的It支持,因为人们会忘记他们的凭据等

如何将Azure凭据保存到ASP.NET标识中?与其他外部提供商(如Facebook等)一样,或者您是否会避免同时使用ASP.NET标识并将电子邮件地址保存到表中,并引用该表而不是ASP.NET标识版本

Startup.cs

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

        services.Configure<OpenIdConnectOptions>(AzureADDefaults.OpenIdScheme, options =>
        {
            options.Authority = options.Authority + "/v2.0/";

            // Per the code below, this application signs in users in any Work and School
            // accounts and any Microsoft Personal Accounts.
            // If you want to direct Azure AD to restrict the users that can sign-in, change 
            // the tenant value of the appsettings.json file in the following way:
            // - only Work and School accounts => 'organizations'
            // - only Microsoft Personal accounts => 'consumers'
            // - Work and School and Personal accounts => 'common'

            // If you want to restrict the users that can sign-in to only one tenant
            // set the tenant value in the appsettings.json file to the tenant ID of this
            // organization, and set ValidateIssuer below to true.

            // If you want to restrict the users that can sign-in to several organizations
            // Set the tenant value in the appsettings.json file to 'organizations', set
            // ValidateIssuer, above to 'true', and add the issuers you want to accept to the
            // options.TokenValidationParameters.ValidIssuers collection
            options.TokenValidationParameters.ValidateIssuer = false;

            // Custom
            options.Scope.Add("email");
            //options.Scope.Add("profile");
            options.SaveTokens = true;
            options.GetClaimsFromUserInfoEndpoint = true;

            options.TokenValidationParameters = new TokenValidationParameters
            {
                NameClaimType = "name"
            };
        });
services.AddAuthentication(AzureAddFaults.AuthenticationScheme)
.AddAzureAD(options=>Configuration.Bind(“AzureAd”,options));
配置(AzureADDefaults.OpenIdScheme,选项=>
{
options.Authority=options.Authority+“/v2.0/”;
//根据下面的代码,此应用程序将在任何工作和学校的用户中登录
//帐户和任何Microsoft个人帐户。
//如果您想引导Azure广告限制可以登录的用户,请更改
//appsettings.json文件的租户值如下所示:
//-仅工作和学校账户=>“组织”
//-仅Microsoft个人帐户=>“消费者”
//-工作、学校和个人账户=>“普通”
//如果要限制只能登录到一个租户的用户
//将appsettings.json文件中的租户值设置为此文件的租户ID
//组织,并将下面的ValidateIssuer设置为true。
//如果要限制可以登录到多个组织的用户
//将appsettings.json文件中的租户值设置为“组织”,设置
//将上面的ValidateSuer设置为“true”,并将要接受的发行人添加到
//options.TokenValidationParameters.ValidisUsers集合
options.TokenValidationParameters.ValidateIssuer=false;
//习俗
选项。范围。添加(“电子邮件”);
//选项。范围。添加(“配置文件”);
options.SaveTokens=true;
options.GetClaimsFromUserInfoEndpoint=true;
options.TokenValidationParameters=新的TokenValidationParameters
{
NameClaimType=“name”
};
});
谢谢你的阅读

编辑:
现在,我只使用TokenValidated事件,然后使用UserManager和CreateAncy创建用户。

如果使用asp.net核心标识和Azure AD作为外部标识提供程序。使用AAD登录后,asp.net标识将帮助创建本地用户,用户可以输入其AAD电子邮件,以便在数据库中您可以知道哪个本地用户与特定的Azure AD用户关联。然后,您可以在本地数据库中实现自定义逻辑,如授权。但本地用户不会影响AAD用户,更改本地帐户的凭据不会影响云中AAD用户的凭据。下次,您仍然需要使用AAD作为身份提供者而不是本地用户帐户登录

您不需要也不应该将Azure凭据保存到本地数据库中。如果要重置特定用户的凭据,可以使用。您的管理员(IT)用户应具有更改租户中其他用户信息的正确权限(
user.ReadWrite.All
Directory.ReadWrite.All
委派权限)


是Microsoft Graph Auth文档,是ASP.NET核心的代码示例。

我不认为将Azure凭据保存到ASP.NET标识中是实现目标的有效方法

如果你想使用Azure凭据登录,你需要的是将Azure AD集成到你的ASP.NET核心Web应用程序中,使用户能够使用工作和学校帐户登录


快速入门的详细步骤/示例:和。

这正是我想要的,您登录AAD,ASP.NET Identity将为您创建一个本地帐户。我并不真正关心用户是否能够使用该本地帐户登录,它只是用来获取用户订阅报表时的电子邮件地址。我的两个想法是:;将电子邮件地址记录到一个表中,并在用户使用AAD登录后将其用作新的参考,或者将AAD与ASP.NET标识集成,这样,如果我添加了任何其他外部提供程序(没有任何计划这样做),我就可以在不更改任何数据库的情况下将其保持为标准。谢谢。是的,ASP.NET identity有一个表(
AspNetUserLogins
table)显示哪个本地用户与哪个身份提供商的哪个云用户关联。您可以检查,asp.net identity将允许用户在从外部提供商登录后输入其电子邮件地址,如果确认不存在与该帐户关联的本地用户,请不要忘记在AAD配置中使用
“CookieSchemeName”:“identity.external”
,如图所示