Ejemplo n.º 1
0
    def get(self, request, format=None):
        """
        Identity mapping API
        ---
        # YAML
        type:
          name:
            required: true
            type: string
          url:
            required: false
            type: url
          created_at:
            required: true
            type: string
            format: date-time

        parameters:
            - name: wants
              description: attributes returned
              required: false
              type: string
              paramType: query
            - name: [attribute]
              description: the attribute to query against
              required: true
              type: string
              paramType: query
        responseMessages:
            - code: 200
              message: success
        """
        params = request.query_params
        users = []
        retrieved_fields = []
        key_names = PluginManager.get_all_needs()
        wants = params.getlist('wants', ['user_id'])
        for key_name in [key_name for key_name in key_names if key_name in params]:
            keys = params.getlist(key_name)
            users.extend([{key_name: key_value} for key_value in keys])
            retrieved_fields.append(key_name)
            providers = select_providers(PluginManager.get_all_providers(), wants, [key_name])
            providers = sort_by_dependencies(providers, [key_name])
            for provider in providers:
                load_by = provider.can_load(retrieved_fields)
                if load_by:
                    logger.info('Using {} with {}'.format(provider, retrieved_fields))
                    users = merge_users(
                        users, provider.load(**{load_by: [user[load_by] for user in users if load_by in user]}))
                    retrieved_fields.extend(provider.get_provides())

        # filter out unwanted attributes and use None for missing ones
        default_user_dict = {key: None for key in wants}
        users = [merge_dicts(default_user_dict, {key: value for key, value in user.iteritems() if key in wants})
                 for user in users]

        return Response(users)
Ejemplo n.º 2
0
    def get(self, request, format=None):
        needs = set()
        provides = set()
        for provider in PluginManager.get_all_providers():
            needs.update(provider.get_needs())
            provides.update(provider.get_provides())

        return Response({'needs': needs, 'provides': provides})
Ejemplo n.º 3
0
    def get(self, request, format=None):
        needs = set()
        provides = set()
        for provider in PluginManager.get_all_providers():
            needs.update(provider.get_needs())
            provides.update(provider.get_provides())

        return Response({'needs': needs, 'provides': provides})
Ejemplo n.º 4
0
 def testRegister(self):
     providers = PluginManager.get_all_providers()
     providers.sort(key=lambda p: p.name)
     for idx, providerClass in enumerate([EdxUsernameProvider, UserInfoProvider]):
         self.assertIsInstance(providers[idx], providerClass)
Ejemplo n.º 5
0
 def test_get_all_keys(self):
     keys = PluginManager.get_all_keys()
     self.assertItemsEqual(
         keys, ['user_id', 'employee_number', 'edx_username', 'remote_id', 'cwl', 'student_number', 'email'])
Ejemplo n.º 6
0
        'contact': '*****@*****.**',
        'description': 'This is a sample Identity Detective server. ',
        'license': 'Apache 2.0',
        'licenseUrl': 'http://www.apache.org/licenses/LICENSE-2.0.html',
        # 'termsOfServiceUrl': 'http://helloreverb.com/terms/',
        'title': 'Identity Detective',
    },
    'doc_expansion': 'none',
}

HASH_SALT = os.environ.get('HASH_SALT')
EDX_SERVER = os.environ.get('EDX_SERVER', 'http://localhost:8000')
EDX_MAPPING_ENDPOINT = os.environ.get('EDX_MAPPING_ENDPOINT', '/api/third_party_auth/v0/providers/saml-ubc/users')
EDX_ACCESS_TOKEN = os.environ.get('EDX_ACCESS_TOKEN')

PLUGINS = [
    # 'idm.plugins.providers.RemoteIdProvider',
    'idm.plugins.providers.UserInfoProvider',
    'idm.plugins.providers.EdxUsernameProvider',
]

PluginManager.register(*PLUGINS)

PROVIDER = {}

for provider in PluginManager.get_all_providers():
    provider_name = type(provider).__name__
    PROVIDER[provider_name] = {}
    for key, default in provider.settings.iteritems():
        PROVIDER[provider_name][key] = os.environ.get(key, default)
Ejemplo n.º 7
0
        'license': 'Apache 2.0',
        'licenseUrl': 'http://www.apache.org/licenses/LICENSE-2.0.html',
        # 'termsOfServiceUrl': 'http://helloreverb.com/terms/',
        'title': 'Identity Detective',
    },
    'doc_expansion': 'none',
}

HASH_SALT = os.environ.get('HASH_SALT')
EDX_SERVER = os.environ.get('EDX_SERVER', 'http://localhost:8000')
EDX_MAPPING_ENDPOINT = os.environ.get(
    'EDX_MAPPING_ENDPOINT',
    '/api/third_party_auth/v0/providers/saml-ubc/users')
EDX_ACCESS_TOKEN = os.environ.get('EDX_ACCESS_TOKEN')

PLUGINS = [
    # 'idm.plugins.providers.RemoteIdProvider',
    'idm.plugins.providers.UserInfoProvider',
    'idm.plugins.providers.EdxUsernameProvider',
]

PluginManager.register(*PLUGINS)

PROVIDER = {}

for provider in PluginManager.get_all_providers():
    provider_name = type(provider).__name__
    PROVIDER[provider_name] = {}
    for key, default in provider.settings.iteritems():
        PROVIDER[provider_name][key] = os.environ.get(key, default)