All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.http4k.contract.security.BearerAuthSecurity.kt Maven / Gradle / Ivy

There is a newer version: 5.31.0.0
Show newest version
package org.http4k.contract.security

import org.http4k.core.Filter
import org.http4k.filter.ServerFilters
import org.http4k.lens.RequestContextLens

/**
 * Checks the presence of bearer auth credentials. Filter returns 401 if auth fails.
 */
class BearerAuthSecurity(override val filter: Filter, val name: String = "bearerAuth") : Security {
    constructor(token: String, name: String = "bearerAuth") : this(ServerFilters.BearerAuth(token), name)
    constructor(token: (String) -> Boolean, name: String = "bearerAuth") : this(ServerFilters.BearerAuth(token), name)

    companion object {
        operator fun  invoke(key: RequestContextLens, lookup: (String) -> T?, name: String = "bearerAuth") =
            BearerAuthSecurity(ServerFilters.BearerAuth(key, lookup), name)
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy