.Net Core Firebase带有JWT-401的Google电子邮件身份验证

fth*_*ins 6 c# authentication jwt firebase asp.net-core

我正在尝试firebase通过在.net coreWeb后端上使用电子邮件身份验证JWT。我找不到详细清晰的示例。

  1. 我成功登录我的android应用程序,然后得到IdToken

  2. 我在PostMan(或应用程序)上IdToken以前缀发送"Bearer"到我的控制器。但是它给401

无论我尝试了什么,我都无法得到200。只有401

我的服务配置:

services
    .AddAuthentication(o =>
    {
        o.DefaultAuthenticateScheme = JwtBearerDefaults.AuthenticationScheme;
        o.DefaultChallengeScheme = JwtBearerDefaults.AuthenticationScheme;
        o.DefaultScheme = JwtBearerDefaults.AuthenticationScheme;
    })
    .AddJwtBearer("Bearer", options =>
    {
        options.Authority = "https://securetoken.google.com/myapp-c1e32";
        options.SaveToken = true;
        options.TokenValidationParameters = new TokenValidationParameters
        {
            ValidateIssuer = true,
            ValidIssuer = "https://securetoken.google.com/myapp-c1e32",
            ValidateAudience = true,
            ValidAudience = "myapp-c1e32",
            ValidateLifetime = true
        };
    });
Run Code Online (Sandbox Code Playgroud)

我的控制器:

[Authorize(AuthenticationSchemes = JwtBearerDefaults.AuthenticationScheme)]
public ActionResult GetAllRoomsWithOtherInfos(int id)
{
    var rooms = _roomService.GetAllRoomsWithOtherInfos(id);
    return Ok(rooms);
}
Run Code Online (Sandbox Code Playgroud)

我的请求:

http://localhost:5000/Room/GetAllRoomsWithOtherInfos/1
Run Code Online (Sandbox Code Playgroud)

日志上的异常消息:

承载未认证。失败消息:IDX10501:签名验证失败。无法匹配密钥:

还有我的应用程序和服务配置

public void ConfigureServices(IServiceCollection services)
    {
        services.Configure<CookiePolicyOptions>(options =>
        {
            options.CheckConsentNeeded = context => true;
            options.MinimumSameSitePolicy = SameSiteMode.None;
        });
        services.AddDbContext<TaraftarServerContext>(options => options.UseMySql(Configuration.GetConnectionString(GlobalVariables.DbConnectionName)));
        services.AddMvc(options =>
            {
                options.Filters.Add<GlobalExceptionFilter>();
            })
            .SetCompatibilityVersion(CompatibilityVersion.Version_2_2)
            .AddJsonOptions(options => options.SerializerSettings.ContractResolver = new DefaultContractResolver())
            .AddFluentValidation();
        services.AddKendo();
        services.AddSignalR(hubOptions =>
            {
                hubOptions.EnableDetailedErrors = true;
            })
            .AddJsonProtocol(jsonOptions =>
            {
                jsonOptions.PayloadSerializerSettings.ContractResolver = new DefaultContractResolver();
                jsonOptions.PayloadSerializerSettings.NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore;
            });
        services.AddWebClientServices();

        // configure strongly typed settings objects
        var appSettingsSection = Configuration.GetSection("AppSettings");
        services.Configure<AppSettings>(appSettingsSection);

        // this method is above configuration where the jwt is ( My service Configuration:)
        services.AddFirebaseAuthentication(Configuration);

    }

    public void Configure(IApplicationBuilder app, IHostingEnvironment env)
    {
        if (env.IsDevelopment())
        {
            app.UseDeveloperExceptionPage();
        }
        else
        {
            app.UseExceptionHandler("/Home/Error");
            app.UseHsts();
        }

        app.UseHttpsRedirection();
        app.UseStaticFiles();
        app.UseAuthentication();

        var supportedCultures = new[]
        {
            new CultureInfo("tr")
        };

        app.UseRequestLocalization(
            new RequestLocalizationOptions
            {
                DefaultRequestCulture = new RequestCulture("tr"),
                SupportedCultures = supportedCultures,
                SupportedUICultures = supportedCultures,
                FallBackToParentCultures = true,
                FallBackToParentUICultures = true,
                RequestCultureProviders = null
            });

        app.UseMvc(routes =>
        {
            routes.MapRoute(
                name: "default",
                template: "{controller=Room}/{action=Index}/{id?}");
        });

    }
Run Code Online (Sandbox Code Playgroud)

.Net核心版本:2.2