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 Net核心中的AWS Cognito JWT-如何验证每个用户对AWS服务的调用_Asp.net Core_.net Core_Jwt_Asp.net Core Webapi_Amazon Cognito - Fatal编程技术网

Asp.net core Net核心中的AWS Cognito JWT-如何验证每个用户对AWS服务的调用

Asp.net core Net核心中的AWS Cognito JWT-如何验证每个用户对AWS服务的调用,asp.net-core,.net-core,jwt,asp.net-core-webapi,amazon-cognito,Asp.net Core,.net Core,Jwt,Asp.net Core Webapi,Amazon Cognito,我有一个AWS Amplify前端,它从Cognito生成JWT令牌,我用它在Asp.net核心Web Api中对用户进行身份验证。我现在希望使用用户的凭据来调用AWS服务,以便使用Cloudtrail进行审计 我通常使用AWSSDK.Extensions.NetCore.Setup services.AddDefaultAWSOptions(Configuration.GetAWSOptions()) 我如何做到这一点 下面是Startup.cs中的ConfigureServices和Conf

我有一个AWS Amplify前端,它从Cognito生成JWT令牌,我用它在Asp.net核心Web Api中对用户进行身份验证。我现在希望使用用户的凭据来调用AWS服务,以便使用Cloudtrail进行审计

我通常使用AWSSDK.Extensions.NetCore.Setup
services.AddDefaultAWSOptions(Configuration.GetAWSOptions())

我如何做到这一点

下面是Startup.cs中的ConfigureServices和Configure方法

        public void ConfigureServices(IServiceCollection services)
    {
        services.AddControllers();

        services.AddAuthentication(options => options.DefaultScheme = JwtBearerDefaults.AuthenticationScheme)
            .AddJwtBearer(options =>
            {
                options.Audience = "xxxxxxxxxxxxxxxx";
                options.Authority = "https://cognito-idp.us-east-1.amazonaws.com/us-east-1_xxxxxx";
                options.RequireHttpsMetadata = false;   //set this to true for prod environments!
                options.SaveToken = true;
            });
    }

    // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
    public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
    {
        if (env.IsDevelopment())
        {
            app.UseDeveloperExceptionPage();
        }

        app.UseHttpsRedirection();
        app.UseRouting();
        app.UseAuthentication();
        app.UseAuthorization();

        app.UseEndpoints(endpoints =>
        {
            endpoints.MapControllers();
        });
    }