Skip to content

Commit

Permalink
Show email in Hydra userinfo context
Browse files Browse the repository at this point in the history
  • Loading branch information
Brutus5000 committed Nov 6, 2024
1 parent 84c9f56 commit 58d0fec
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -142,12 +142,22 @@ class HydraService(

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

val context = mutableMapOf(
"username" to user.username,
"roles" to roles,
)

if (OAuthScope.canShowEmail(consentRequest.requestedScope)) {
context["email"] = user.email
context["email_verified"] = true
}

val redirectResponse = hydraClient.acceptConsentRequest(
challenge,
AcceptConsentRequest(
session = ConsentRequestSession(
accessToken = mapOf("username" to user.username, "roles" to roles),
idToken = mapOf("username" to user.username, "roles" to roles),
accessToken = context,
idToken = context,
),
grantScope = consentRequest.requestedScope,
),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,11 @@ package com.faforever.userservice.backend.security
* Contains pre-defined FAF scopes
*/
object OAuthScope {
// OIDC scopes
const val EMAIL = "email"
const val PROFILE = "profile"

// FAF scopes
const val PUBLIC_PROFILE = "public_profile"
const val WRITE_ACHIEVEMENTS = "write_achievements"
const val WRITE_EVENTS = "write_events"
Expand All @@ -16,4 +21,9 @@ object OAuthScope {
const val READ_SENSIBLE_USERDATA = "read_sensible_userdata"
const val ADMINISTRATIVE_ACTION = "administrative_actions"
const val MANAGE_VAULT = "manage_vault"

fun canShowEmail(scopes: List<String>?) =
if (scopes == null) {
false
} else scopes.contains(EMAIL) || scopes.contains(PROFILE) || scopes.contains(PUBLIC_PROFILE)
}

0 comments on commit 58d0fec

Please sign in to comment.