def lookup_federation_by_name_id_and_provider_id(name_id, provider_id): '''Try to find a LibertyFederation object for the given NameID and the provider id.''' kwargs = models.nameid2kwargs(name_id) kwargs['idp_id'] = provider_id try: return LibertyFederation.objects.get(**kwargs) except: return None
def lookup_federation_by_name_id_and_provider_id(name_id, provider_id): '''Try to find a LibertyFederation object for the given NameID and the provider id.''' kwargs = models.nameid2kwargs(name_id) kwargs['idp'] = LibertyProvider.objects.get(entity_id=provider_id).identity_provider try: return LibertyFederation.objects.get(user__isnull=False, **kwargs) except: return None
def lookup_federation_by_name_identifier(name_id=None, profile=None): '''Try to find a LibertyFederation object for the given NameID or profile object.''' if not name_id: name_id = profile.nameIdentifier kwargs = models.nameid2kwargs(name_id) try: return LibertyFederation.objects.get(**kwargs) except: return None
def lookup_federation_by_name_id_and_provider_id(name_id, provider_id): '''Try to find a LibertyFederation object for the given NameID and the provider id.''' kwargs = models.nameid2kwargs(name_id) kwargs['idp'] = LibertyProvider.objects.get(entity_id=provider_id) \ .identity_provider try: return LibertyFederation.objects.get(user__isnull=False, **kwargs) except: return None
def add_federation(user, login=None, name_id=None, provider_id=None): assert name_id or (login and login.nameIdentifier), 'missing name identifier' name_id = name_id or login.nameIdentifier kwargs = models.nameid2kwargs(name_id) if provider_id: kwargs['idp'] = LibertyProvider.objects.get(entity_id=provider_id).identity_provider fed = LibertyFederation(user=user, **kwargs) fed.save() logger.debug('federation %r linked to user %r', fed.name_id_content, user) return fed
def add_federation(user, login=None, name_id=None, provider_id=None): assert name_id or (login and login.nameIdentifier), \ 'missing name identifier' name_id = name_id or login.nameIdentifier kwargs = models.nameid2kwargs(name_id) if provider_id: kwargs['idp'] = LibertyProvider.objects.get(entity_id=provider_id) \ .identity_provider fed = LibertyFederation(user=user, **kwargs) fed.save() logger.debug('federation %s linked to user %s', fed.name_id_content, user) return fed