Skip to content

Commit 845b442

Browse files
committed
Add hmac to access token
1 parent 250d937 commit 845b442

File tree

3 files changed

+20
-0
lines changed

3 files changed

+20
-0
lines changed

src/main/kotlin/com/faforever/userservice/backend/hydra/HydraService.kt

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,9 @@ import com.faforever.userservice.backend.account.LoginResult
44
import com.faforever.userservice.backend.account.LoginService
55
import com.faforever.userservice.backend.domain.IpAddress
66
import com.faforever.userservice.backend.domain.UserRepository
7+
import com.faforever.userservice.backend.security.HmacService
78
import com.faforever.userservice.backend.security.OAuthScope
9+
import com.faforever.userservice.config.FafProperties
810
import jakarta.enterprise.context.ApplicationScoped
911
import jakarta.enterprise.inject.Produces
1012
import jakarta.transaction.Transactional
@@ -48,6 +50,8 @@ class HydraService(
4850
private val httpClient: HttpClient,
4951
private val loginService: LoginService,
5052
private val userRepository: UserRepository,
53+
private val fafProperties: FafProperties,
54+
private val hmacService: HmacService,
5155
) {
5256
companion object {
5357
private val LOG: Logger = LoggerFactory.getLogger(HydraService::class.java)
@@ -147,10 +151,15 @@ class HydraService(
147151

148152
val roles = listOf("USER") + permissions.map { it.technicalName }
149153

154+
val hmac = fafProperties.jwt().hmac()?.let {
155+
hmacService.generateHmacToken(it.message(), it.secret())
156+
}
157+
150158
val context = mutableMapOf(
151159
"username" to user.username, // not official OIDC claim, but required for backwards compatible
152160
"preferred_username" to user.username,
153161
"roles" to roles,
162+
"hmac" to hmac,
154163
)
155164

156165
if (OAuthScope.canShowEmail(consentRequest.requestedScope)) {

src/main/kotlin/com/faforever/userservice/config/FafProperties.kt

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,14 @@ interface FafProperties {
6161

6262
interface Jwt {
6363
fun secret(): String
64+
65+
fun hmac(): Hmac?
66+
}
67+
68+
interface Hmac {
69+
fun message(): String
70+
71+
fun secret(): String
6472
}
6573

6674
interface Recaptcha {

src/main/resources/application.yaml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,9 @@ faf:
3232
site-key: ${RECAPTCHA_SITE_KEY:6LeIxAcTAAAAAJcZVRqyHh71UMIEGNQ_MXjiZKhI}
3333
jwt:
3434
secret: ${JWT_SECRET:banana}
35+
hmac:
36+
message: ${JWT_MAC_MESSAGE:helloFaf}
37+
secret: ${JWT_MAC_SECRET:banana}
3538
lobby:
3639
secret: ${LOBBY_SECRET:banana}
3740
access-uri: ${LOBBY_URL:ws://localhost:8003}

0 commit comments

Comments
 (0)