An error: Bearer error=“invalid_token”, error_description=“The signature is invalid”

I tried to implement JWT authentication. This is my code. I'm trying to sigh in account and on the server I got an error: Bearer error=“invalid_token”, error_description=“The signature is invalid”. Can anyone help me. what I missed?

configureService code

public void ConfigureServices(IServiceCollection services) {
            services.AddAuthentication(JwtBearerDefaults.AuthenticationScheme)
                    .AddJwtBearer(options => {
                        options.RequireHttpsMetadata = false;
                        options.TokenValidationParameters = new TokenValidationParameters {
                            ValidateIssuer = false,
                            ValidateAudience = false,
                            ValidateLifetime = false,
                            IssuerSigningKey = new SymmetricSecurityKey(Encoding.ASCII.GetBytes(this.Configuration["Authorization:Token"])),
                            ValidateIssuerSigningKey = true,
                        };
                    });
            if (this.Environment.IsDevelopment()) {
            Swagger.ConfigureService(services);
            }
            services
                .AddControllersWithViews()
                .AddJsonOptions(options => options.JsonSerializerOptions.Converters.Add(new JsonStringEnumConverter()));
            // In production, the Angular files will be served from this directory
            services.AddSpaStaticFiles(configuration => {
                configuration.RootPath = "ClientApp/dist";
            });

            services.AddDataModule(this.Configuration);
            services.AddBusinessModule();
            services.AddHttpContextAccessor();
            services.AddSingleton<IAuthorizationPolicyProvider, PermissionPolicyProvider>();

            services.AddMvc().ConfigureApiBehaviorOptions(options => {
                        options.InvalidModelStateResponseFactory = CustomErrorResponse.BadRequestErrorResponse;
                    });
        }

configure

        [UsedImplicitly]
        public void Configure(IApplicationBuilder app, IWebHostEnvironment env) {
            if (env.IsDevelopment()) {
                Swagger.Configure(app);
            }
            app.ConfigureExceptionMiddleware();
            app.UseStaticFiles();
            if(!env.IsDevelopment()) {
                app.UseSpaStaticFiles();
            }
            app.UseRouting();
            app.UseAuthentication();
            app.ConfigureAuthMiddleware();
            app.UseAuthorization();
            app.UseEndpoints(endpoints => {
                endpoints.MapControllerRoute(name : "default",
                                             pattern : "{controller}/{action=Index}/{id?}");
            });
            app.UseSpa(spa => {
                spa.Options.SourcePath = "ClientApp";
                if(env.IsDevelopment()) {
                    spa.UseAngularCliServer(npmScript : "start");
                }
            });
        }

1 answer