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

templates.kotlin-micronaut.client.auth.configuration.ApiKeyAuthConfiguration.mustache Maven / Gradle / Ivy

{{>common/licenseInfo}}
package {{invokerPackage}}.auth.configuration

import io.micronaut.context.annotation.ConfigurationInject
import io.micronaut.context.annotation.EachProperty
import io.micronaut.context.annotation.Parameter
import io.micronaut.core.annotation.NonNull
import io.micronaut.http.MutableHttpRequest
import io.micronaut.http.cookie.Cookie
{{#generatedAnnotation}}
import {{javaxPackage}}.annotation.Generated
{{/generatedAnnotation}}

{{#generatedAnnotation}}
{{>common/generatedAnnotation}}
{{/generatedAnnotation}}
@EachProperty("security.api-key-auth")
data class ApiKeyAuthConfiguration @ConfigurationInject
constructor(
    @Parameter override val name: String,
    @NonNull var location: AuthKeyLocation,
    @NonNull var paramName: String,
    @NonNull var apiKey: String
) : ConfigurableAuthorization {

    override fun applyAuthorization(@NonNull request: MutableHttpRequest<*>) {
        when (location) {
            AuthKeyLocation.HEADER -> {
                request.header(paramName, apiKey)
            }
            AuthKeyLocation.QUERY -> {
                request.parameters.add(paramName, apiKey)
            }
            AuthKeyLocation.COOKIE -> {
                request.cookie(Cookie.of(paramName, apiKey))
            }
        }
    }

    enum class AuthKeyLocation {
        HEADER,
        QUERY,
        COOKIE
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy