Skip to content

Commit

Permalink
#10 feat: jwt 비즈니스 로직 구현
Browse files Browse the repository at this point in the history
  • Loading branch information
SunwoongH committed Dec 5, 2024
1 parent e6a4bd2 commit 5200430
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 5 deletions.
16 changes: 11 additions & 5 deletions core/src/main/kotlin/org/doorip/core/auth/JwtService.kt
Original file line number Diff line number Diff line change
@@ -1,13 +1,19 @@
package org.doorip.core.auth

import org.doorip.domain.UserId
import org.springframework.stereotype.Component
import org.doorip.support.jwt.JwtProvider
import org.doorip.support.jwt.JwtSecretKey
import org.springframework.stereotype.Service

@Component
internal class JwtService : AccessTokenUseCase {
@Service
internal class JwtService(
private val jwtProvider: JwtProvider,
private val jwtSecretKey: JwtSecretKey,
) : AccessTokenUseCase {

override fun getUserId(token: String): UserId? {
// TODO
return null
val subject = jwtProvider.validateAndGetSubject(token, jwtSecretKey) ?: return null

return UserId(subject.toLong())
}
}
18 changes: 18 additions & 0 deletions core/src/main/kotlin/org/doorip/core/config/JwtConfig.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package org.doorip.core.config

import org.doorip.support.jwt.JwtProvider
import org.doorip.support.jwt.JwtSecretKey
import org.springframework.boot.context.properties.EnableConfigurationProperties
import org.springframework.context.annotation.Bean
import org.springframework.context.annotation.Configuration

@EnableConfigurationProperties(JwtProperties::class)
@Configuration
internal class JwtConfig {

@Bean
fun jwtProvider(): JwtProvider = JwtProvider()

@Bean
fun jwtSecretKey(jwtProperties: JwtProperties): JwtSecretKey = JwtSecretKey(jwtProperties.secret)
}
8 changes: 8 additions & 0 deletions core/src/main/kotlin/org/doorip/core/config/JwtProperties.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package org.doorip.core.config

import org.springframework.boot.context.properties.ConfigurationProperties

@ConfigurationProperties(prefix = "jwt")
data class JwtProperties(
val secret: String,
)
2 changes: 2 additions & 0 deletions core/src/main/resources/application-jwt.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
jwt:
secret: ${JWT_SECRET_KEY}

0 comments on commit 5200430

Please sign in to comment.