标签: asp.net-identity

“where 子句”中的未知列“Extent1.Discriminator”

我正在使用 Visual Studio 2013 Web 表单应用程序和 MySql 数据库来构建 Web 表单应用程序,但我无法通过“成员资格和角色管理”。我对会员资格使用了数据库优先方法,当我尝试注册新用户时,收到以下错误消息:

Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code. 

Exception Details: MySql.Data.MySqlClient.MySqlException: Unknown column   'Extent1.Discriminator' in 'where clause'

Source Error: 


Line 16:             var manager = new UserManager();
Line 17:             var user = new ApplicationUser() { UserName = UserName.Text };
Line 18:             IdentityResult result = manager.Create(user, Password.Text);
Line 19: …
Run Code Online (Sandbox Code Playgroud)

mysql asp.net membership-provider entity-framework-6 asp.net-identity

1
推荐指数
1
解决办法
8947
查看次数

ASP.NET Core Identity 主键性能问题

ASP.NET 核心的默认实现Guid用作用户和角色表的主键。

我在这里担心的是,在 DB 设计过程中,开发人员经常需要将实体链接到用户 ID 作为外键,例如添加ModifiedByCreatedBy列进行审计,在这种情况下,外键将nvarchar(450)是远非有效的int执行JOINs 和其他类型的查询时的主键。

我知道我可以将身份核心配置为使用自定义主键类型,例如int,但出于安全考虑,我是否应该坚持默认配置(我不是安全专家)?

JOINint外键相比,字符串外键上的 s也不是非常慢(加上主键是 an 的组合,nvarchar这使得情况更糟)?

PS:在 ASP.NET 核心的上下文之外,我一般不会首先使用代码或 EF

asp.net-identity entity-framework-core .net-core asp.net-core

1
推荐指数
1
解决办法
537
查看次数

为什么使用 Identity Server 和 asp.net core 2 在基于令牌的身份验证上使用 cookie

我正在创建一个示例应用程序,以了解身份服务器 4 身份验证如何与 Asp.net core 2 一起工作。我注意到为不同级别生成了一些 cookie,如所附屏幕截图所示。我的问题是为什么会生成这些 cookie?

下面的语句,我取自 Identity Server 文档。身份服务器配置时

IdentityServer 使用自定义方案(通过常量 IdentityServerConstants.DefaultCookieAuthenticationScheme)在内部调用 AddAuthentication 和 AddCookie,

这里为什么它调用AddCookies身份服务器本身的方法?

此外,当我将 Asp.net 核心 Web 客户端配置为使用身份服务器身份验证时,它也会调用AddCookie()方法。当我尝试对其发表评论时,它会给我一个错误。我有点不清楚这里发生了什么。

身份服务器配置

services.AddIdentityServer()
                .AddDeveloperSigningCredential()
                .AddToDoUserStore()
                .AddInMemoryIdentityResources(Config.GetIdentityResources())
                .AddInMemoryApiResources(Config.GetApiResources())
                .AddInMemoryClients(Config.GetClients());

            services.AddAuthentication("MyCookie")
            .AddCookie("MyCookie", options =>
            {
                options.ExpireTimeSpan = new System.TimeSpan(0, 0, 15);
            });
Run Code Online (Sandbox Code Playgroud)

网页客户端配置

services.AddAuthentication(options =>
            {
                options.DefaultScheme = CookieAuthenticationDefaults.AuthenticationScheme;
                options.DefaultChallengeScheme = OpenIdConnectDefaults.AuthenticationScheme;
            })
            .AddCookie()
            .AddOpenIdConnect(options =>
            {
                options.Authority = "https://localhost:44377/";
                options.RequireHttpsMetadata = true;
                options.ClientId = "ToDoTaskManagmentClient";
                options.Scope.Clear();
                options.Scope.Add("openid");
                options.Scope.Add("profile");
                options.Scope.Add("address");
                options.Scope.Add("roles");
                options.Scope.Add("usertodoapi");
                options.Scope.Add("countries");
                options.Scope.Add("subscriptionlevel"); …
Run Code Online (Sandbox Code Playgroud)

c# asp.net asp.net-identity identityserver4 asp.net-core-2.0

1
推荐指数
2
解决办法
4889
查看次数

将参数传递给 Identity Server 4 登录页面

我有一个使用 IDSVR4 进行身份验证的客户端应用程序。我需要在客户端的会话或其他客户端数据存储机制中存储用户的用户名(与通过 IDSVR 登录的过程不同),以便用户每次登录时都不必输入详细信息特定浏览器。如何将用户名从客户端传递到身份服务器?

asp.net-mvc asp.net-identity asp.net-core identityserver4

1
推荐指数
1
解决办法
2607
查看次数

子声明缺少带有 Mongo DB 的 Identity Server 4

我正在将 Identity Server 4 与 MongoDB 一起使用来创建身份门户。

services.AddIdentityServer().AddMongoRepository()
                .AddMongoDbForAspIdentity<ApplicationUser, IdentityRole>(Configuration)
                .AddClients()
                .AddIdentityApiResources()
                .AddPersistedGrants()
                .AddDeveloperSigningCredential();


app.UseMongoDbForIdentityServer();
            app.UseIdentityServer();
Run Code Online (Sandbox Code Playgroud)

这是 Mongo Db 存储库

namespace IdentityServer.Extension
{
    public static class IdentityServerBuilderExtensions
    {/// <summary>
     /// Adds mongo repository (mongodb) for IdentityServer
     /// </summary>
     /// <param name="builder"></param>
     /// <returns></returns>
        public static IIdentityServerBuilder AddMongoRepository(this IIdentityServerBuilder builder)
        {
            builder.Services.AddTransient<IRepository, Repository>();
            return builder;
        }

        /// <summary>
        /// Adds mongodb implementation for the "Asp Net Core Identity" part (saving user and roles)
        /// </summary>
        /// <remarks><![CDATA[
        /// Contains implemenations for …
Run Code Online (Sandbox Code Playgroud)

c# asp.net mongodb asp.net-identity identityserver4

1
推荐指数
1
解决办法
1383
查看次数

User.Identity.Name 在我的 ASP.NET Core Web API 中为 null

我在一个具有一个数据库的项目中添加了 ASP.NET Core 标识和 Identity Server4,并且我想在所有其他项目中使用我的 Identity Server。

IdentityServer4 启动类

public class Startup
{
    public IConfigurationRoot Config { get; set; }

    public Startup(IConfiguration configuration)
    {
        Config = new ConfigurationBuilder()
                     .SetBasePath(Directory.GetCurrentDirectory())
                     .AddJsonFile("appsettings.json", false)
                     .Build();

        Configuration = configuration;
    }

    public IConfiguration Configuration { get; }

    public void ConfigureServices(IServiceCollection services)
    {
        IdentityModelEventSource.ShowPII = true;

        //=== Identity Config ===
        string ConnectionString = Config.GetSection("AppSettings:DefaultConnection").Value;
        var migrationAssembly = typeof(Startup).GetTypeInfo().Assembly.GetName().Name;

        //-----------------------------------------------------------------
        services.AddDbContext<MyIdentityDbContext>(options =>
             options.UseSqlServer(ConnectionString, sql => sql.MigrationsAssembly(migrationAssembly)));

        //-----------------------------------------------------------------
        services.AddIdentity<MyIdentityUser, IdentityRole>(op =>
        {
            op.Password.RequireDigit = false;
            op.Password.RequiredLength = …
Run Code Online (Sandbox Code Playgroud)

c# authentication authorization asp.net-identity identityserver4

1
推荐指数
2
解决办法
3780
查看次数

ASP.NET Core JWT 身份验证更改声明(子)

我有一个使用 JWT 身份验证的 ASP.NET Core API。简单的设置:

....
string authority = $"https://{configuration["Auth:Authority"]}";
string audience = configuration["Auth:Audience"];

return builder.AddJwtBearer(options =>
{
    options.Authority = authority;
    options.Audience = audience;

    options.TokenValidationParameters = new TokenValidationParameters
    {
        // NameClaimType = "http://schemas.org/email"
        // NameClaimType = "http://schemas.xmlsoap.org/ws/2005/05/identity/claims/email"
        // NameClaimType = "sub"
    };
});
Run Code Online (Sandbox Code Playgroud)

(正如您所看到的注释代码,我一直在尝试几种设置)

当我解码 JWT(使用 jwt.io)时,我看到 JWT 中有声明“sub”并且有字符串值(dbo 中用户的内部 ID)

{
  "nbf": 1592585433,
  "exp": 1592585763,
  "iss": "https://*************",
  "aud": "api_10",
  "sub": "142",
  "scope": [
    "openid",
    "api_10"
  ]
}
Run Code Online (Sandbox Code Playgroud)

问题是 dotnet 将 sub 切换到名称声明。这不返回 (0) 结果:

principal.Claims.Where(w => w.Type == …

c# jwt asp.net-identity asp.net-core identityserver4

1
推荐指数
1
解决办法
1397
查看次数

如何将表和关系添加到生成的 Asp.Net Core MVC Identity 数据库?

我有一个项目,我必须在其中创建一个 ASP.NET Core MVC Web 应用程序,我应该在其中包含用户注册、登录和具有基本 CRUD 操作和相应视图的 SQL 数据库。对于登录和注册,我决定按照本教程使用 Asp.Net Core Identity:https : //youtu.be/CzRM-hOe35o. 一切正常,注册和登录看起来都很好,但我不知道如何将我的数据库与 Identity 生成的数据库一起使用。我对项目数据库的想法是为用户和文章创建一个表(有更多的表,但我将保持简单来解释我的问题)具有一对多的关系。现在我有一个关于用户的所有事情的生成数据库(来自身份教程)我如何在数据库中包含这个文章表并在 AspNetUsers 和文章之间建立一对多的关系?或者我可以在我的项目中使用两个数据库,一个用于用户,另一个用于其他项目表?但是如何在不同数据库的表之间建立关系,甚至可能吗?

c# asp.net asp.net-mvc asp.net-identity asp.net-core

1
推荐指数
1
解决办法
2342
查看次数

在服务器端 Blazor 项目中构建身份时出错

我正在开发一个服务器端 Blazor 应用程序,该应用程序是使用为身份验证选择的“个人用户帐户”选项创建的。

我现在想自定义登录页面,但是当我选择通过脚手架添加身份页面时,我收到以下错误,我不知道从哪里开始进行故障排除。

无法在内存中编译项目

.OnInitializedAynsc() 找不到合适的方法来覆盖

为我的项目中的每个页面列出了上述错误。

在此处输入图片说明

asp.net-identity blazor blazor-server-side

1
推荐指数
1
解决办法
487
查看次数

.net core 3.1 Bearer error="invalid_token", error_description="受众'空'无效"

我有 3 个项目 1-Angular SPA 2-Web API 项目核心 3.1,3-IdentityServer with Core 3.1 但我收到以下错误

> www-authenticate: Bearer error="invalid_token", error_description="The audience 'empty' is invalid"
Run Code Online (Sandbox Code Playgroud)

这是我的 API 启动

 public void ConfigureServices(IServiceCollection services)
        {
            services.Configure<SchemaRegistryConfig>(Configuration.GetSection("SchemaRegistryConfig"));


            //identity server

            services.AddAuthentication(options =>
                {
                    options.DefaultAuthenticateScheme = JwtBearerDefaults.AuthenticationScheme;
                    options.DefaultChallengeScheme = JwtBearerDefaults.AuthenticationScheme;
                })
                .AddJwtBearer("Bearer", options =>
                {
                    options.Authority = "https://localhost:5002/";
                    options.RequireHttpsMetadata = false;
                    options.Audience = "Api";
                });


            IdentityModelEventSource.ShowPII = true;

           
            services.AddCors(c =>
            {
                c.AddPolicy("AllowOrigin", options => options.AllowAnyOrigin().AllowAnyMethod().AllowAnyHeader());
            });

            services.AddMvc(config =>
            {
                config.Filters.Add(typeof(UnhandledExceptionFilter));
                config.EnableEndpointRouting = false;
            }).SetCompatibilityVersion(CompatibilityVersion.Latest);

            services.AddServices(Configuration);
            services.AddHealthChecksUI();                
            
          
        }

        
        [Obsolete] …
Run Code Online (Sandbox Code Playgroud)

jwt asp.net-identity .net-core identityserver4

1
推荐指数
1
解决办法
2809
查看次数