abp icon indicating copy to clipboard operation
abp copied to clipboard

Authorize on appservice can not work

Open wingqing1314 opened this issue 6 years ago • 1 comments

I added [Authorize] on AppService can't work,but it works on the Controller .

context.Services.AddAuthentication(options =>
            {
                options.DefaultAuthenticateScheme = JwtBearerDefaults.AuthenticationScheme;
                options.DefaultChallengeScheme = JwtBearerDefaults.AuthenticationScheme;
            }).AddJwtBearer(options =>
            {
                options.TokenValidationParameters = parameters;
                options.Events = new JwtBearerEvents
                {
                    OnChallenge = context =>
                    {
                        context.HandleResponse();
                        var payload = "";
                        context.Response.ContentType = "application/json";
                        context.Response.StatusCode = StatusCodes.Status401Unauthorized;
                        context.Response.WriteAsync(payload);
                        return Task.FromResult(0);
                    }
                };
            });

wingqing1314 avatar May 22 '20 12:05 wingqing1314

I used wrong namespace 😭 be careful System.Web.Http and Microsoft.AspNetCore.Authorization

wingqing1314 avatar May 22 '20 12:05 wingqing1314