当前位置: 动力学知识库 > 问答 > 编程问答 >

social - Django allauth - Checking if a provider is an active one in my project

问题描述:

I've tried these so far:

Either do SocialApp.objects.get(provider='provider-allowed-in-app')

And that would tell me if the provider indeed exists.

But the caveat here is, that if I have different providers installed in my settings, then this query fails to tell if the provider is infact allowed active in my Django project.

In [104]: for app in s.INSTALLED_APPS:

.....: if 'google' in app:

.....: print(app)

.....:

allauth.socialaccount.providers.google

But I want to do it in a proper way. Maybe there's a method to do this?

I found this module in allauth:

allauth.socialaccount.providers

Using it, I can do this:

providers.registry.get_list()

Which gives me something like this:

dict_values([<allauth.socialaccount.providers.google.provider.GoogleProvider object at 0x7f5803998470>, <allauth.socialaccount.providers.facebook.provider.FacebookProvider object at 0x7f5803998198>])

And that's almost what I want. But I need a list like

['google', 'facebook'], so that I can atleast do a simple:

registered_proviers = ['google', 'facebook']

if provider in registered_providers:

But it'd be greate if I can use some allauth function which would be like:

if is_registered_provider(provider):

Thanks.

网友答案:

You can try something like:

providers.registry.provider_map.keys()
分享给朋友:
您可能感兴趣的文章:
随机阅读: