add avatar URL

This commit is contained in:
Tim Möhlmann
2023-11-13 18:27:09 +02:00
parent c4cf569164
commit 477d565ffb
3 changed files with 11 additions and 9 deletions

View File

@@ -126,6 +126,7 @@ func NewServer(
fallbackLogger: fallbackLogger, fallbackLogger: fallbackLogger,
hashAlg: crypto.NewBCrypt(10), // as we are only verifying in oidc, the cost is already part of the hash string and the config here is irrelevant. hashAlg: crypto.NewBCrypt(10), // as we are only verifying in oidc, the cost is already part of the hash string and the config here is irrelevant.
signingKeyAlgorithm: config.SigningKeyAlgorithm, signingKeyAlgorithm: config.SigningKeyAlgorithm,
assetAPIPrefix: assets.AssetAPI(externalSecure),
} }
metricTypes := []metrics.MetricType{metrics.MetricTypeRequestCount, metrics.MetricTypeStatusCode, metrics.MetricTypeTotalCount} metricTypes := []metrics.MetricType{metrics.MetricTypeRequestCount, metrics.MetricTypeStatusCode, metrics.MetricTypeTotalCount}
server.Handler = op.RegisterLegacyServer(server, op.WithHTTPMiddleware( server.Handler = op.RegisterLegacyServer(server, op.WithHTTPMiddleware(

View File

@@ -26,6 +26,7 @@ type Server struct {
fallbackLogger *slog.Logger fallbackLogger *slog.Logger
hashAlg crypto.HashAlgorithm hashAlg crypto.HashAlgorithm
signingKeyAlgorithm string signingKeyAlgorithm string
assetAPIPrefix func(ctx context.Context) string
} }
func endpoints(endpointConfig *EndpointConfig) op.Endpoints { func endpoints(endpointConfig *EndpointConfig) op.Endpoints {

View File

@@ -60,7 +60,7 @@ func (s *Server) getUserInfoWithRoles(ctx context.Context, userID, projectID str
} }
} }
userInfo := userInfoToOIDC(userInfoResult.userInfo, scope) userInfo := userInfoToOIDC(userInfoResult.userInfo, scope, s.assetAPIPrefix(ctx))
setUserInfoRoleClaims(userInfo, assertRolesResult.projectsRoles) setUserInfoRoleClaims(userInfo, assertRolesResult.projectsRoles)
return userInfo, s.userinfoFlows(ctx, userInfoResult.userInfo, assertRolesResult.userGrants, userInfo) return userInfo, s.userinfoFlows(ctx, userInfoResult.userInfo, assertRolesResult.userGrants, userInfo)
@@ -150,7 +150,7 @@ func (s *Server) assertRoles(ctx context.Context, userID, projectID string, scop
} }
} }
func userInfoToOIDC(user *query.OIDCUserInfo, scope []string) *oidc.UserInfo { func userInfoToOIDC(user *query.OIDCUserInfo, scope []string, assetPrefix string) *oidc.UserInfo {
out := new(oidc.UserInfo) out := new(oidc.UserInfo)
for _, s := range scope { for _, s := range scope {
switch s { switch s {
@@ -159,7 +159,7 @@ func userInfoToOIDC(user *query.OIDCUserInfo, scope []string) *oidc.UserInfo {
case oidc.ScopeEmail: case oidc.ScopeEmail:
out.UserInfoEmail = userInfoEmailToOIDC(user.User) out.UserInfoEmail = userInfoEmailToOIDC(user.User)
case oidc.ScopeProfile: case oidc.ScopeProfile:
out.UserInfoProfile = userInfoProfileToOidc(user.User) out.UserInfoProfile = userInfoProfileToOidc(user.User, assetPrefix)
case oidc.ScopePhone: case oidc.ScopePhone:
out.UserInfoPhone = userInfoPhoneToOIDC(user.User) out.UserInfoPhone = userInfoPhoneToOIDC(user.User)
case oidc.ScopeAddress: case oidc.ScopeAddress:
@@ -192,14 +192,14 @@ func userInfoEmailToOIDC(user *query.User) oidc.UserInfoEmail {
return oidc.UserInfoEmail{} return oidc.UserInfoEmail{}
} }
func userInfoProfileToOidc(user *query.User) oidc.UserInfoProfile { func userInfoProfileToOidc(user *query.User, assetPrefix string) oidc.UserInfoProfile {
if human := user.Human; human != nil { if human := user.Human; human != nil {
return oidc.UserInfoProfile{ return oidc.UserInfoProfile{
Name: human.DisplayName, Name: human.DisplayName,
GivenName: human.FirstName, GivenName: human.FirstName,
FamilyName: human.LastName, FamilyName: human.LastName,
Nickname: human.NickName, Nickname: human.NickName,
// Picture: domain.AvatarURL(o.assetAPIPrefix(ctx), user.ResourceOwner, user.Human.AvatarKey), Picture: domain.AvatarURL(assetPrefix, user.ResourceOwner, user.Human.AvatarKey),
Gender: getGender(human.Gender), Gender: getGender(human.Gender),
Locale: oidc.NewLocale(human.PreferredLanguage), Locale: oidc.NewLocale(human.PreferredLanguage),
UpdatedAt: oidc.FromTime(user.ChangeDate), UpdatedAt: oidc.FromTime(user.ChangeDate),