authentik.sources.scim.views.v2.resource_types
SCIM Meta views
1"""SCIM Meta views""" 2 3from django.urls import reverse 4from rest_framework.request import Request 5from rest_framework.response import Response 6 7from authentik.sources.scim.views.v2.base import SCIMView 8from authentik.sources.scim.views.v2.exceptions import SCIMNotFoundError 9 10 11class ResourceTypesView(SCIMView): 12 """https://ldapwiki.com/wiki/SCIM%20ResourceTypes%20endpoint""" 13 14 def get_resource_types(self): 15 """List all resource types""" 16 return [ 17 { 18 "id": "ServiceProviderConfig", 19 "name": "ServiceProviderConfig", 20 "description": "the service providers configuration", 21 "endpoint": "/ServiceProviderConfig", 22 "schema": "urn:ietf:params:scim:schemas:core:2.0:ServiceProviderConfig", 23 "schemas": [ 24 "urn:ietf:params:scim:schemas:core:2.0:ResourceType", 25 ], 26 "meta": { 27 "resourceType": "ResourceType", 28 "location": self.request.build_absolute_uri( 29 reverse( 30 "authentik_sources_scim:v2-resource-types", 31 kwargs={ 32 "source_slug": self.kwargs["source_slug"], 33 "resource_type": "ServiceProviderConfig", 34 }, 35 ) 36 ), 37 }, 38 }, 39 { 40 "id": "ResourceType", 41 "name": "ResourceType", 42 "description": "ResourceType", 43 "endpoint": "/ResourceTypes", 44 "schema": "urn:ietf:params:scim:schemas:core:2.0:ResourceType", 45 "schemas": [ 46 "urn:ietf:params:scim:schemas:core:2.0:ResourceType", 47 ], 48 "meta": { 49 "resourceType": "ResourceType", 50 "location": self.request.build_absolute_uri( 51 reverse( 52 "authentik_sources_scim:v2-resource-types", 53 kwargs={ 54 "source_slug": self.kwargs["source_slug"], 55 "resource_type": "ResourceType", 56 }, 57 ) 58 ), 59 }, 60 }, 61 { 62 "id": "Schema", 63 "name": "Schema", 64 "description": "Schema endpoint description", 65 "endpoint": "/Schemas", 66 "schema": "urn:ietf:params:scim:schemas:core:2.0:Schema", 67 "schemas": [ 68 "urn:ietf:params:scim:schemas:core:2.0:ResourceType", 69 ], 70 "meta": { 71 "resourceType": "ResourceType", 72 "location": self.request.build_absolute_uri( 73 reverse( 74 "authentik_sources_scim:v2-resource-types", 75 kwargs={ 76 "source_slug": self.kwargs["source_slug"], 77 "resource_type": "Schema", 78 }, 79 ) 80 ), 81 }, 82 }, 83 { 84 "id": "User", 85 "name": "User", 86 "endpoint": "/Users", 87 "description": "https://tools.ietf.org/html/rfc7643#section-8.7.1", 88 "schemas": ["urn:ietf:params:scim:schemas:core:2.0:ResourceType"], 89 "schema": "urn:ietf:params:scim:schemas:core:2.0:User", 90 "schemaExtensions": [ 91 { 92 "schema": "urn:ietf:params:scim:schemas:extension:enterprise:2.0:User", 93 "required": True, 94 } 95 ], 96 "meta": { 97 "location": self.request.build_absolute_uri( 98 reverse( 99 "authentik_sources_scim:v2-resource-types", 100 kwargs={ 101 "source_slug": self.kwargs["source_slug"], 102 "resource_type": "User", 103 }, 104 ) 105 ), 106 "resourceType": "ResourceType", 107 }, 108 }, 109 { 110 "id": "Group", 111 "name": "Group", 112 "description": "Group", 113 "endpoint": "/Groups", 114 "schema": "urn:ietf:params:scim:schemas:core:2.0:Group", 115 "schemas": [ 116 "urn:ietf:params:scim:schemas:core:2.0:ResourceType", 117 ], 118 "meta": { 119 "resourceType": "ResourceType", 120 "location": self.request.build_absolute_uri( 121 reverse( 122 "authentik_sources_scim:v2-resource-types", 123 kwargs={ 124 "source_slug": self.kwargs["source_slug"], 125 "resource_type": "Group", 126 }, 127 ) 128 ), 129 }, 130 }, 131 ] 132 133 # pylint: disable=unused-argument 134 def get(self, request: Request, source_slug: str, resource_type: str | None = None) -> Response: 135 """Get resource types as SCIM response""" 136 resource_types = self.get_resource_types() 137 if resource_type: 138 resource = [x for x in resource_types if x.get("id") == resource_type] 139 if resource: 140 return Response(resource[0]) 141 raise SCIMNotFoundError("Resource not found.") 142 return Response( 143 { 144 "schemas": ["urn:ietf:params:scim:api:messages:2.0:ListResponse"], 145 "totalResults": len(resource_types), 146 "itemsPerPage": len(resource_types), 147 "startIndex": 1, 148 "Resources": resource_types, 149 } 150 )
12class ResourceTypesView(SCIMView): 13 """https://ldapwiki.com/wiki/SCIM%20ResourceTypes%20endpoint""" 14 15 def get_resource_types(self): 16 """List all resource types""" 17 return [ 18 { 19 "id": "ServiceProviderConfig", 20 "name": "ServiceProviderConfig", 21 "description": "the service providers configuration", 22 "endpoint": "/ServiceProviderConfig", 23 "schema": "urn:ietf:params:scim:schemas:core:2.0:ServiceProviderConfig", 24 "schemas": [ 25 "urn:ietf:params:scim:schemas:core:2.0:ResourceType", 26 ], 27 "meta": { 28 "resourceType": "ResourceType", 29 "location": self.request.build_absolute_uri( 30 reverse( 31 "authentik_sources_scim:v2-resource-types", 32 kwargs={ 33 "source_slug": self.kwargs["source_slug"], 34 "resource_type": "ServiceProviderConfig", 35 }, 36 ) 37 ), 38 }, 39 }, 40 { 41 "id": "ResourceType", 42 "name": "ResourceType", 43 "description": "ResourceType", 44 "endpoint": "/ResourceTypes", 45 "schema": "urn:ietf:params:scim:schemas:core:2.0:ResourceType", 46 "schemas": [ 47 "urn:ietf:params:scim:schemas:core:2.0:ResourceType", 48 ], 49 "meta": { 50 "resourceType": "ResourceType", 51 "location": self.request.build_absolute_uri( 52 reverse( 53 "authentik_sources_scim:v2-resource-types", 54 kwargs={ 55 "source_slug": self.kwargs["source_slug"], 56 "resource_type": "ResourceType", 57 }, 58 ) 59 ), 60 }, 61 }, 62 { 63 "id": "Schema", 64 "name": "Schema", 65 "description": "Schema endpoint description", 66 "endpoint": "/Schemas", 67 "schema": "urn:ietf:params:scim:schemas:core:2.0:Schema", 68 "schemas": [ 69 "urn:ietf:params:scim:schemas:core:2.0:ResourceType", 70 ], 71 "meta": { 72 "resourceType": "ResourceType", 73 "location": self.request.build_absolute_uri( 74 reverse( 75 "authentik_sources_scim:v2-resource-types", 76 kwargs={ 77 "source_slug": self.kwargs["source_slug"], 78 "resource_type": "Schema", 79 }, 80 ) 81 ), 82 }, 83 }, 84 { 85 "id": "User", 86 "name": "User", 87 "endpoint": "/Users", 88 "description": "https://tools.ietf.org/html/rfc7643#section-8.7.1", 89 "schemas": ["urn:ietf:params:scim:schemas:core:2.0:ResourceType"], 90 "schema": "urn:ietf:params:scim:schemas:core:2.0:User", 91 "schemaExtensions": [ 92 { 93 "schema": "urn:ietf:params:scim:schemas:extension:enterprise:2.0:User", 94 "required": True, 95 } 96 ], 97 "meta": { 98 "location": self.request.build_absolute_uri( 99 reverse( 100 "authentik_sources_scim:v2-resource-types", 101 kwargs={ 102 "source_slug": self.kwargs["source_slug"], 103 "resource_type": "User", 104 }, 105 ) 106 ), 107 "resourceType": "ResourceType", 108 }, 109 }, 110 { 111 "id": "Group", 112 "name": "Group", 113 "description": "Group", 114 "endpoint": "/Groups", 115 "schema": "urn:ietf:params:scim:schemas:core:2.0:Group", 116 "schemas": [ 117 "urn:ietf:params:scim:schemas:core:2.0:ResourceType", 118 ], 119 "meta": { 120 "resourceType": "ResourceType", 121 "location": self.request.build_absolute_uri( 122 reverse( 123 "authentik_sources_scim:v2-resource-types", 124 kwargs={ 125 "source_slug": self.kwargs["source_slug"], 126 "resource_type": "Group", 127 }, 128 ) 129 ), 130 }, 131 }, 132 ] 133 134 # pylint: disable=unused-argument 135 def get(self, request: Request, source_slug: str, resource_type: str | None = None) -> Response: 136 """Get resource types as SCIM response""" 137 resource_types = self.get_resource_types() 138 if resource_type: 139 resource = [x for x in resource_types if x.get("id") == resource_type] 140 if resource: 141 return Response(resource[0]) 142 raise SCIMNotFoundError("Resource not found.") 143 return Response( 144 { 145 "schemas": ["urn:ietf:params:scim:api:messages:2.0:ListResponse"], 146 "totalResults": len(resource_types), 147 "itemsPerPage": len(resource_types), 148 "startIndex": 1, 149 "Resources": resource_types, 150 } 151 )
def
get_resource_types(self):
15 def get_resource_types(self): 16 """List all resource types""" 17 return [ 18 { 19 "id": "ServiceProviderConfig", 20 "name": "ServiceProviderConfig", 21 "description": "the service providers configuration", 22 "endpoint": "/ServiceProviderConfig", 23 "schema": "urn:ietf:params:scim:schemas:core:2.0:ServiceProviderConfig", 24 "schemas": [ 25 "urn:ietf:params:scim:schemas:core:2.0:ResourceType", 26 ], 27 "meta": { 28 "resourceType": "ResourceType", 29 "location": self.request.build_absolute_uri( 30 reverse( 31 "authentik_sources_scim:v2-resource-types", 32 kwargs={ 33 "source_slug": self.kwargs["source_slug"], 34 "resource_type": "ServiceProviderConfig", 35 }, 36 ) 37 ), 38 }, 39 }, 40 { 41 "id": "ResourceType", 42 "name": "ResourceType", 43 "description": "ResourceType", 44 "endpoint": "/ResourceTypes", 45 "schema": "urn:ietf:params:scim:schemas:core:2.0:ResourceType", 46 "schemas": [ 47 "urn:ietf:params:scim:schemas:core:2.0:ResourceType", 48 ], 49 "meta": { 50 "resourceType": "ResourceType", 51 "location": self.request.build_absolute_uri( 52 reverse( 53 "authentik_sources_scim:v2-resource-types", 54 kwargs={ 55 "source_slug": self.kwargs["source_slug"], 56 "resource_type": "ResourceType", 57 }, 58 ) 59 ), 60 }, 61 }, 62 { 63 "id": "Schema", 64 "name": "Schema", 65 "description": "Schema endpoint description", 66 "endpoint": "/Schemas", 67 "schema": "urn:ietf:params:scim:schemas:core:2.0:Schema", 68 "schemas": [ 69 "urn:ietf:params:scim:schemas:core:2.0:ResourceType", 70 ], 71 "meta": { 72 "resourceType": "ResourceType", 73 "location": self.request.build_absolute_uri( 74 reverse( 75 "authentik_sources_scim:v2-resource-types", 76 kwargs={ 77 "source_slug": self.kwargs["source_slug"], 78 "resource_type": "Schema", 79 }, 80 ) 81 ), 82 }, 83 }, 84 { 85 "id": "User", 86 "name": "User", 87 "endpoint": "/Users", 88 "description": "https://tools.ietf.org/html/rfc7643#section-8.7.1", 89 "schemas": ["urn:ietf:params:scim:schemas:core:2.0:ResourceType"], 90 "schema": "urn:ietf:params:scim:schemas:core:2.0:User", 91 "schemaExtensions": [ 92 { 93 "schema": "urn:ietf:params:scim:schemas:extension:enterprise:2.0:User", 94 "required": True, 95 } 96 ], 97 "meta": { 98 "location": self.request.build_absolute_uri( 99 reverse( 100 "authentik_sources_scim:v2-resource-types", 101 kwargs={ 102 "source_slug": self.kwargs["source_slug"], 103 "resource_type": "User", 104 }, 105 ) 106 ), 107 "resourceType": "ResourceType", 108 }, 109 }, 110 { 111 "id": "Group", 112 "name": "Group", 113 "description": "Group", 114 "endpoint": "/Groups", 115 "schema": "urn:ietf:params:scim:schemas:core:2.0:Group", 116 "schemas": [ 117 "urn:ietf:params:scim:schemas:core:2.0:ResourceType", 118 ], 119 "meta": { 120 "resourceType": "ResourceType", 121 "location": self.request.build_absolute_uri( 122 reverse( 123 "authentik_sources_scim:v2-resource-types", 124 kwargs={ 125 "source_slug": self.kwargs["source_slug"], 126 "resource_type": "Group", 127 }, 128 ) 129 ), 130 }, 131 }, 132 ]
List all resource types
def
get( self, request: rest_framework.request.Request, source_slug: str, resource_type: str | None = None) -> rest_framework.response.Response:
135 def get(self, request: Request, source_slug: str, resource_type: str | None = None) -> Response: 136 """Get resource types as SCIM response""" 137 resource_types = self.get_resource_types() 138 if resource_type: 139 resource = [x for x in resource_types if x.get("id") == resource_type] 140 if resource: 141 return Response(resource[0]) 142 raise SCIMNotFoundError("Resource not found.") 143 return Response( 144 { 145 "schemas": ["urn:ietf:params:scim:api:messages:2.0:ListResponse"], 146 "totalResults": len(resource_types), 147 "itemsPerPage": len(resource_types), 148 "startIndex": 1, 149 "Resources": resource_types, 150 } 151 )
Get resource types as SCIM response