address logout
This commit is contained in:
parent
0a0e627b4a
commit
c4985f9690
@ -65,6 +65,7 @@ fun main(args: Array<String>) {
|
||||
get("/init", Auth::init)
|
||||
get("/code", Auth::code)
|
||||
get("/keys", Auth::keys)
|
||||
post("/logout", Auth::logout)
|
||||
post("/refresh", Auth::refreshToken)
|
||||
}
|
||||
before("/api/*") { ctx ->
|
||||
@ -80,9 +81,6 @@ fun main(args: Array<String>) {
|
||||
|
||||
setAuthorizedUser(validateAuthToken(authToken = authToken))
|
||||
|
||||
if (appConfig.enforcePayloadEncryption()) {
|
||||
//todo: decrypt the request from user
|
||||
}
|
||||
}
|
||||
after("/api/*") {
|
||||
|
||||
@ -94,9 +92,6 @@ fun main(args: Array<String>) {
|
||||
it.header("X-Checksum", outEncoded)
|
||||
it.header("X-Signature", signPayload(outEncoded))
|
||||
|
||||
if (appConfig.enforcePayloadEncryption()) {
|
||||
//todo: encrypt and send the response back to user
|
||||
}
|
||||
|
||||
}
|
||||
path("/api") {
|
||||
|
||||
@ -31,8 +31,6 @@ import java.util.*
|
||||
import java.util.concurrent.ConcurrentHashMap
|
||||
|
||||
|
||||
const val AUTH_TOKEN = "AUTH_TOKEN_V2"
|
||||
|
||||
private fun getFormDataAsString(formData: Map<String, String>): String {
|
||||
|
||||
return formData.entries.joinToString("&") {
|
||||
@ -193,6 +191,22 @@ object Auth {
|
||||
ctx.result(atResponse.accessToken).contentType(ContentType.TEXT_PLAIN)
|
||||
}
|
||||
|
||||
|
||||
fun logout(ctx: Context) {
|
||||
val authToken = ctx.header("Authorization")?.replace("Bearer ", "")?.replace("Bearer: ", "")?.trim()
|
||||
?: return
|
||||
val authUser = validateAuthToken(authToken, skipValidate = true)
|
||||
logger.warn("User ${authUser.userName} is logging out")
|
||||
database.updateAll(
|
||||
database.find(AuthTokenCache::class.java)
|
||||
.where()
|
||||
.eq("authToken", authToken)
|
||||
.findList()
|
||||
.onEach {
|
||||
it.loggedOut = true
|
||||
})
|
||||
}
|
||||
|
||||
fun refreshToken(ctx: Context) {
|
||||
//refresh authToken
|
||||
val authToken = ctx.header("Authorization")?.replace("Bearer ", "")?.replace("Bearer: ", "")?.trim()
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user