Skip to content

Commit 756925d

Browse files
authored
fix: Add authentication for primary email change through web (#285)
- Handle authentication error for email mismatch case fix: LEARNER-9919
1 parent 19930a9 commit 756925d

File tree

1 file changed

+14
-4
lines changed

1 file changed

+14
-4
lines changed

app/src/main/java/org/openedx/app/data/networking/OauthRefreshTokenAuthenticator.kt

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -68,10 +68,12 @@ class OauthRefreshTokenAuthenticator(
6868
return null
6969
}
7070

71-
val errorCode = getErrorCode(response.peekBody(200).string())
71+
val errorCode = getErrorCode(response.peekBody(Long.MAX_VALUE).string())
7272
if (errorCode != null) {
7373
when (errorCode) {
74-
TOKEN_EXPIRED_ERROR_MESSAGE, JWT_TOKEN_EXPIRED -> {
74+
TOKEN_EXPIRED_ERROR_MESSAGE,
75+
JWT_TOKEN_EXPIRED,
76+
-> {
7577
try {
7678
val newAuth = refreshAccessToken(refreshToken)
7779
if (newAuth != null) {
@@ -98,7 +100,10 @@ class OauthRefreshTokenAuthenticator(
98100
}
99101
}
100102

101-
TOKEN_NONEXISTENT_ERROR_MESSAGE, TOKEN_INVALID_GRANT_ERROR_MESSAGE, JWT_INVALID_TOKEN -> {
103+
TOKEN_NONEXISTENT_ERROR_MESSAGE,
104+
TOKEN_INVALID_GRANT_ERROR_MESSAGE,
105+
JWT_INVALID_TOKEN,
106+
-> {
102107
// Retry request with the current access_token if the original access_token used in
103108
// request does not match the current access_token. This case can occur when
104109
// asynchronous calls are made and are attempting to refresh the access_token where
@@ -118,7 +123,10 @@ class OauthRefreshTokenAuthenticator(
118123
}
119124
}
120125

121-
DISABLED_USER_ERROR_MESSAGE, JWT_DISABLED_USER_ERROR_MESSAGE -> {
126+
DISABLED_USER_ERROR_MESSAGE,
127+
JWT_DISABLED_USER_ERROR_MESSAGE,
128+
JWT_USER_EMAIL_MISMATCH,
129+
-> {
122130
runBlocking {
123131
appNotifier.send(LogoutEvent())
124132
}
@@ -241,6 +249,8 @@ class OauthRefreshTokenAuthenticator(
241249
private const val JWT_TOKEN_EXPIRED = "Token has expired."
242250
private const val JWT_INVALID_TOKEN = "Invalid token."
243251
private const val JWT_DISABLED_USER_ERROR_MESSAGE = "User account is disabled."
252+
private const val JWT_USER_EMAIL_MISMATCH =
253+
"Failing JWT authentication due to jwt user email mismatch with lms user email."
244254

245255
private const val FIELD_ERROR_CODE = "error_code"
246256
private const val FIELD_DETAIL = "detail"

0 commit comments

Comments
 (0)