@@ -24,14 +24,15 @@ type AuthentikClient struct {
2424
2525// AuthentikUserResponse represents the response from Authentik's user API
2626type AuthentikUserResponse struct {
27- ID int `json:"pk"`
28- Username string `json:"username"`
29- Name string `json:"name"`
30- Email string `json:"email"`
31- IsActive bool `json:"is_active"`
32- LastLogin string `json:"last_login"`
33- Groups []string `json:"groups"`
34- Avatar string `json:"avatar"`
27+ ID int `json:"pk"`
28+ Username string `json:"username"`
29+ Name string `json:"name"`
30+ Email string `json:"email"`
31+ IsActive bool `json:"is_active"`
32+ LastLogin string `json:"last_login"`
33+ Groups []string `json:"groups"`
34+ Avatar string `json:"avatar"`
35+ Attributes map [string ]interface {} `json:"attributes"`
3536}
3637
3738// NewAuthentikClient creates a new Authentik API client
@@ -230,6 +231,12 @@ func (ac *AuthentikClient) GetUserByEmail(email string) (*models.UserProfile, er
230231 return createUserProfileFromAuthentikUser (ac , authUser )
231232 }
232233
234+ // Check if we have any results
235+ if len (paginatedResponse .Results ) == 0 {
236+ log .Printf ("[ERROR] No user found with email: %s in paginated response" , email )
237+ return nil , errors .New ("user not found" )
238+ }
239+
233240 // Get first user from paginated response
234241 authUser := paginatedResponse .Results [0 ]
235242 log .Printf ("[DEBUG] Found user by email in paginated response: %s (ID: %d)" , authUser .Name , authUser .ID )
@@ -264,6 +271,36 @@ func createUserProfileFromAuthentikUser(ac *AuthentikClient, authUser AuthentikU
264271 userProfile .Avatar = & authUser .Avatar
265272 }
266273
274+ // Extract user attributes/metadata
275+ if authUser .Attributes != nil {
276+ // Log available attributes for debugging
277+ log .Printf ("[DEBUG] User attributes for %s: %v" , authUser .Email , authUser .Attributes )
278+
279+ // Extract member_since if available
280+ if memberSince , ok := authUser .Attributes ["member_since" ].(string ); ok {
281+ log .Printf ("[DEBUG] Found member_since attribute: %s" , memberSince )
282+ userProfile .MemberSince = memberSince
283+ }
284+
285+ // Extract membership_type if available
286+ if membershipType , ok := authUser .Attributes ["membership_type" ].(string ); ok {
287+ log .Printf ("[DEBUG] Found membership_type attribute: %s" , membershipType )
288+ userProfile .MembershipType = membershipType
289+ }
290+
291+ // Extract expiry_date if available
292+ if expiryDate , ok := authUser .Attributes ["expiry_date" ].(string ); ok {
293+ log .Printf ("[DEBUG] Found expiry_date attribute: %s" , expiryDate )
294+ userProfile .ExpiryDate = expiryDate
295+ }
296+
297+ // Extract membership_status if available
298+ if status , ok := authUser .Attributes ["membership_status" ].(string ); ok {
299+ log .Printf ("[DEBUG] Found membership_status attribute: %s" , status )
300+ userProfile .MembershipStatus = status
301+ }
302+ }
303+
267304 return userProfile , nil
268305}
269306
0 commit comments