sources/plex: add API for user connections

Signed-off-by: Jens Langhammer <jens.langhammer@beryju.org>
This commit is contained in:
Jens Langhammer 2021-08-17 12:56:38 +02:00
parent 065121d280
commit 84c4547005
7 changed files with 541 additions and 207 deletions

View File

@ -58,7 +58,8 @@ from authentik.providers.saml.api import SAMLPropertyMappingViewSet, SAMLProvide
from authentik.sources.ldap.api import LDAPPropertyMappingViewSet, LDAPSourceViewSet
from authentik.sources.oauth.api.source import OAuthSourceViewSet
from authentik.sources.oauth.api.source_connection import UserOAuthSourceConnectionViewSet
from authentik.sources.plex.api import PlexSourceViewSet
from authentik.sources.plex.api.source import PlexSourceViewSet
from authentik.sources.plex.api.source_connection import PlexSourceConnectionViewSet
from authentik.sources.saml.api import SAMLSourceViewSet
from authentik.stages.authenticator_duo.api import (
AuthenticatorDuoStageViewSet,
@ -127,7 +128,8 @@ router.register("events/transports", NotificationTransportViewSet)
router.register("events/rules", NotificationRuleViewSet)
router.register("sources/all", SourceViewSet)
router.register("sources/oauth_user_connections", UserOAuthSourceConnectionViewSet)
router.register("sources/user_connections/oauth", UserOAuthSourceConnectionViewSet)
router.register("sources/user_connections/plex", PlexSourceConnectionViewSet)
router.register("sources/ldap", LDAPSourceViewSet)
router.register("sources/saml", SAMLSourceViewSet)
router.register("sources/oauth", OAuthSourceViewSet)

View File

View File

@ -0,0 +1,41 @@
"""Plex Source connection Serializer"""
from django_filters.rest_framework import DjangoFilterBackend
from rest_framework import mixins
from rest_framework.filters import OrderingFilter, SearchFilter
from rest_framework.viewsets import GenericViewSet
from authentik.api.authorization import OwnerFilter, OwnerPermissions
from authentik.core.api.sources import SourceSerializer
from authentik.core.api.used_by import UsedByMixin
from authentik.sources.plex.models import PlexSourceConnection
class PlexSourceConnectionSerializer(SourceSerializer):
"""Plex Source connection Serializer"""
class Meta:
model = PlexSourceConnection
fields = [
"pk",
"user",
"source",
"identifier",
"plex_token",
]
class PlexSourceConnectionViewSet(
mixins.RetrieveModelMixin,
mixins.UpdateModelMixin,
mixins.DestroyModelMixin,
UsedByMixin,
mixins.ListModelMixin,
GenericViewSet,
):
"""Plex Source connection Serializer"""
queryset = PlexSourceConnection.objects.all()
serializer_class = PlexSourceConnectionSerializer
filterset_fields = ["source__slug"]
permission_classes = [OwnerPermissions]
filter_backends = [OwnerFilter, DjangoFilterBackend, OrderingFilter, SearchFilter]

View File

@ -56,7 +56,7 @@ class PlexSource(Source):
@property
def serializer(self) -> BaseSerializer:
from authentik.sources.plex.api import PlexSourceSerializer
from authentik.sources.plex.api.source import PlexSourceSerializer
return PlexSourceSerializer

View File

@ -13197,208 +13197,6 @@ paths:
$ref: '#/components/schemas/ValidationError'
'403':
$ref: '#/components/schemas/GenericError'
/api/v2beta/sources/oauth_user_connections/:
get:
operationId: sources_oauth_user_connections_list
description: Source Viewset
parameters:
- name: ordering
required: false
in: query
description: Which field to use when ordering the results.
schema:
type: string
- name: page
required: false
in: query
description: A page number within the paginated result set.
schema:
type: integer
- name: page_size
required: false
in: query
description: Number of results to return per page.
schema:
type: integer
- name: search
required: false
in: query
description: A search term.
schema:
type: string
- in: query
name: source__slug
schema:
type: string
tags:
- sources
security:
- authentik: []
- cookieAuth: []
responses:
'200':
content:
application/json:
schema:
$ref: '#/components/schemas/PaginatedUserOAuthSourceConnectionList'
description: ''
'400':
$ref: '#/components/schemas/ValidationError'
'403':
$ref: '#/components/schemas/GenericError'
/api/v2beta/sources/oauth_user_connections/{id}/:
get:
operationId: sources_oauth_user_connections_retrieve
description: Source Viewset
parameters:
- in: path
name: id
schema:
type: integer
description: A unique integer value identifying this User OAuth Source Connection.
required: true
tags:
- sources
security:
- authentik: []
- cookieAuth: []
responses:
'200':
content:
application/json:
schema:
$ref: '#/components/schemas/UserOAuthSourceConnection'
description: ''
'400':
$ref: '#/components/schemas/ValidationError'
'403':
$ref: '#/components/schemas/GenericError'
put:
operationId: sources_oauth_user_connections_update
description: Source Viewset
parameters:
- in: path
name: id
schema:
type: integer
description: A unique integer value identifying this User OAuth Source Connection.
required: true
tags:
- sources
requestBody:
content:
application/json:
schema:
$ref: '#/components/schemas/UserOAuthSourceConnectionRequest'
application/x-www-form-urlencoded:
schema:
$ref: '#/components/schemas/UserOAuthSourceConnectionRequest'
multipart/form-data:
schema:
$ref: '#/components/schemas/UserOAuthSourceConnectionRequest'
required: true
security:
- authentik: []
- cookieAuth: []
responses:
'200':
content:
application/json:
schema:
$ref: '#/components/schemas/UserOAuthSourceConnection'
description: ''
'400':
$ref: '#/components/schemas/ValidationError'
'403':
$ref: '#/components/schemas/GenericError'
patch:
operationId: sources_oauth_user_connections_partial_update
description: Source Viewset
parameters:
- in: path
name: id
schema:
type: integer
description: A unique integer value identifying this User OAuth Source Connection.
required: true
tags:
- sources
requestBody:
content:
application/json:
schema:
$ref: '#/components/schemas/PatchedUserOAuthSourceConnectionRequest'
application/x-www-form-urlencoded:
schema:
$ref: '#/components/schemas/PatchedUserOAuthSourceConnectionRequest'
multipart/form-data:
schema:
$ref: '#/components/schemas/PatchedUserOAuthSourceConnectionRequest'
security:
- authentik: []
- cookieAuth: []
responses:
'200':
content:
application/json:
schema:
$ref: '#/components/schemas/UserOAuthSourceConnection'
description: ''
'400':
$ref: '#/components/schemas/ValidationError'
'403':
$ref: '#/components/schemas/GenericError'
delete:
operationId: sources_oauth_user_connections_destroy
description: Source Viewset
parameters:
- in: path
name: id
schema:
type: integer
description: A unique integer value identifying this User OAuth Source Connection.
required: true
tags:
- sources
security:
- authentik: []
- cookieAuth: []
responses:
'204':
description: No response body
'400':
$ref: '#/components/schemas/ValidationError'
'403':
$ref: '#/components/schemas/GenericError'
/api/v2beta/sources/oauth_user_connections/{id}/used_by/:
get:
operationId: sources_oauth_user_connections_used_by_list
description: Get a list of all objects that use this object
parameters:
- in: path
name: id
schema:
type: integer
description: A unique integer value identifying this User OAuth Source Connection.
required: true
tags:
- sources
security:
- authentik: []
- cookieAuth: []
responses:
'200':
content:
application/json:
schema:
type: array
items:
$ref: '#/components/schemas/UsedBy'
description: ''
'400':
$ref: '#/components/schemas/ValidationError'
'403':
$ref: '#/components/schemas/GenericError'
/api/v2beta/sources/plex/:
get:
operationId: sources_plex_list
@ -14110,6 +13908,410 @@ paths:
$ref: '#/components/schemas/ValidationError'
'403':
$ref: '#/components/schemas/GenericError'
/api/v2beta/sources/user_connections/oauth/:
get:
operationId: sources_user_connections_oauth_list
description: Source Viewset
parameters:
- name: ordering
required: false
in: query
description: Which field to use when ordering the results.
schema:
type: string
- name: page
required: false
in: query
description: A page number within the paginated result set.
schema:
type: integer
- name: page_size
required: false
in: query
description: Number of results to return per page.
schema:
type: integer
- name: search
required: false
in: query
description: A search term.
schema:
type: string
- in: query
name: source__slug
schema:
type: string
tags:
- sources
security:
- authentik: []
- cookieAuth: []
responses:
'200':
content:
application/json:
schema:
$ref: '#/components/schemas/PaginatedUserOAuthSourceConnectionList'
description: ''
'400':
$ref: '#/components/schemas/ValidationError'
'403':
$ref: '#/components/schemas/GenericError'
/api/v2beta/sources/user_connections/oauth/{id}/:
get:
operationId: sources_user_connections_oauth_retrieve
description: Source Viewset
parameters:
- in: path
name: id
schema:
type: integer
description: A unique integer value identifying this User OAuth Source Connection.
required: true
tags:
- sources
security:
- authentik: []
- cookieAuth: []
responses:
'200':
content:
application/json:
schema:
$ref: '#/components/schemas/UserOAuthSourceConnection'
description: ''
'400':
$ref: '#/components/schemas/ValidationError'
'403':
$ref: '#/components/schemas/GenericError'
put:
operationId: sources_user_connections_oauth_update
description: Source Viewset
parameters:
- in: path
name: id
schema:
type: integer
description: A unique integer value identifying this User OAuth Source Connection.
required: true
tags:
- sources
requestBody:
content:
application/json:
schema:
$ref: '#/components/schemas/UserOAuthSourceConnectionRequest'
application/x-www-form-urlencoded:
schema:
$ref: '#/components/schemas/UserOAuthSourceConnectionRequest'
multipart/form-data:
schema:
$ref: '#/components/schemas/UserOAuthSourceConnectionRequest'
required: true
security:
- authentik: []
- cookieAuth: []
responses:
'200':
content:
application/json:
schema:
$ref: '#/components/schemas/UserOAuthSourceConnection'
description: ''
'400':
$ref: '#/components/schemas/ValidationError'
'403':
$ref: '#/components/schemas/GenericError'
patch:
operationId: sources_user_connections_oauth_partial_update
description: Source Viewset
parameters:
- in: path
name: id
schema:
type: integer
description: A unique integer value identifying this User OAuth Source Connection.
required: true
tags:
- sources
requestBody:
content:
application/json:
schema:
$ref: '#/components/schemas/PatchedUserOAuthSourceConnectionRequest'
application/x-www-form-urlencoded:
schema:
$ref: '#/components/schemas/PatchedUserOAuthSourceConnectionRequest'
multipart/form-data:
schema:
$ref: '#/components/schemas/PatchedUserOAuthSourceConnectionRequest'
security:
- authentik: []
- cookieAuth: []
responses:
'200':
content:
application/json:
schema:
$ref: '#/components/schemas/UserOAuthSourceConnection'
description: ''
'400':
$ref: '#/components/schemas/ValidationError'
'403':
$ref: '#/components/schemas/GenericError'
delete:
operationId: sources_user_connections_oauth_destroy
description: Source Viewset
parameters:
- in: path
name: id
schema:
type: integer
description: A unique integer value identifying this User OAuth Source Connection.
required: true
tags:
- sources
security:
- authentik: []
- cookieAuth: []
responses:
'204':
description: No response body
'400':
$ref: '#/components/schemas/ValidationError'
'403':
$ref: '#/components/schemas/GenericError'
/api/v2beta/sources/user_connections/oauth/{id}/used_by/:
get:
operationId: sources_user_connections_oauth_used_by_list
description: Get a list of all objects that use this object
parameters:
- in: path
name: id
schema:
type: integer
description: A unique integer value identifying this User OAuth Source Connection.
required: true
tags:
- sources
security:
- authentik: []
- cookieAuth: []
responses:
'200':
content:
application/json:
schema:
type: array
items:
$ref: '#/components/schemas/UsedBy'
description: ''
'400':
$ref: '#/components/schemas/ValidationError'
'403':
$ref: '#/components/schemas/GenericError'
/api/v2beta/sources/user_connections/plex/:
get:
operationId: sources_user_connections_plex_list
description: Plex Source connection Serializer
parameters:
- name: ordering
required: false
in: query
description: Which field to use when ordering the results.
schema:
type: string
- name: page
required: false
in: query
description: A page number within the paginated result set.
schema:
type: integer
- name: page_size
required: false
in: query
description: Number of results to return per page.
schema:
type: integer
- name: search
required: false
in: query
description: A search term.
schema:
type: string
- in: query
name: source__slug
schema:
type: string
tags:
- sources
security:
- authentik: []
- cookieAuth: []
responses:
'200':
content:
application/json:
schema:
$ref: '#/components/schemas/PaginatedPlexSourceConnectionList'
description: ''
'400':
$ref: '#/components/schemas/ValidationError'
'403':
$ref: '#/components/schemas/GenericError'
/api/v2beta/sources/user_connections/plex/{id}/:
get:
operationId: sources_user_connections_plex_retrieve
description: Plex Source connection Serializer
parameters:
- in: path
name: id
schema:
type: integer
description: A unique integer value identifying this User Plex Source Connection.
required: true
tags:
- sources
security:
- authentik: []
- cookieAuth: []
responses:
'200':
content:
application/json:
schema:
$ref: '#/components/schemas/PlexSourceConnection'
description: ''
'400':
$ref: '#/components/schemas/ValidationError'
'403':
$ref: '#/components/schemas/GenericError'
put:
operationId: sources_user_connections_plex_update
description: Plex Source connection Serializer
parameters:
- in: path
name: id
schema:
type: integer
description: A unique integer value identifying this User Plex Source Connection.
required: true
tags:
- sources
requestBody:
content:
application/json:
schema:
$ref: '#/components/schemas/PlexSourceConnectionRequest'
application/x-www-form-urlencoded:
schema:
$ref: '#/components/schemas/PlexSourceConnectionRequest'
multipart/form-data:
schema:
$ref: '#/components/schemas/PlexSourceConnectionRequest'
required: true
security:
- authentik: []
- cookieAuth: []
responses:
'200':
content:
application/json:
schema:
$ref: '#/components/schemas/PlexSourceConnection'
description: ''
'400':
$ref: '#/components/schemas/ValidationError'
'403':
$ref: '#/components/schemas/GenericError'
patch:
operationId: sources_user_connections_plex_partial_update
description: Plex Source connection Serializer
parameters:
- in: path
name: id
schema:
type: integer
description: A unique integer value identifying this User Plex Source Connection.
required: true
tags:
- sources
requestBody:
content:
application/json:
schema:
$ref: '#/components/schemas/PatchedPlexSourceConnectionRequest'
application/x-www-form-urlencoded:
schema:
$ref: '#/components/schemas/PatchedPlexSourceConnectionRequest'
multipart/form-data:
schema:
$ref: '#/components/schemas/PatchedPlexSourceConnectionRequest'
security:
- authentik: []
- cookieAuth: []
responses:
'200':
content:
application/json:
schema:
$ref: '#/components/schemas/PlexSourceConnection'
description: ''
'400':
$ref: '#/components/schemas/ValidationError'
'403':
$ref: '#/components/schemas/GenericError'
delete:
operationId: sources_user_connections_plex_destroy
description: Plex Source connection Serializer
parameters:
- in: path
name: id
schema:
type: integer
description: A unique integer value identifying this User Plex Source Connection.
required: true
tags:
- sources
security:
- authentik: []
- cookieAuth: []
responses:
'204':
description: No response body
'400':
$ref: '#/components/schemas/ValidationError'
'403':
$ref: '#/components/schemas/GenericError'
/api/v2beta/sources/user_connections/plex/{id}/used_by/:
get:
operationId: sources_user_connections_plex_used_by_list
description: Get a list of all objects that use this object
parameters:
- in: path
name: id
schema:
type: integer
description: A unique integer value identifying this User Plex Source Connection.
required: true
tags:
- sources
security:
- authentik: []
- cookieAuth: []
responses:
'200':
content:
application/json:
schema:
type: array
items:
$ref: '#/components/schemas/UsedBy'
description: ''
'400':
$ref: '#/components/schemas/ValidationError'
'403':
$ref: '#/components/schemas/GenericError'
/api/v2beta/stages/all/:
get:
operationId: stages_all_list
@ -24767,6 +24969,41 @@ components:
required:
- pagination
- results
PaginatedPlexSourceConnectionList:
type: object
properties:
pagination:
type: object
properties:
next:
type: number
previous:
type: number
count:
type: number
current:
type: number
total_pages:
type: number
start_index:
type: number
end_index:
type: number
required:
- next
- previous
- count
- current
- total_pages
- start_index
- end_index
results:
type: array
items:
$ref: '#/components/schemas/PlexSourceConnection'
required:
- pagination
- results
PaginatedPlexSourceList:
type: object
properties:
@ -27099,6 +27336,19 @@ components:
minimum: -2147483648
description: How many attempts a user has before the flow is canceled. To
lock the user out, use a reputation policy and a user_write stage.
PatchedPlexSourceConnectionRequest:
type: object
description: Plex Source connection Serializer
properties:
user:
type: integer
source:
type: string
format: uuid
identifier:
type: string
plex_token:
type: string
PatchedPlexSourceRequest:
type: object
description: Plex Source Serializer
@ -27775,6 +28025,47 @@ components:
- slug
- verbose_name
- verbose_name_plural
PlexSourceConnection:
type: object
description: Plex Source connection Serializer
properties:
pk:
type: integer
readOnly: true
title: ID
user:
type: integer
source:
type: string
format: uuid
identifier:
type: string
plex_token:
type: string
required:
- identifier
- pk
- plex_token
- source
- user
PlexSourceConnectionRequest:
type: object
description: Plex Source connection Serializer
properties:
user:
type: integer
source:
type: string
format: uuid
identifier:
type: string
plex_token:
type: string
required:
- identifier
- plex_token
- source
- user
PlexSourceRequest:
type: object
description: Plex Source Serializer

View File

@ -21,7 +21,7 @@ export class SourceSettingsOAuth extends BaseUserSettings {
renderInner(): TemplateResult {
return html`${until(
new SourcesApi(DEFAULT_CONFIG)
.sourcesOauthUserConnectionsList({
.sourcesUserConnectionsOauthList({
sourceSlug: this.objectId,
})
.then((connection) => {
@ -32,7 +32,7 @@ export class SourceSettingsOAuth extends BaseUserSettings {
@click=${() => {
return new SourcesApi(
DEFAULT_CONFIG,
).sourcesOauthUserConnectionsDestroy({
).sourcesUserConnectionsOauthDestroy({
id: connection.results[0].pk || 0,
});
}}