authorization icon indicating copy to clipboard operation
authorization copied to clipboard

UNAUTHENTICATED error code

Open EbrahimMajdey opened this issue 4 years ago • 3 comments

I just need to know how to get the error code UNAUTHENTICATED because when I use .AuthorizeWith I am getting a VALIDATION_ERROR.

here is a bit of startup.cs

        services.AddAuthentication(options =>
            {
                options.DefaultAuthenticateScheme = JwtBearerDefaults.AuthenticationScheme;
                options.DefaultChallengeScheme = JwtBearerDefaults.AuthenticationScheme;
            })
            .AddJwtBearer();
            services.TryAddSingleton<IHttpContextAccessor, HttpContextAccessor>();
            services.TryAddSingleton<IAuthorizationEvaluator, AuthorizationEvaluator>();
            services.AddTransient<IValidationRule, AuthorizationValidationRule>();
            services.AddTransient((c) =>{
                               var authSettings = new AuthorizationSettings();
                           authSettings.AddPolicy("authenticated",p=>p.RequireClaim(ClaimTypes.Name));
                          return authSettings;
            );
            app.UseAuthentication();
            app.UseAuthorization();
            app.UseGraphQL<MySchema>("/api");

EbrahimMajdey avatar Mar 03 '21 02:03 EbrahimMajdey

These authorization rules for the GraphQL Schema are done through a GraphQL Validation rule, so you will only get validation errors. You will not get unauthenticated error codes as this framework is designed to work within the GraphQL context.

joemcbride avatar Mar 22 '21 16:03 joemcbride

Relates to https://github.com/graphql-dotnet/server/pull/480 and may be fixed in v4.

sungam3r avatar Mar 22 '21 17:03 sungam3r

@EbrahimMajdey see readme.md from #128. I expect to publish v4 soon.

sungam3r avatar Mar 23 '21 15:03 sungam3r