add JwtService
This commit is contained in:
@@ -8,6 +8,7 @@ plugins {
|
|||||||
|
|
||||||
dependencies {
|
dependencies {
|
||||||
implementation(hlaeja.jjwt.api)
|
implementation(hlaeja.jjwt.api)
|
||||||
|
implementation(hlaeja.kotlin.logging)
|
||||||
implementation(hlaeja.kotlin.reflect)
|
implementation(hlaeja.kotlin.reflect)
|
||||||
implementation(hlaeja.kotlinx.coroutines)
|
implementation(hlaeja.kotlinx.coroutines)
|
||||||
implementation(hlaeja.org.springframework.springboot.actuator.starter)
|
implementation(hlaeja.org.springframework.springboot.actuator.starter)
|
||||||
|
|||||||
27
src/main/kotlin/ltd/hlaeja/service/JwtService.kt
Normal file
27
src/main/kotlin/ltd/hlaeja/service/JwtService.kt
Normal file
@@ -0,0 +1,27 @@
|
|||||||
|
package ltd.hlaeja.service
|
||||||
|
|
||||||
|
import io.jsonwebtoken.JwtParser
|
||||||
|
import io.jsonwebtoken.Jwts
|
||||||
|
import java.util.UUID
|
||||||
|
import ltd.hlaeja.property.JwtProperty
|
||||||
|
import ltd.hlaeja.util.PublicKeyProvider
|
||||||
|
import mu.KotlinLogging
|
||||||
|
import org.springframework.stereotype.Service
|
||||||
|
|
||||||
|
private val log = KotlinLogging.logger {}
|
||||||
|
|
||||||
|
@Service
|
||||||
|
class JwtService(
|
||||||
|
jwtProperty: JwtProperty,
|
||||||
|
) {
|
||||||
|
|
||||||
|
private val parser: JwtParser = Jwts.parser()
|
||||||
|
.verifyWith(PublicKeyProvider.load(jwtProperty.publicKey))
|
||||||
|
.build()
|
||||||
|
|
||||||
|
suspend fun readIdentity(
|
||||||
|
identity: String,
|
||||||
|
): UUID = parser.parseSignedClaims(identity)
|
||||||
|
.let { UUID.fromString(it.payload["device"] as String) }
|
||||||
|
.also { log.debug("Identified client device: {}", it) }
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user