【问题标题】:What is the difference between services.AddAuthentication() and services.AddAuthorization() in asp net core?asp net core中的services.AddAuthentication()和services.AddAuthorization()有什么区别?
【发布时间】:2020-01-20 12:40:27
【问题描述】:

我有以下代码,我想了解这两种扩展方法之间的区别。每个人都做什么?

services.AddAuthentication (JwtBearerDefaults.AuthenticationScheme)
            .AddJwtBearer (options => options.TokenValidationParameters = new TokenValidationParameters {
                ValidateIssuer = true,
                    ValidateAudience = true,
                    ValidateLifetime = true,
                    ValidateIssuerSigningKey = true,
                    ClockSkew = TimeSpan.Zero,
                    ValidIssuer = Issuer,
                    ValidAudience = Audience,
                    IssuerSigningKey = new SymmetricSecurityKey(secret)
            });

            services.AddAuthorization();

谢谢,

【问题讨论】:

  • 一个添加身份验证。其他授权。一是你是谁。另一个是你能做什么。你读过docs.microsoft.com/en-us/aspnet/core/security/… 吗?
  • 我认为身份验证是用户发送他的凭据并且您使用数据库验证他的凭据,如果一切正确,您将返回一个令牌以用于授权。所以我的问题是这个方法如何向我的应用程序添加身份验证?

标签: c# asp.net-core jwt asp.net-authorization asp.net-authentication


【解决方案1】:

如果您知道这些术语之间的区别,那么了解这些方法之间区别的最佳方法可能是查看源代码并查看注册了哪些服务。

AddAuthentication

AddAuthorization

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-10-27
    • 2020-05-08
    • 1970-01-01
    • 1970-01-01
    • 2019-08-04
    • 2015-01-10
    相关资源
    最近更新 更多