Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Why is 401 always returned in JwtBearerEvent OnChallenge? #17

Open
emilwkarlsson opened this issue Sep 24, 2020 · 3 comments
Open

Why is 401 always returned in JwtBearerEvent OnChallenge? #17

emilwkarlsson opened this issue Sep 24, 2020 · 3 comments

Comments

@emilwkarlsson
Copy link

When adding authentication in AddIdentityInfrastructure() in ServiceExtensions.cs, the code clearly states it should return 401 when OnChallenge event is invoked. Why is that? Nothing bad has really happened?

OnChallenge = context =>
                        {
                            context.HandleResponse();
                            context.Response.StatusCode = 401;
                            context.Response.ContentType = "application/json";
                            var result = JsonConvert.SerializeObject(new Response<string>("You are not Authorized"));
                            return context.Response.WriteAsync(result);
                        }

https://docs.microsoft.com/en-us/dotnet/api/microsoft.aspnetcore.authentication.jwtbearer.jwtbearerevents.onchallenge?view=aspnetcore-3.0

@hanatharesh2712
Copy link

@emilwkarlsson Make sure you are passing auth token with prefix like "Bearer {YOUR TOKEN HERE}". and it will resolve your issue

@sak1065
Copy link

sak1065 commented Oct 8, 2022

@emilwkarlsson"Taşıyıcı {KENDİNİZ BURADAKİ TOKEN}" gibi bir ön ek ile yetkilendirme belirtecini ilettiğinizden emin olun. ve sorununuzu çözecektir

hi, i sent expired token to api.
statuscode cannot be set because the response has already started.

what are you know this problem ?

thanks

@IldarY1
Copy link

IldarY1 commented Dec 28, 2022

@emilwkarlsson Make sure you are passing auth token with prefix like "Bearer {YOUR TOKEN HERE}". and it will resolve your issue

Maaaan, so many thanks to you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants