This commit is contained in:
gowthaman 2024-05-09 14:18:18 +05:30
parent a889b48bd1
commit fc402e0232
2 changed files with 12 additions and 1 deletions

View File

@ -189,6 +189,7 @@ object Auth {
this.expiresAt = LocalDateTime.now().plusSeconds(atResponse.expiresIn.toLong())
this.refreshToken = atResponse.refreshToken
this.refreshExpiresAt = LocalDateTime.now().plusSeconds(atResponse.refreshExpiresIn.toLong())
this.refreshHistory = arrayListOf()
})
ctx.result(atResponse.accessToken).contentType(ContentType.TEXT_PLAIN)
}
@ -272,7 +273,15 @@ object Auth {
foundOldAt.expiresAt = LocalDateTime.now().plusSeconds(atResponse.expiresIn.toLong())
foundOldAt.refreshExpiresAt = LocalDateTime.now().plusSeconds(atResponse.refreshExpiresIn.toLong())
foundOldAt.refreshToken = atResponse.refreshToken
foundOldAt.refreshHistory = (foundOldAt.refreshHistory ?: arrayListOf()).apply {
add(RefreshHistory().apply {
oldAt = authUser.token
oldExpiryAt = expiresAt.format(DateTimeFormatter.ISO_LOCAL_DATE_TIME)
newAt = atResponse.accessToken
newExpiryAt = LocalDateTime.now().plusSeconds(atResponse.expiresIn.toLong()).format(DateTimeFormatter.ISO_LOCAL_DATE_TIME)
this.createdAt = LocalDateTime.now().format(DateTimeFormatter.ISO_LOCAL_DATE_TIME)
})
}
database.update(foundOldAt)
ctx.result(atResponse.accessToken).contentType(ContentType.TEXT_PLAIN)

View File

@ -709,4 +709,6 @@ open class AuthTokenCache : BaseModel() {
var expired: Boolean = false
var loggedOut: Boolean = false
@DbJsonB
var refreshHistory: MutableList<RefreshHistory>? = arrayListOf()
}