GetToken Unauthorized()
shiblydangdang opened this issue · 5 comments
shiblydangdang commented
Hi
We a have the following code in the GetToken method.....
if (response.ReturnValue == 0)
begin
;;Login failed, return 401 (unauthorized)
mreturn Unauthorized()
end
I want to be able to use ServiceUnavailable() instead of Unauthorized() but it's not available.
I've been able to use BadRequest().
If I hover over Unauthorized() or right-click and Go To Definition, it doesn't give me any info as to where this is defined.
Any ideas please?
Thanks
SteveIves commented
I hope you don't mind me saying so, but having an application return a 503 (Service Unavailable) is a bit of a weird choice. That status is generally something that would be sent a the web server when a served application is down. A definition of 503 is "The server is unable to process the request". Also, something to be aware of is that 500 status codes can be detrimental to your SEO, as search engines can prompt crawlers to slow down with crawling and remove indexed URLs that continually return these errors. Although I get that you may not care about that in the case of an internal app.
But, if you really want to do it, you could try something like this:
mreturn StatusCode(503, "Service is currently unavailable. Please try again later.");
Steve
From: shiblydangdang ***@***.***>
Sent: Friday, August 23, 2024 8:37 AM
To: Synergex/HarmonyCore ***@***.***>
Cc: Subscribed ***@***.***>
Subject: [EXTERNAL] [Synergex/HarmonyCore] GetToken Unauthorized() (Issue #371)
Hi
We a have the following code in the GetToken method.....
```
if (response.ReturnValue == 0)
begin
;;Login failed, return 401 (unauthorized)
mreturn Unauthorized()
end
I want to be able to use ServiceUnavailable() instead of Unauthorized() but it's not available.
I've been able to use BadRequest().
If I hover over Unauthorized() or right-click and Go To Definition, it doesn't give me any info as to where this is defined.
Any ideas please?
Thanks
-
Reply to this email directly, view it on GitHub<#371>, or unsubscribe<https://github.com/notifications/unsubscribe-auth/AAHUZIAFENSBG7AQDGNSAETZS5JJHAVCNFSM6AAAAABNANEDKGVHI2DSMVQWIX3LMV43ASLTON2WKOZSGQ4DGNBQGAYDMNI>.
You are receiving this because you are subscribed to this thread.Message ID: ***@***.******@***.***>>
CAUTION: This email originated from outside of Synergex. Please do not click links or open attachments from an unknown or suspicious sender.
SteveIves commented
Another thought. In the case of a failed login by a valid user that fat fingered their credentials, you would hope that the user retries. But if they see this, they're likely no not retry, and instead get frustrated with the app being down so frequently. Could generate support calls!
Steve
From: Steve Ives
Sent: Friday, August 23, 2024 9:41 AM
To: 'Synergex/HarmonyCore' ***@***.***>; Synergex/HarmonyCore ***@***.***>
Cc: Subscribed ***@***.***>
Subject: RE: [EXTERNAL] [Synergex/HarmonyCore] GetToken Unauthorized() (Issue #371)
I hope you don't mind me saying so, but having an application return a 503 (Service Unavailable) is a bit of a weird choice. That status is generally something that would be sent a the web server when a served application is down. A definition of 503 is "The server is unable to process the request". Also, something to be aware of is that 500 status codes can be detrimental to your SEO, as search engines can prompt crawlers to slow down with crawling and remove indexed URLs that continually return these errors. Although I get that you may not care about that in the case of an internal app.
But, if you really want to do it, you could try something like this:
mreturn StatusCode(503, "Service is currently unavailable. Please try again later.");
Steve
From: shiblydangdang ***@***.******@***.***>>
Sent: Friday, August 23, 2024 8:37 AM
To: Synergex/HarmonyCore ***@***.******@***.***>>
Cc: Subscribed ***@***.******@***.***>>
Subject: [EXTERNAL] [Synergex/HarmonyCore] GetToken Unauthorized() (Issue #371)
Hi
We a have the following code in the GetToken method.....
```
if (response.ReturnValue == 0)
begin
;;Login failed, return 401 (unauthorized)
mreturn Unauthorized()
end
I want to be able to use ServiceUnavailable() instead of Unauthorized() but it's not available.
I've been able to use BadRequest().
If I hover over Unauthorized() or right-click and Go To Definition, it doesn't give me any info as to where this is defined.
Any ideas please?
Thanks
-
Reply to this email directly, view it on GitHub<#371>, or unsubscribe<https://github.com/notifications/unsubscribe-auth/AAHUZIAFENSBG7AQDGNSAETZS5JJHAVCNFSM6AAAAABNANEDKGVHI2DSMVQWIX3LMV43ASLTON2WKOZSGQ4DGNBQGAYDMNI>.
You are receiving this because you are subscribed to this thread.Message ID: ***@***.******@***.***>>
CAUTION: This email originated from outside of Synergex. Please do not click links or open attachments from an unknown or suspicious sender.
shiblydangdang commented
Thanks for the info Steve. I didn't explain it very well. I don't want to replace 401, I just want other options and couldn't work out where Unauthorized was defined.
SteveIves commented
It's a method on the base class:
https://learn.microsoft.com/en-us/dotnet/api/microsoft.aspnetcore.mvc.controllerbase.unauthorized?view=aspnetcore-8.0
Steve
From: shiblydangdang ***@***.***>
Sent: Friday, August 23, 2024 9:51 AM
To: Synergex/HarmonyCore ***@***.***>
Cc: Steve Ives ***@***.***>; Comment ***@***.***>
Subject: [EXTERNAL] Re: [Synergex/HarmonyCore] GetToken Unauthorized() (Issue #371)
Thanks for the info Steve. I didn't explain it very well. I don't want to replace 401, I just want other options and couldn't work out where Unauthorized was defined.
-
Reply to this email directly, view it on GitHub<#371 (comment)>, or unsubscribe<https://github.com/notifications/unsubscribe-auth/AAHUZIAZ7TYJBFHYARZTYJDZS5R7PAVCNFSM6AAAAABNANEDKGVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDGMBXGQ2TMMJZGE>.
You are receiving this because you commented.Message ID: ***@***.******@***.***>>
CAUTION: This email originated from outside of Synergex. Please do not click links or open attachments from an unknown or suspicious sender.
shiblydangdang commented
Thanks Steve