Security.kt 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839
  1. package ru.mephi.plugins
  2. import io.ktor.auth.*
  3. import io.ktor.util.*
  4. import io.ktor.auth.jwt.*
  5. import com.auth0.jwt.JWT
  6. import com.auth0.jwt.JWTVerifier
  7. import com.auth0.jwt.algorithms.Algorithm
  8. import io.ktor.sessions.*
  9. import io.ktor.application.*
  10. import io.ktor.response.*
  11. import io.ktor.request.*
  12. fun Application.configureSecurity() {
  13. authentication {
  14. // jwt {
  15. // val jwtAudience = environment.config.property("jwt.audience").getString()
  16. // realm = environment.config.property("jwt.realm").getString()
  17. // verifier(
  18. // JWT
  19. // .require(Algorithm.HMAC256("secret"))
  20. // .withAudience(jwtAudience)
  21. // .withIssuer(environment.config.property("jwt.domain").getString())
  22. // .build()
  23. // )
  24. // validate { credential ->
  25. // if (credential.payload.audience.contains(jwtAudience)) JWTPrincipal(credential.payload) else null
  26. // }
  27. // }
  28. }
  29. data class MySession(val count: Int = 0)
  30. install(Sessions) {
  31. cookie<MySession>("MY_SESSION") {
  32. cookie.extensions["SameSite"] = "lax"
  33. }
  34. }
  35. }