Commit 2833e6c0 authored by Mathieu's avatar Mathieu
Browse files

Implements logout route

parent 40c84e90
......@@ -143,13 +143,17 @@ class ConnectServlet(arguments: ConnectServer.ServletArguments) extends Scalatra
}
private def buildAndAddCookieToHeader(tokenData: TokenData) = {
val dateFormat = new java.text.SimpleDateFormat("EEE, d MMM yyyy HH:mm:ss z", new java.util.Locale("en"))
val format = new java.text.SimpleDateFormat("EEE, d MMM yyyy HH:mm:ss z", new java.util.Locale("en"))
private def buildAndAddCookieToHeader(tokenData: TokenData) = {
response.addHeader(
"Set-Cookie",
s"${tokenData.tokenType.cookieKey}=${tokenData.toContent};Expires=${format.format(tokenData.expirationTime)};HttpOnly;SameSite=Strict")
s"${tokenData.tokenType.cookieKey}=${tokenData.toContent};Expires=${dateFormat.format(tokenData.expirationTime)};HttpOnly;SameSite=Strict")
}
private def deleteCookie(tokenData: TokenData) = {
response.setHeader("Set-Cookie", s"${tokenData.tokenType.cookieKey}=;Expires=${dateFormat.format(0L)}")
}
private def getResource(path: String, requestContentType: String) = {
......@@ -164,7 +168,7 @@ class ConnectServlet(arguments: ConnectServer.ServletArguments) extends Scalatra
tokenData.host.hostIP.map { hip =>
val u = uriBuilder(hip, path)
request.getParameterNames.foreach {pn=>
request.getParameterNames.foreach { pn =>
u.addParameter(pn, request.getParameter(pn))
}
......@@ -196,6 +200,17 @@ class ConnectServlet(arguments: ConnectServer.ServletArguments) extends Scalatra
getResource(request.uri.getPath, request.getContentType)
}
get("/logout") {
withAccesToken { accessTokenData =>
withRefreshToken {refreshTokenData =>
deleteCookie(refreshTokenData)
deleteCookie(accessTokenData)
Ok()
}
Ok()
}
}
get("/") {
connectionAppRedirection
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment