summaryrefslogtreecommitdiff
path: root/coip/apps/consumer/__init__.py
blob: 5cfd0b1d151dce26aabfae2af7f9f653ee299427 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
__author__ = 'leifj'

from django.conf import settings
from django.utils.importlib import import_module

_consumer_provider_modules = list()

def autodiscover():
    for app in settings.INSTALLED_APPS:
	try:
        	mod = import_module("%s.models" % app)
	except: continue
        try:
            if hasattr(mod,'consumer_providers') and hasattr(mod.consumer_providers,'__call__'):
                _consumer_provider_modules.append(mod)
	except AttributeError:
  	    continue

def consumer_providers():
    p = list()
    for mod in _consumer_provider_modules:
        p.extend(mod.token_providers())
    return p

def consumer_provider(name):
    for mod in _consumer_provider_modules:
        for p in mod.token_providers():
            if p.name == name:
                return p
    return None

autodiscover()

# self.authorization_uri
# self.logo
# self.name
# self.description
# self.service_uri
# self.is_authorized(user)