django-scim2¶
This is a partial provider-side implementation of the SCIM 2.0 [1] specification for use in Django.
Note that currently the only supported database is Postgres.
Installation¶
Install with pip:
$ pip install django-scim2
Then add the django_scim
app to INSTALLED_APPS
in your Django’s settings:
INSTALLED_APPS = (
...
'django_scim',
)
Add the appropriate middleware to authorize or deny the SCIM calls:
MIDDLEWARE_CLASSES = (
...
'django_scim.middleware.SCIMAuthCheckMiddleware',
...
)
Make sure to place this middleware after authentication middleware as this middleware simply checks request.user.is_anonymous() to determine if the SCIM request should be allowed or denied.
Add the necessary url patterns to your root urls.py file. Please note that the namespace is mandatory and must be named scim:
# Django 1.11
urlpatterns = [
...
url(r'^scim/v2/', include('django_scim.urls', namespace='scim')),
]
# Django 2+
urlpatterns = [
...
path('scim/v2/', include('django_scim.urls')),
]
Finally, add settings appropriate for you app to your settings.py file:
SCIM_SERVICE_PROVIDER = {
'NETLOC': 'localhost',
'AUTHENTICATION_SCHEMES': [
{
'type': 'oauth2',
'name': 'OAuth 2',
'description': 'Oauth 2 implemented with bearer token',
},
],
}
Other SCIM settings can be provided but those listed above are required.
License¶
This library is released under the terms of the MIT license. Full details in LICENSE.txt
file.
Extensibility¶
This library was forked and developed to be highly extensible. A number of adapters can be defined to control what different endpoints do to your resources. Please see the documentation for more details.
PLEASE NOTE: This app does not implement authorization and authentication. Such tasks are left for other apps such as Django OAuth Toolkit to implement.
Credits¶
This project was forked from https://bitbucket.org/atlassian/django_scim
[1] | http://www.simplecloud.info/, https://tools.ietf.org/html/rfc7644 |
Contents¶
Adapters¶
Adapters are used to convert the data model described by the SCIM 2.0 specification to a data model that fits the data provided by the application implementing a SCIM api.
For example, in a Django app, there are User and Group models that do
not have the same attributes/fields that are defined by the SCIM 2.0
specification. The Django User model has both first_name
and last_name
attributes but the SCIM speicifcation requires this same data be sent under
the names givenName
and familyName
respectively.
An adapter is instantiated with a model instance. Eg:
user = get_user_model().objects.get(id=1)
scim_user = SCIMUser(user)
...
-
class
django_scim.adapters.
SCIMGroup
(obj, request=None)[source]¶ Adapter for adding SCIM functionality to a Django Group object.
This adapter can be overriden; see the
GROUP_ADAPTER
setting for details.-
display_name
¶ Return the displayName of the group per the SCIM spec.
-
from_dict
(d)[source]¶ Consume a
dict
conforming to the SCIM Group Schema, updating the internal group object with data from thedict
.Please note, the group object is not saved within this method. To persist the changes made by this method, please call
.save()
on the adapter. Eg:scim_group.from_dict(d) scim_group.save()
-
members
¶ Return a list of user dicts (ready for serialization) for the members of the group.
Return type: list
-
meta
¶ Return the meta object of the group per the SCIM spec.
-
-
class
django_scim.adapters.
SCIMUser
(obj, request=None)[source]¶ Adapter for adding SCIM functionality to a Django User object.
This adapter can be overriden; see the
USER_ADAPTER
setting for details.-
display_name
¶ Return the displayName of the user per the SCIM spec.
-
emails
¶ Return the email of the user per the SCIM spec.
-
from_dict
(d)[source]¶ Consume a
dict
conforming to the SCIM User Schema, updating the internal user object with data from thedict
.Please note, the user object is not saved within this method. To persist the changes made by this method, please call
.save()
on the adapter. Eg:scim_user.from_dict(d) scim_user.save()
-
groups
¶ Return the groups of the user per the SCIM spec.
-
meta
¶ Return the meta object of the user per the SCIM spec.
-
Filters¶
Filter transformers are used to convert the SCIM query and filter syntax into valid SQL queries.
-
class
django_scim.filters.
SCIMGroupFilterTransformer
[source]¶ Transforms a PlyPlus parse tree into a tuple containing a raw SQL query and a dict with query parameters to go with the query.
Models¶
Utilities¶
-
django_scim.utils.
default_base_scim_location_getter
(request=None, *args, **kwargs)[source]¶ Return the default location of the app implementing the SCIM api.
-
django_scim.utils.
default_get_extra_model_exclude_kwargs_getter
(model)[source]¶ Return a method that will return extra model exclude kwargs for the passed in model.
Parameters: model –
-
django_scim.utils.
default_get_extra_model_filter_kwargs_getter
(model)[source]¶ Return a method that will return extra model filter kwargs for the passed in model.
Parameters: model –
-
django_scim.utils.
get_all_schemas_getter
()[source]¶ Return a function that will, when called, returns the base location of scim app.
-
django_scim.utils.
get_base_scim_location_getter
()[source]¶ Return a function that will, when called, returns the base location of scim app.
-
django_scim.utils.
get_extra_model_exclude_kwargs_getter
(model)[source]¶ Return a function that will, when called, returns the base location of scim app.
-
django_scim.utils.
get_extra_model_filter_kwargs_getter
(model)[source]¶ Return a function that will, when called, returns the base location of scim app.
Views¶
-
class
django_scim.views.
GroupsView
(**kwargs)[source]¶ -
get_extra_exclude_kwargs
(request, *args, **kwargs)¶ Return extra exclude kwargs for the given model. :param request: :param args: :param kwargs: :rtype: dict
-
get_extra_filter_kwargs
(request, *args, **kwargs)¶ Return extra filter kwargs for the given model. :param request: :param args: :param kwargs: :rtype: dict
-
model_cls
¶ alias of
django.contrib.auth.models.Group
-
parser
¶
-
scim_adapter
¶ alias of
django_scim.adapters.SCIMGroup
-
-
class
django_scim.views.
SearchView
(**kwargs)[source]¶ -
get_extra_exclude_kwargs
(request, *args, **kwargs)¶ Return extra exclude kwargs for the given model. :param request: :param args: :param kwargs: :rtype: dict
-
get_extra_filter_kwargs
(request, *args, **kwargs)¶ Return extra filter kwargs for the given model. :param request: :param args: :param kwargs: :rtype: dict
-
-
class
django_scim.views.
UsersView
(**kwargs)[source]¶ -
get_extra_exclude_kwargs
(request, *args, **kwargs)¶ Return extra exclude kwargs for the given model. :param request: :param args: :param kwargs: :rtype: dict
-
get_extra_filter_kwargs
(request, *args, **kwargs)¶ Return extra filter kwargs for the given model. :param request: :param args: :param kwargs: :rtype: dict
-
model_cls
¶ alias of
django.contrib.auth.models.User
-
parser
¶
-
scim_adapter
¶ alias of
django_scim.adapters.SCIMUser
-