
* set auth_via Signed-off-by: Jens Langhammer <jens@goauthentik.io> * allow requests with json content type Signed-off-by: Jens Langhammer <jens@goauthentik.io> * fix group schema Signed-off-by: Jens Langhammer <jens@goauthentik.io> * start improving error handling Signed-off-by: Jens Langhammer <jens@goauthentik.io> * add scim group patch for members Signed-off-by: Jens Langhammer <jens@goauthentik.io> * unrelated #1: fix debug check on startup Signed-off-by: Jens Langhammer <jens@goauthentik.io> * unrelated fix #2: fix path for user page Signed-off-by: Jens Langhammer <jens@goauthentik.io> * add group view tests Signed-off-by: Jens Langhammer <jens@goauthentik.io> * add more user tests too Signed-off-by: Jens Langhammer <jens@goauthentik.io> --------- Signed-off-by: Jens Langhammer <jens@goauthentik.io>
57 lines
1.9 KiB
Python
57 lines
1.9 KiB
Python
"""Schema Views"""
|
|
|
|
from json import loads
|
|
|
|
from django.conf import settings
|
|
from django.urls import reverse
|
|
from rest_framework.request import Request
|
|
from rest_framework.response import Response
|
|
|
|
from authentik.sources.scim.views.v2.base import SCIMView
|
|
from authentik.sources.scim.views.v2.exceptions import SCIMNotFoundError
|
|
|
|
with open(
|
|
settings.BASE_DIR / "authentik" / "sources" / "scim" / "schemas" / "schema.json",
|
|
encoding="utf-8",
|
|
) as SCHEMA_FILE:
|
|
_raw_schemas = loads(SCHEMA_FILE.read())
|
|
|
|
|
|
class SchemaView(SCIMView):
|
|
"""https://ldapwiki.com/wiki/SCIM%20Schemas%20Attribute"""
|
|
|
|
def get_schemas(self):
|
|
"""List of all schemas"""
|
|
schemas = []
|
|
for raw_schema in _raw_schemas:
|
|
raw_schema["meta"]["location"] = self.request.build_absolute_uri(
|
|
reverse(
|
|
"authentik_sources_scim:v2-schema",
|
|
kwargs={
|
|
"source_slug": self.kwargs["source_slug"],
|
|
"schema_uri": raw_schema["id"],
|
|
},
|
|
)
|
|
)
|
|
schemas.append(raw_schema)
|
|
return schemas
|
|
|
|
# pylint: disable=unused-argument
|
|
def get(self, request: Request, source_slug: str, schema_uri: str | None = None) -> Response:
|
|
"""Get schemas as SCIM response"""
|
|
schemas = self.get_schemas()
|
|
if schema_uri:
|
|
schema = [x for x in schemas if x.get("id") == schema_uri]
|
|
if schema:
|
|
return Response(schema[0])
|
|
raise SCIMNotFoundError("Schema not found.")
|
|
return Response(
|
|
{
|
|
"schemas": ["urn:ietf:params:scim:api:messages:2.0:ListResponse"],
|
|
"totalResults": len(schemas),
|
|
"itemsPerPage": len(schemas),
|
|
"startIndex": 1,
|
|
"Resources": schemas,
|
|
}
|
|
)
|