spring-boot-jwt-security-starter

SpringBoot starter for JWT Token based Security

License

License

Categories

Categories

Spring Boot Container Microservices Security
GroupId

GroupId

io.github.sivalabs
ArtifactId

ArtifactId

spring-boot-jwt-security-starter
Last Version

Last Version

0.0.1
Release Date

Release Date

Type

Type

jar
Description

Description

spring-boot-jwt-security-starter
SpringBoot starter for JWT Token based Security
Project URL

Project URL

https://github.com/sivalabs/spring-boot-jwt-security-starter
Source Code Management

Source Code Management

https://github.com/sivalabs/spring-boot-jwt-security-starter

Download spring-boot-jwt-security-starter

How to add to project

<!-- https://jarcasting.com/artifacts/io.github.sivalabs/spring-boot-jwt-security-starter/ -->
<dependency>
    <groupId>io.github.sivalabs</groupId>
    <artifactId>spring-boot-jwt-security-starter</artifactId>
    <version>0.0.1</version>
</dependency>
// https://jarcasting.com/artifacts/io.github.sivalabs/spring-boot-jwt-security-starter/
implementation 'io.github.sivalabs:spring-boot-jwt-security-starter:0.0.1'
// https://jarcasting.com/artifacts/io.github.sivalabs/spring-boot-jwt-security-starter/
implementation ("io.github.sivalabs:spring-boot-jwt-security-starter:0.0.1")
'io.github.sivalabs:spring-boot-jwt-security-starter:jar:0.0.1'
<dependency org="io.github.sivalabs" name="spring-boot-jwt-security-starter" rev="0.0.1">
  <artifact name="spring-boot-jwt-security-starter" type="jar" />
</dependency>
@Grapes(
@Grab(group='io.github.sivalabs', module='spring-boot-jwt-security-starter', version='0.0.1')
)
libraryDependencies += "io.github.sivalabs" % "spring-boot-jwt-security-starter" % "0.0.1"
[io.github.sivalabs/spring-boot-jwt-security-starter "0.0.1"]

Dependencies

compile (5)

Group / Artifact Type Version
org.projectlombok : lombok Optional jar
org.springframework.boot : spring-boot-configuration-processor Optional jar
org.springframework.boot : spring-boot-starter-web jar
org.springframework.boot : spring-boot-starter-security jar
io.jsonwebtoken : jjwt jar 0.6.0

Project Modules

There are no modules declared in this project.

spring-boot-jwt-security-starter

This is a SpringBoot starter to provide JWT token based security auto-configuration.

How to use?

Add the dependency

Maven

<dependency>
    <groupId>com.github.sivalabs</groupId>
    <artifactId>spring-boot-jwt-security-starter</artifactId>
    <version>0.0.1</version>
</dependency>

Gradle

compile group: 'com.github.sivalabs', name: 'spring-boot-jwt-security-starter', version: '0.0.1'

With the starter dependency is added, you need to configure a bean of type org.springframework.security.core.userdetails.UserDetailsService.

Configuration

The following configuration properties are available to customize the default behaviour.

Property Required Default Value
security.jwt.issuer yes ""
security.jwt.header yes Authorization
security.jwt.expires-in yes 604800
security.jwt.secret yes ""
security.jwt.base-path yes /api/**
security.jwt.permit-all-paths no /api/auth/login,/api/auth/refresh
security.jwt.auth-api-enabled no true
security.jwt.create-auth-token-path no /api/auth/login
security.jwt.refresh-auth-token-path no /api/auth/refresh
security.jwt.auth-me-path no /api/auth/me

If security.jwt.auth-api-enabled property is set to true then following REST endpoints will be available:

1. Login/Create Auth Token

curl --header "Content-Type: application/json" \
  --request POST \
  --data '{"username":"xyz","password":"xyz"}' \
  http://localhost:8080/api/auth/login

Response JSON:

{
    "access_token": "....",
    "expires_in": "..."
}

2. Refresh Auth Token

curl --header "Authorization: Bearer access_token" \
  --request POST \
  http://localhost:8080/api/auth/refresh

Response JSON:

{
    "access_token": "....",
    "expires_in": "..."
}

3. Get Authenticated User Info

curl --header "Content-Type: application/json" \
  --request GET \
  http://localhost:8080/api/auth/me

Response JSON:

{
    "username": "admin",
    "roles": ["ROLE_USER","ROLE_ADMIN"]
}

Developer Notes

Procedure for deploying to Maven Central https://central.sonatype.org/pages/apache-maven.html

Set version to SNAPSHOT (ex: 1.0.0-SNAPSHOT)

Deploy SNAPSHOT version to https://oss.sonatype.org/content/repositories/snapshots/

spring-boot-jwt-security-starter> ./mvnw clean deploy -Prelease

Deploy release version to Maven Central

spring-boot-jwt-security-starter> ./mvnw release:clean release:prepare -Prelease
spring-boot-jwt-security-starter> ./mvnw release:perform -Prelease
io.github.sivalabs

SivaLabs

Versions

Version
0.0.1