Skip to content

Commit

Permalink
Use OIDC extension field for gameId
Browse files Browse the repository at this point in the history
  • Loading branch information
Brutus5000 committed Dec 29, 2023
1 parent abe2d8b commit ab46115
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ class FafPermissionsAugmentor : SecurityIdentityAugmentor {
when (val principal = identity.principal) {
is JsonWebToken -> {
val roles = principal.claim<Map<String, Any>>("ext")
.map { it["roles"] as List<JsonString> }
.map<List<JsonString>> { it["roles"] as? List<JsonString> }
.map { it.map { jsonString -> jsonString.string } }
.map { it.toSet() }
.orElse(setOf())
Expand All @@ -34,9 +34,11 @@ class FafPermissionsAugmentor : SecurityIdentityAugmentor {
.map { it.map { jsonString -> jsonString.string }.toSet() }
.orElse(setOf())

principal.claim<JsonNumber>("gameId").ifPresent {
builder.addAttribute("gameId", it.longValue())
}
principal.claim<Map<String, Any>>("ext")
.map<JsonNumber> { it["gameId"] as? JsonNumber }
.ifPresent {
builder.addAttribute("gameId", it.longValue())
}

builder.addPermissionChecker { requiredPermission ->
val hasRole = roles.contains(requiredPermission.name)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,13 @@ class SessionService(
}

return Jwt.subject(userId.toString())
.claim("gameId", gameId)
.claim("ext", mapOf("roles" to listOf("USER")))
.claim(
"ext",
mapOf(
"roles" to listOf("USER"),
"gameId" to gameId,
),
)
.claim("scp", listOf("lobby"))
.issuer(fafProperties.selfUrl())
.audience(fafProperties.selfUrl())
Expand Down

0 comments on commit ab46115

Please sign in to comment.