-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #105 from Fabszn/i95_enhance_authen_mechanism
I95 enhance authen mechanism
- Loading branch information
Showing
10 changed files
with
166 additions
and
94 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
<template> | ||
<div class="spinner"> | ||
<div>Please wait while loading Floxx ....</div> | ||
<div><b-spinner label="Loading..."></b-spinner></div> | ||
</div> | ||
</template> | ||
<script> | ||
import _ from "lodash"; | ||
import shared from "../shared"; | ||
export default { | ||
created: function () { | ||
fetch("try-reco", { | ||
headers: shared.tokenHandle(), | ||
method: "POST", | ||
}) | ||
.then((response) => response.json()) | ||
.then((p) => { | ||
shared.storeToken(p.token, p.isAdmin, p.name); | ||
this.$store.commit("setUsername", p.name); | ||
this.$router.push("/menu"); | ||
}) | ||
.catch((err) => { | ||
console.info("error"); | ||
this.$router.push("/login"); | ||
}); | ||
}, | ||
}; | ||
</script> | ||
|
||
<style scoped> | ||
.spinner { | ||
display: flex; | ||
justify-content: center; | ||
} | ||
</style> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
62 changes: 52 additions & 10 deletions
62
httpEngine/src/main/scala/org/floxx/env/api/entriesPointApi.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,43 +1,85 @@ | ||
package org.floxx.env.api | ||
|
||
import org.http4s.HttpRoutes | ||
import org.http4s.{ HttpDate, HttpRoutes, Request,ResponseCookie, SameSite } | ||
import io.circe.generic.auto._ | ||
import org.floxx.BuildInfo | ||
import org.floxx.{ domain, BuildInfo } | ||
import org.floxx.domain.AuthUser.Mdp | ||
import org.floxx.domain.User.SimpleUser | ||
import org.floxx.env.service.securityService | ||
import org.floxx.env.service.securityService.AuthenticatedUser | ||
import org.http4s.circe._ | ||
import org.http4s.dsl.Http4sDsl | ||
|
||
import zio.{ URIO, ZIO } | ||
import zio.interop.catz._ | ||
|
||
import java.time.{ ZoneId, ZonedDateTime } | ||
|
||
|
||
object entriesPointApi { | ||
|
||
val dsl = Http4sDsl[ApiTask] | ||
val dsl = Http4sDsl[ApiTask] | ||
|
||
import dsl._ | ||
|
||
case class LoginResquest(login: String, mdp: String) | ||
object LoginResquest{ | ||
object LoginResquest { | ||
|
||
implicit val formatMdp = jsonOf[ApiTask, Mdp] | ||
implicit val formatSimpleUserId = jsonOf[ApiTask, SimpleUser.Id] | ||
implicit val formatLoginRequest = jsonOf[ApiTask, LoginResquest] | ||
implicit val formatMdp = jsonOf[ApiTask, Mdp] | ||
implicit val formatSimpleUserId = jsonOf[ApiTask, SimpleUser.Id] | ||
implicit val formatLoginRequest = jsonOf[ApiTask, LoginResquest] | ||
} | ||
|
||
implicit val decoder = jsonOf[ApiTask, LoginResquest] | ||
implicit val d = jsonEncoderOf[ApiTask, AuthenticatedUser] | ||
case class User(name:String,token:String, isAdmin:Boolean) | ||
case class User(name: String, token: String, isAdmin: Boolean) | ||
|
||
|
||
val floxx_auth = "floxx_auth" | ||
def api = HttpRoutes.of[ApiTask] { | ||
case req @ POST -> Root / "try-reco" => { | ||
|
||
for { | ||
info <- processCookie(req) | ||
response <- info.fold(BadRequest("auth has failed")) { | ||
case (token, userInfo) => | ||
Ok( | ||
AuthenticatedUser( | ||
s"${userInfo.firstName.value} ${userInfo.lastName.value}", | ||
token, | ||
userInfo.isAdmin | ||
) | ||
) | ||
} | ||
} yield response | ||
|
||
} | ||
case req @ POST -> Root / "login" => | ||
for { | ||
loginInfo <- req.as[LoginResquest] | ||
auth <- securityService.authentification(SimpleUser.Id(loginInfo.login), Mdp(loginInfo.mdp)) | ||
now <- ZIO.attempt(HttpDate.unsafeFromZonedDateTime(ZonedDateTime.now(ZoneId.of("Europe/Paris")).plusHours(24))) | ||
resp <- Ok(auth) | ||
} yield resp | ||
case _ @ GET -> Root / "infos" => | ||
} yield resp.addCookie( | ||
ResponseCookie( | ||
floxx_auth, | ||
auth.token, | ||
expires = Some(now), | ||
maxAge = None, | ||
httpOnly = true, | ||
secure = true, | ||
sameSite = Option(SameSite.Strict) | ||
) | ||
) | ||
case _ @GET -> Root / "infos" => | ||
Ok(BuildInfo.version) | ||
} | ||
|
||
private def processCookie(req: Request[ApiTask]): URIO[securityService.SecurityService, Option[(String, domain.AuthUser)]] = | ||
(for { | ||
r <- ZIO.attempt(req.cookies.find(c => c.name == floxx_auth)).some | ||
userInfo <- securityService.checkAuthentification(r.content).some | ||
u <- securityService.loadUserById(userInfo.userId).some | ||
} yield (r.content, u)).option | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.