SG-786 - Fix 400 error code log outs without invalid_grant#2156
Merged
SG-786 - Fix 400 error code log outs without invalid_grant#2156
Conversation
fedemkr
requested changes
Oct 28, 2022
src/Core/Services/ApiService.cs
Outdated
Comment on lines
+799
to
+811
| if (authed | ||
| && | ||
| ( | ||
| (tokenError && response.StatusCode == HttpStatusCode.BadRequest && responseJObject?["error"]?.ToString() == "invalid_grant") | ||
| || | ||
| (logoutOnUnauthorized && response.StatusCode == HttpStatusCode.Unauthorized) | ||
| || | ||
| response.StatusCode == HttpStatusCode.Forbidden | ||
| )) | ||
| { | ||
| await _logoutCallbackAsync(new Tuple<string, bool, bool>(null, false, true)); | ||
| return null; | ||
| } |
Member
There was a problem hiding this comment.
I'd split this in two:
In the same place as it was before I'd leave:
if (authed
&&
(
(logoutOnUnauthorized && response.StatusCode == HttpStatusCode.Unauthorized)
||
response.StatusCode == HttpStatusCode.Forbidden
))
{
await _logoutCallbackAsync(new Tuple<string, bool, bool>(null, false, true));
return null;
}and in on the new place:
if (authed && tokenError
&&
response.StatusCode == HttpStatusCode.BadRequest
&&
responseJObject?["error"]?.ToString() == "invalid_grant")
{
await _logoutCallbackAsync(new Tuple<string, bool, bool>(null, false, true));
return null;
}The reason behind this is that if let's say that the status code is HttpStatusCode.Unauthorized then it will waste time reading the response content; so splitting it like this we gain performance on those cases.
fedemkr
approved these changes
Oct 28, 2022
trmartin4
pushed a commit
that referenced
this pull request
Oct 31, 2022
* SG-786 - Added validation to check if the 400 error is invalid grant * SG 786 - Improved code quality (cherry picked from commit ee09c0a)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Type of change
Objective
Be more precise to force log out when receiving 400 error code by ensuring that the response error is invalid grant.
Code changes
This is related to the clients PR 400s only log out on invalid grant error #3924
Screenshots
Before you submit
dotnet format --verify-no-changes) (required)