Coverage Summary for Class: SecurityKt (dev.suresh.plugins)

Class Method, % Branch, % Line, % Instruction, %
SecurityKt 0% (0/6) 0% (0/14) 0% (0/89)
SecurityKt$configureSecurity$$inlined$provideDelegate$1 0% (0/1)
SecurityKt$configureSecurity$1$1$1 0% (0/1) 0% (0/4) 0% (0/3) 0% (0/27)
SecurityKt$configureSecurity$1$2$1 0% (0/1) 0% (0/2) 0% (0/3) 0% (0/19)
SecurityKt$configureSecurity$1$3$2 0% (0/1) 0% (0/2) 0% (0/1) 0% (0/19)
SecurityKt$configureSecurity$1$3$3 0% (0/1) 0% (0/1) 0% (0/21)
Total 0% (0/11) 0% (0/8) 0% (0/22) 0% (0/175)


 package dev.suresh.plugins
 
 import com.auth0.jwt.JWT
 import com.auth0.jwt.algorithms.Algorithm
 import dev.suresh.di.Auth
 import io.ktor.server.application.*
 import io.ktor.server.auth.*
 import io.ktor.server.auth.jwt.JWTPrincipal
 import io.ktor.server.auth.jwt.jwt
 import io.ktor.server.plugins.di.dependencies
 
 fun Application.configureSecurity() {
   val auth: Auth by dependencies
 
   authentication {
     basic("admin") {
       realm = "App Admin"
       validate { credentials ->
         when (credentials.name == auth.admin.user && credentials.password == auth.admin.password) {
           true -> UserIdPrincipal(credentials.name)
           else -> null
         }
       }
     }
 
     bearer("auth-bearer") {
       realm = "Ktor App"
       authenticate { tokenCredential ->
         when (tokenCredential.token) {
           auth.api.bearerToken -> UserIdPrincipal(auth.api.user)
           else -> null
         }
       }
     }
 
     jwt("auth-jwt") {
       realm = "Ktor App"
 
       verifier {
         JWT.require(Algorithm.HMAC256(auth.api.bearerToken)).withIssuer(BuildConfig.name).build()
       }
 
       validate { cred -> cred.payload.subject?.let { JWTPrincipal(cred.payload) } }
       challenge { defaultScheme, realm ->
         call.respondError(Unauthorized, "Token is not valid or has expired")
       }
     }
 
     //  oauth("login") {
     //      client = ...
     //      urlProvider = ...
     //      providerLookup = { ... }
     //      fallback = { cause ->
     //          if (cause is OAuth2RedirectError) {
     //              respondRedirect("/login-after-fallback")
     //          } else {
     //              respond(HttpStatusCode.Forbidden, cause.message)
     //          }
     //      }
     //  }
 
     // apiKey {
     //   headerName = "X-Secret-Key"
     //   validate { apiKey ->
     //     if (apiKey == "secret-key") {
     //       UserIdPrincipal(apiKey)
     //     } else {
     //       null
     //     }
     //   }
     //   challenge { it.respond(HttpStatusCode.Unauthorized, "Invalid or missing API key") }
     // }
   }
 }