code: def get_identity(user):
      
      identity = Identity(user.id)
  
      if hasattr(user, 'id'):
          identity.provides.add(UserNeed(user.id))
  
      for role in getattr(user, 'roles', []):
          identity.provides.add(RoleNeed(role.name))
  
      identity.user = user
      return identity
docs: Create an identity for a given user instance.
  
      Primarily useful for testing.