ApiKeyAuthentication

Lean and easy to use API key filter to protect endpoints with API key authentication

License

License

MIT
Categories

Categories

Spring Boot Container Microservices Net KeY Data Data Formats Formal Verification
GroupId

GroupId

net.skobow
ArtifactId

ArtifactId

apikey-authentication-spring-boot-starter
Last Version

Last Version

0.6.0
Release Date

Release Date

Type

Type

jar
Description

Description

ApiKeyAuthentication
Lean and easy to use API key filter to protect endpoints with API key authentication
Project URL

Project URL

https://github.com/skobow/apikey-authentication-spring-boot-starter
Project Organization

Project Organization

skobow
Source Code Management

Source Code Management

https://github.com/skobow/apikey-authentication-spring-boot-starter

Download apikey-authentication-spring-boot-starter

How to add to project

<!-- https://jarcasting.com/artifacts/net.skobow/apikey-authentication-spring-boot-starter/ -->
<dependency>
    <groupId>net.skobow</groupId>
    <artifactId>apikey-authentication-spring-boot-starter</artifactId>
    <version>0.6.0</version>
</dependency>
// https://jarcasting.com/artifacts/net.skobow/apikey-authentication-spring-boot-starter/
implementation 'net.skobow:apikey-authentication-spring-boot-starter:0.6.0'
// https://jarcasting.com/artifacts/net.skobow/apikey-authentication-spring-boot-starter/
implementation ("net.skobow:apikey-authentication-spring-boot-starter:0.6.0")
'net.skobow:apikey-authentication-spring-boot-starter:jar:0.6.0'
<dependency org="net.skobow" name="apikey-authentication-spring-boot-starter" rev="0.6.0">
  <artifact name="apikey-authentication-spring-boot-starter" type="jar" />
</dependency>
@Grapes(
@Grab(group='net.skobow', module='apikey-authentication-spring-boot-starter', version='0.6.0')
)
libraryDependencies += "net.skobow" % "apikey-authentication-spring-boot-starter" % "0.6.0"
[net.skobow/apikey-authentication-spring-boot-starter "0.6.0"]

Dependencies

compile (1)

Group / Artifact Type Version
net.skobow : apikey-authentication-spring-boot-autoconfigure jar 0.6.0

Project Modules

There are no modules declared in this project.

API Key Authentication Spring Boot Starter

Maven Central

Description

This Spring Boot starter provides easy to use and though configurable API Key authentication for your Spring Boot project.

Installation

To install simple add the dependency to you project build system, e.g. Gradle or Maven.

Gradle

implementation 'net.skobow:apikey-authentication-spring-boot-starter:0.6.0'

Maven

<dependency>
  <groupId>net.skobow</groupId>
  <artifactId>apikey-authentication-spring-boot-starter</artifactId>
  <version>0.6.0</version>
</dependency>

Usage

Just add the @EnableApiKeyAuthentication annotation to you Spring Boot Application class and provide web.authentication.apikey property to enable static API key authentication. This will add an Spring HandlerInterceptor that will check the X-Api-Key request header for the configured static API key. If no or not the correct key is provided the request will fail and send 401 as return code.

If no value for an API key is provided a random key is generated and logged to command line. This configuration is only suitable for testing scenarios as it does not provide security as the API key may appear in logs and is therefore considered as insecure!

Customization

Adding custom includes or excludes

If you want to configure paths to be included or excluded you can provide lists with patterns in you Spring configuration.

@Bean("apiKeyAuthenticationIncludePatterns") 
public List<String> apiKeyAuthenticationIncludePatterns() {
    ...
}

or

@Bean("apiKeyAuthenticationExcludePatterns")
public List<String> apiKeyAuthenticationExcludePatterns) {
    ...
}

Normally you may want to exclude at least your /error endpoint otherwise no errors will be returned to the user.

Using custom HTTP header fields

If you want to use a different HTTP header field you can simply provide your own implementation of the RequestApiKeyExtractor interface as a Spring bean.

Customizing API key verification

By default static API key verification for all requests is used. If your needs demand for a different verification schema you can provide your own implementation of the ApiKeyVerificationHandler interface as a Spring bean. This instance will be called during the request and lets you do your specific API key verification.

Versions

Version
0.6.0
0.5.1
0.5.0
0.1.0