Skip to content
This repository has been archived by the owner on May 6, 2024. It is now read-only.

fix: App crash on primary email change from web #1848

Merged
merged 2 commits into from
Feb 23, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -59,16 +59,15 @@ class OauthRefreshTokenAuthenticator @Inject constructor(

@Synchronized
override fun authenticate(route: Route?, response: Response): Request? {
logger.warn(response.toString())
val responseBody = response.peekBody(Long.MAX_VALUE).string()
logger.warn(responseBody)

val currentAuth = loginPrefs.get().currentAuth
if (currentAuth?.refresh_token == null) {
return null
}

val errorCode = response.body?.let {
getErrorCode(it.string(), currentAuth.token_type)
} ?: return null
val errorCode = getErrorCode(responseBody, currentAuth.token_type) ?: return null

when (errorCode) {
TOKEN_EXPIRED_ERROR_MESSAGE,
Expand All @@ -80,6 +79,7 @@ class OauthRefreshTokenAuthenticator @Inject constructor(
requestBuilder.build()
}
}

TOKEN_NONEXISTENT_ERROR_MESSAGE,
TOKEN_INVALID_GRANT_ERROR_MESSAGE,
JWT_INVALID_TOKEN -> {
Expand All @@ -103,8 +103,10 @@ class OauthRefreshTokenAuthenticator @Inject constructor(
*/
EventBus.getDefault().post(LogoutEvent())
}

DISABLED_USER_ERROR_MESSAGE,
JWT_DISABLED_USER_ERROR_MESSAGE -> {
JWT_DISABLED_USER_ERROR_MESSAGE,
JWT_USER_EMAIL_MISMATCH -> {
EventBus.getDefault().post(LogoutEvent())
}
}
Expand Down Expand Up @@ -240,6 +242,8 @@ class OauthRefreshTokenAuthenticator @Inject constructor(
private const val JWT_DISABLED_USER_ERROR_MESSAGE = "User account is disabled."
private const val JWT_TOKEN_EXPIRED = "Token has expired."
private const val JWT_INVALID_TOKEN = "Invalid token."
private const val JWT_USER_EMAIL_MISMATCH =
"Failing JWT authentication due to jwt user email mismatch with lms user email."

/**
* [REFRESH_TOKEN_EXPIRY_THRESHOLD] behave as a buffer time to be used in the expiry
Expand Down
Loading