小编dea*_*t05的帖子

.AddOpenIdConnect() 中间件说明

因此,我尝试使用 ASP.NET Core 3.1 实现 OIDC 客户端应用程序。我正在尝试利用.AddOpenIdConnect().AddJswtBearer()中间件。但是,我需要澄清一下这个中间件的作用。

这是我目前的中间件配置:

.AddOpenIdConnect(options =>
{
    options.Authority = Configuration["auth:oidc:authority"];
    options.ClientId = Configuration["auth:oidc:clientid"];
    options.ClientSecret = Configuration["auth:oidc:clientsecret"];
    options.ResponseType = OpenIdConnectResponseType.Code;
    options.GetClaimsFromUserInfoEndpoint = true;
    options.SaveTokens = true;
})
.AddJwtBearer(options =>
{
    options.Authority = Configuration["auth:oidc:authority"];
    options.Audience = Configuration["auth:oidc:clientid"];
    options.TokenValidationParameters = new TokenValidationParameters
    {
        ValidateIssuer = true,
        ValidateAudience = true,
        ValidateLifetime = true,
        ValidIssuer = Configuration["auth:oidc:authority"],
        ValidAudience = Configuration["auth:oidc:clientid"],
        ValidateIssuerSigningKey = true,
        ClockSkew = TimeSpan.Zero
     };
}
Run Code Online (Sandbox Code Playgroud)

我注意到,根据下面的 Fiddler 捕获,应用程序首次启动时会请求对授权服务器/.well-known/oidc-configuration和端点的请求/.well-known/keys

Fiddler 捕获配置和密钥端点

它在哪里做到这一点?

我还尝试验证从授权服务器收到的 JWT …

c# authentication oauth-2.0 openid-connect asp.net-core

8
推荐指数
2
解决办法
2万
查看次数

.AddMvc() 在 ASP.NET Core 3.0 中?

我正在将 ASP.NET Core 2.2 Web 应用程序迁移到 3.0,并且有关于 .AddMvc() 的澄清问题。如果这很重要,我的应用程序使用 Razor 页面和视图。

所以目前,我在 2.2 代码中有以下内容:

services.AddMvc()
            .AddRazorPagesOptions(options =>
            {
                options.Conventions.ConfigureFilter(new IgnoreAntiforgeryTokenAttribute());
            })
           .SetCompatibilityVersion(CompatibilityVersion.Version_2_2);
Run Code Online (Sandbox Code Playgroud)

迁移文件说,“AddMvc继续表现为它在以前的版本。” 但是,接着说以下内容“与 2.2 中的 .AddMvc() 相同”:

    services.AddControllers();
    services.AddRazorPages();
Run Code Online (Sandbox Code Playgroud)

因此,我的问题是,我应该使用哪一种?

我的方法是做这样的事情:

    services.AddControllersWithViews();
    services.AddRazorPages()
            .AddRazorPagesOptions(options =>
             {
                 options.Conventions.ConfigureFilter(new IgnoreAntiforgeryTokenAttribute());
              })
              .SetCompatibilityVersion(CompatibilityVersion.Version_3_0);
Run Code Online (Sandbox Code Playgroud)

这是正确的方法吗?

谢谢!

.net asp.net-core

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

有时,ARM 模板在使用用户分配的托管身份时会抛出 PrimaryNotFound 错误

因此,我尝试使用 ARM 模板执行以下操作:

  1. my-managed-identity在资源组中创建新的用户分配的托管标识 ( )my-rg
  2. 分配my-managed-identity角色Readermy-rg
  3. 将角色分配Managed Identity Operator给 AKS 服务主体 ( my-aks-sp)my-managed-id

这是我的 ARM 模板:

{
    "$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#",
    "contentVersion": "1.0.0.0",
    "parameters": {
        "aksServicePrincipalObjectId": {
            "type": "string",
            "metadata": {
                "description": "The Object Id for the AKS Cluster Service Principal"
            }
        },
    },
    "variables": {
        "managedIdentityName": "my-managed-identity",
        "readerRole": "[concat('/subscriptions/', subscription().subscriptionId, '/providers/Microsoft.Authorization/roleDefinitions/', 'acdd72a7-3385-48ef-bd42-f606fba81ae7')]",
        "managedIdOperatorRole": "[concat('/subscriptions/', subscription().subscriptionId, '/providers/Microsoft.Authorization/roleDefinitions/', 'f1a07417-d97a-45cb-824c-7a7467783830')]"
    },
    "resources": [
        {
            "type": "Microsoft.ManagedIdentity/userAssignedIdentities",
            "name": "[variables('managedIdentityName')]",
            "apiVersion": "2018-11-30",
            "location": "[resourceGroup().location]", …
Run Code Online (Sandbox Code Playgroud)

azure azure-resource-manager

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