sources/oauth: allow creation of user connection objects with parameters (#12195)

* sources/oauth: allow creation of user connection objects with parameters

Signed-off-by: Jens Langhammer <jens@goauthentik.io>

* fix web

Signed-off-by: Jens Langhammer <jens@goauthentik.io>

* tix tests

Signed-off-by: Jens Langhammer <jens@goauthentik.io>

* add for all

Signed-off-by: Jens Langhammer <jens@goauthentik.io>

* align

Signed-off-by: Jens Langhammer <jens@goauthentik.io>

---------

Signed-off-by: Jens Langhammer <jens@goauthentik.io>
This commit is contained in:
Jens L.
2024-12-18 13:28:22 +01:00
committed by GitHub
parent 1573cfbaa1
commit 1a1d499833
5 changed files with 380 additions and 22 deletions

View File

@ -159,9 +159,9 @@ class SourceViewSet(
class UserSourceConnectionSerializer(SourceSerializer): class UserSourceConnectionSerializer(SourceSerializer):
"""OAuth Source Serializer""" """User source connection"""
source = SourceSerializer(read_only=True) source_obj = SourceSerializer(read_only=True, source="source")
class Meta: class Meta:
model = UserSourceConnection model = UserSourceConnection
@ -169,10 +169,10 @@ class UserSourceConnectionSerializer(SourceSerializer):
"pk", "pk",
"user", "user",
"source", "source",
"source_obj",
"created", "created",
] ]
extra_kwargs = { extra_kwargs = {
"user": {"read_only": True},
"created": {"read_only": True}, "created": {"read_only": True},
} }
@ -197,9 +197,9 @@ class UserSourceConnectionViewSet(
class GroupSourceConnectionSerializer(SourceSerializer): class GroupSourceConnectionSerializer(SourceSerializer):
"""Group Source Connection Serializer""" """Group Source Connection"""
source = SourceSerializer(read_only=True) source_obj = SourceSerializer(read_only=True)
class Meta: class Meta:
model = GroupSourceConnection model = GroupSourceConnection
@ -207,12 +207,11 @@ class GroupSourceConnectionSerializer(SourceSerializer):
"pk", "pk",
"group", "group",
"source", "source",
"source_obj",
"identifier", "identifier",
"created", "created",
] ]
extra_kwargs = { extra_kwargs = {
"group": {"read_only": True},
"identifier": {"read_only": True},
"created": {"read_only": True}, "created": {"read_only": True},
} }

View File

@ -7170,6 +7170,10 @@
"type": "integer", "type": "integer",
"title": "User" "title": "User"
}, },
"source": {
"type": "integer",
"title": "Source"
},
"identifier": { "identifier": {
"type": "string", "type": "string",
"minLength": 1, "minLength": 1,
@ -7212,6 +7216,20 @@
"model_authentik_sources_kerberos.groupkerberossourceconnection": { "model_authentik_sources_kerberos.groupkerberossourceconnection": {
"type": "object", "type": "object",
"properties": { "properties": {
"group": {
"type": "string",
"format": "uuid",
"title": "Group"
},
"source": {
"type": "integer",
"title": "Source"
},
"identifier": {
"type": "string",
"minLength": 1,
"title": "Identifier"
},
"icon": { "icon": {
"type": "string", "type": "string",
"minLength": 1, "minLength": 1,
@ -7755,6 +7773,14 @@
"model_authentik_sources_oauth.useroauthsourceconnection": { "model_authentik_sources_oauth.useroauthsourceconnection": {
"type": "object", "type": "object",
"properties": { "properties": {
"user": {
"type": "integer",
"title": "User"
},
"source": {
"type": "integer",
"title": "Source"
},
"identifier": { "identifier": {
"type": "string", "type": "string",
"maxLength": 255, "maxLength": 255,
@ -7805,6 +7831,20 @@
"model_authentik_sources_oauth.groupoauthsourceconnection": { "model_authentik_sources_oauth.groupoauthsourceconnection": {
"type": "object", "type": "object",
"properties": { "properties": {
"group": {
"type": "string",
"format": "uuid",
"title": "Group"
},
"source": {
"type": "integer",
"title": "Source"
},
"identifier": {
"type": "string",
"minLength": 1,
"title": "Identifier"
},
"icon": { "icon": {
"type": "string", "type": "string",
"minLength": 1, "minLength": 1,
@ -8038,6 +8078,14 @@
"model_authentik_sources_plex.userplexsourceconnection": { "model_authentik_sources_plex.userplexsourceconnection": {
"type": "object", "type": "object",
"properties": { "properties": {
"user": {
"type": "integer",
"title": "User"
},
"source": {
"type": "integer",
"title": "Source"
},
"identifier": { "identifier": {
"type": "string", "type": "string",
"minLength": 1, "minLength": 1,
@ -8085,6 +8133,20 @@
"model_authentik_sources_plex.groupplexsourceconnection": { "model_authentik_sources_plex.groupplexsourceconnection": {
"type": "object", "type": "object",
"properties": { "properties": {
"group": {
"type": "string",
"format": "uuid",
"title": "Group"
},
"source": {
"type": "integer",
"title": "Source"
},
"identifier": {
"type": "string",
"minLength": 1,
"title": "Identifier"
},
"icon": { "icon": {
"type": "string", "type": "string",
"minLength": 1, "minLength": 1,
@ -8395,6 +8457,14 @@
"model_authentik_sources_saml.usersamlsourceconnection": { "model_authentik_sources_saml.usersamlsourceconnection": {
"type": "object", "type": "object",
"properties": { "properties": {
"user": {
"type": "integer",
"title": "User"
},
"source": {
"type": "integer",
"title": "Source"
},
"identifier": { "identifier": {
"type": "string", "type": "string",
"minLength": 1, "minLength": 1,
@ -8437,6 +8507,20 @@
"model_authentik_sources_saml.groupsamlsourceconnection": { "model_authentik_sources_saml.groupsamlsourceconnection": {
"type": "object", "type": "object",
"properties": { "properties": {
"group": {
"type": "string",
"format": "uuid",
"title": "Group"
},
"source": {
"type": "integer",
"title": "Source"
},
"identifier": {
"type": "string",
"minLength": 1,
"title": "Identifier"
},
"icon": { "icon": {
"type": "string", "type": "string",
"minLength": 1, "minLength": 1,

View File

@ -25008,6 +25008,12 @@ paths:
required: true required: true
tags: tags:
- sources - sources
requestBody:
content:
application/json:
schema:
$ref: '#/components/schemas/GroupKerberosSourceConnectionRequest'
required: true
security: security:
- authentik: [] - authentik: []
responses: responses:
@ -25042,6 +25048,11 @@ paths:
required: true required: true
tags: tags:
- sources - sources
requestBody:
content:
application/json:
schema:
$ref: '#/components/schemas/PatchedGroupKerberosSourceConnectionRequest'
security: security:
- authentik: [] - authentik: []
responses: responses:
@ -25196,6 +25207,12 @@ paths:
description: Group-source connection Viewset description: Group-source connection Viewset
tags: tags:
- sources - sources
requestBody:
content:
application/json:
schema:
$ref: '#/components/schemas/GroupOAuthSourceConnectionRequest'
required: true
security: security:
- authentik: [] - authentik: []
responses: responses:
@ -25263,6 +25280,12 @@ paths:
required: true required: true
tags: tags:
- sources - sources
requestBody:
content:
application/json:
schema:
$ref: '#/components/schemas/GroupOAuthSourceConnectionRequest'
required: true
security: security:
- authentik: [] - authentik: []
responses: responses:
@ -25296,6 +25319,11 @@ paths:
required: true required: true
tags: tags:
- sources - sources
requestBody:
content:
application/json:
schema:
$ref: '#/components/schemas/PatchedGroupOAuthSourceConnectionRequest'
security: security:
- authentik: [] - authentik: []
responses: responses:
@ -25448,6 +25476,12 @@ paths:
description: Group-source connection Viewset description: Group-source connection Viewset
tags: tags:
- sources - sources
requestBody:
content:
application/json:
schema:
$ref: '#/components/schemas/GroupPlexSourceConnectionRequest'
required: true
security: security:
- authentik: [] - authentik: []
responses: responses:
@ -25515,6 +25549,12 @@ paths:
required: true required: true
tags: tags:
- sources - sources
requestBody:
content:
application/json:
schema:
$ref: '#/components/schemas/GroupPlexSourceConnectionRequest'
required: true
security: security:
- authentik: [] - authentik: []
responses: responses:
@ -25548,6 +25588,11 @@ paths:
required: true required: true
tags: tags:
- sources - sources
requestBody:
content:
application/json:
schema:
$ref: '#/components/schemas/PatchedGroupPlexSourceConnectionRequest'
security: security:
- authentik: [] - authentik: []
responses: responses:
@ -25741,6 +25786,12 @@ paths:
required: true required: true
tags: tags:
- sources - sources
requestBody:
content:
application/json:
schema:
$ref: '#/components/schemas/GroupSAMLSourceConnectionRequest'
required: true
security: security:
- authentik: [] - authentik: []
responses: responses:
@ -25774,6 +25825,11 @@ paths:
required: true required: true
tags: tags:
- sources - sources
requestBody:
content:
application/json:
schema:
$ref: '#/components/schemas/PatchedGroupSAMLSourceConnectionRequest'
security: security:
- authentik: [] - authentik: []
responses: responses:
@ -28734,6 +28790,12 @@ paths:
required: true required: true
tags: tags:
- sources - sources
requestBody:
content:
application/json:
schema:
$ref: '#/components/schemas/UserSourceConnectionRequest'
required: true
security: security:
- authentik: [] - authentik: []
responses: responses:
@ -28767,6 +28829,11 @@ paths:
required: true required: true
tags: tags:
- sources - sources
requestBody:
content:
application/json:
schema:
$ref: '#/components/schemas/PatchedUserSourceConnectionRequest'
security: security:
- authentik: [] - authentik: []
responses: responses:
@ -42555,14 +42622,15 @@ components:
group: group:
type: string type: string
format: uuid format: uuid
readOnly: true
source: source:
type: string
format: uuid
source_obj:
allOf: allOf:
- $ref: '#/components/schemas/Source' - $ref: '#/components/schemas/Source'
readOnly: true readOnly: true
identifier: identifier:
type: string type: string
readOnly: true
created: created:
type: string type: string
format: date-time format: date-time
@ -42573,6 +42641,24 @@ components:
- identifier - identifier
- pk - pk
- source - source
- source_obj
GroupKerberosSourceConnectionRequest:
type: object
description: OAuth Group-Source connection Serializer
properties:
group:
type: string
format: uuid
source:
type: string
format: uuid
identifier:
type: string
minLength: 1
required:
- group
- identifier
- source
GroupMatchingModeEnum: GroupMatchingModeEnum:
enum: enum:
- identifier - identifier
@ -42667,14 +42753,15 @@ components:
group: group:
type: string type: string
format: uuid format: uuid
readOnly: true
source: source:
type: string
format: uuid
source_obj:
allOf: allOf:
- $ref: '#/components/schemas/Source' - $ref: '#/components/schemas/Source'
readOnly: true readOnly: true
identifier: identifier:
type: string type: string
readOnly: true
created: created:
type: string type: string
format: date-time format: date-time
@ -42685,6 +42772,24 @@ components:
- identifier - identifier
- pk - pk
- source - source
- source_obj
GroupOAuthSourceConnectionRequest:
type: object
description: OAuth Group-Source connection Serializer
properties:
group:
type: string
format: uuid
source:
type: string
format: uuid
identifier:
type: string
minLength: 1
required:
- group
- identifier
- source
GroupPlexSourceConnection: GroupPlexSourceConnection:
type: object type: object
description: Plex Group-Source connection Serializer description: Plex Group-Source connection Serializer
@ -42696,14 +42801,15 @@ components:
group: group:
type: string type: string
format: uuid format: uuid
readOnly: true
source: source:
type: string
format: uuid
source_obj:
allOf: allOf:
- $ref: '#/components/schemas/Source' - $ref: '#/components/schemas/Source'
readOnly: true readOnly: true
identifier: identifier:
type: string type: string
readOnly: true
created: created:
type: string type: string
format: date-time format: date-time
@ -42714,6 +42820,24 @@ components:
- identifier - identifier
- pk - pk
- source - source
- source_obj
GroupPlexSourceConnectionRequest:
type: object
description: Plex Group-Source connection Serializer
properties:
group:
type: string
format: uuid
source:
type: string
format: uuid
identifier:
type: string
minLength: 1
required:
- group
- identifier
- source
GroupRequest: GroupRequest:
type: object type: object
description: Group Serializer description: Group Serializer
@ -42753,14 +42877,15 @@ components:
group: group:
type: string type: string
format: uuid format: uuid
readOnly: true
source: source:
type: string
format: uuid
source_obj:
allOf: allOf:
- $ref: '#/components/schemas/Source' - $ref: '#/components/schemas/Source'
readOnly: true readOnly: true
identifier: identifier:
type: string type: string
readOnly: true
created: created:
type: string type: string
format: date-time format: date-time
@ -42771,6 +42896,24 @@ components:
- identifier - identifier
- pk - pk
- source - source
- source_obj
GroupSAMLSourceConnectionRequest:
type: object
description: OAuth Group-Source connection Serializer
properties:
group:
type: string
format: uuid
source:
type: string
format: uuid
identifier:
type: string
minLength: 1
required:
- group
- identifier
- source
IdentificationChallenge: IdentificationChallenge:
type: object type: object
description: Identification challenges with all UI elements description: Identification challenges with all UI elements
@ -48562,6 +48705,45 @@ components:
default_group_email_domain: default_group_email_domain:
type: string type: string
minLength: 1 minLength: 1
PatchedGroupKerberosSourceConnectionRequest:
type: object
description: OAuth Group-Source connection Serializer
properties:
group:
type: string
format: uuid
source:
type: string
format: uuid
identifier:
type: string
minLength: 1
PatchedGroupOAuthSourceConnectionRequest:
type: object
description: OAuth Group-Source connection Serializer
properties:
group:
type: string
format: uuid
source:
type: string
format: uuid
identifier:
type: string
minLength: 1
PatchedGroupPlexSourceConnectionRequest:
type: object
description: Plex Group-Source connection Serializer
properties:
group:
type: string
format: uuid
source:
type: string
format: uuid
identifier:
type: string
minLength: 1
PatchedGroupRequest: PatchedGroupRequest:
type: object type: object
description: Group Serializer description: Group Serializer
@ -48588,6 +48770,19 @@ components:
items: items:
type: string type: string
format: uuid format: uuid
PatchedGroupSAMLSourceConnectionRequest:
type: object
description: OAuth Group-Source connection Serializer
properties:
group:
type: string
format: uuid
source:
type: string
format: uuid
identifier:
type: string
minLength: 1
PatchedIdentificationStageRequest: PatchedIdentificationStageRequest:
type: object type: object
description: IdentificationStage Serializer description: IdentificationStage Serializer
@ -50510,6 +50705,9 @@ components:
properties: properties:
user: user:
type: integer type: integer
source:
type: string
format: uuid
identifier: identifier:
type: string type: string
minLength: 1 minLength: 1
@ -50562,6 +50760,11 @@ components:
type: object type: object
description: OAuth Source Serializer description: OAuth Source Serializer
properties: properties:
user:
type: integer
source:
type: string
format: uuid
identifier: identifier:
type: string type: string
minLength: 1 minLength: 1
@ -50574,6 +50777,11 @@ components:
type: object type: object
description: Plex Source connection Serializer description: Plex Source connection Serializer
properties: properties:
user:
type: integer
source:
type: string
format: uuid
identifier: identifier:
type: string type: string
minLength: 1 minLength: 1
@ -50623,9 +50831,23 @@ components:
type: object type: object
description: SAML Source Serializer description: SAML Source Serializer
properties: properties:
user:
type: integer
source:
type: string
format: uuid
identifier: identifier:
type: string type: string
minLength: 1 minLength: 1
PatchedUserSourceConnectionRequest:
type: object
description: User source connection
properties:
user:
type: integer
source:
type: string
format: uuid
PatchedUserWriteStageRequest: PatchedUserWriteStageRequest:
type: object type: object
description: UserWriteStage Serializer description: UserWriteStage Serializer
@ -55550,6 +55772,9 @@ components:
user: user:
type: integer type: integer
source: source:
type: string
format: uuid
source_obj:
allOf: allOf:
- $ref: '#/components/schemas/Source' - $ref: '#/components/schemas/Source'
readOnly: true readOnly: true
@ -55564,6 +55789,7 @@ components:
- identifier - identifier
- pk - pk
- source - source
- source_obj
- user - user
UserKerberosSourceConnectionRequest: UserKerberosSourceConnectionRequest:
type: object type: object
@ -55571,11 +55797,15 @@ components:
properties: properties:
user: user:
type: integer type: integer
source:
type: string
format: uuid
identifier: identifier:
type: string type: string
minLength: 1 minLength: 1
required: required:
- identifier - identifier
- source
- user - user
UserLoginChallenge: UserLoginChallenge:
type: object type: object
@ -55798,8 +56028,10 @@ components:
title: ID title: ID
user: user:
type: integer type: integer
readOnly: true
source: source:
type: string
format: uuid
source_obj:
allOf: allOf:
- $ref: '#/components/schemas/Source' - $ref: '#/components/schemas/Source'
readOnly: true readOnly: true
@ -55815,11 +56047,17 @@ components:
- identifier - identifier
- pk - pk
- source - source
- source_obj
- user - user
UserOAuthSourceConnectionRequest: UserOAuthSourceConnectionRequest:
type: object type: object
description: OAuth Source Serializer description: OAuth Source Serializer
properties: properties:
user:
type: integer
source:
type: string
format: uuid
identifier: identifier:
type: string type: string
minLength: 1 minLength: 1
@ -55830,6 +56068,8 @@ components:
nullable: true nullable: true
required: required:
- identifier - identifier
- source
- user
UserObjectPermission: UserObjectPermission:
type: object type: object
description: User-bound object level permission description: User-bound object level permission
@ -55887,8 +56127,10 @@ components:
title: ID title: ID
user: user:
type: integer type: integer
readOnly: true
source: source:
type: string
format: uuid
source_obj:
allOf: allOf:
- $ref: '#/components/schemas/Source' - $ref: '#/components/schemas/Source'
readOnly: true readOnly: true
@ -55903,11 +56145,17 @@ components:
- identifier - identifier
- pk - pk
- source - source
- source_obj
- user - user
UserPlexSourceConnectionRequest: UserPlexSourceConnectionRequest:
type: object type: object
description: Plex Source connection Serializer description: Plex Source connection Serializer
properties: properties:
user:
type: integer
source:
type: string
format: uuid
identifier: identifier:
type: string type: string
minLength: 1 minLength: 1
@ -55918,6 +56166,8 @@ components:
required: required:
- identifier - identifier
- plex_token - plex_token
- source
- user
UserRequest: UserRequest:
type: object type: object
description: User Serializer description: User Serializer
@ -55969,8 +56219,10 @@ components:
title: ID title: ID
user: user:
type: integer type: integer
readOnly: true
source: source:
type: string
format: uuid
source_obj:
allOf: allOf:
- $ref: '#/components/schemas/Source' - $ref: '#/components/schemas/Source'
readOnly: true readOnly: true
@ -55985,16 +56237,24 @@ components:
- identifier - identifier
- pk - pk
- source - source
- source_obj
- user - user
UserSAMLSourceConnectionRequest: UserSAMLSourceConnectionRequest:
type: object type: object
description: SAML Source Serializer description: SAML Source Serializer
properties: properties:
user:
type: integer
source:
type: string
format: uuid
identifier: identifier:
type: string type: string
minLength: 1 minLength: 1
required: required:
- identifier - identifier
- source
- user
UserSelf: UserSelf:
type: object type: object
description: User Serializer for information a user can retrieve about themselves description: User Serializer for information a user can retrieve about themselves
@ -56130,7 +56390,7 @@ components:
- title - title
UserSourceConnection: UserSourceConnection:
type: object type: object
description: OAuth Source Serializer description: User source connection
properties: properties:
pk: pk:
type: integer type: integer
@ -56138,8 +56398,10 @@ components:
title: ID title: ID
user: user:
type: integer type: integer
readOnly: true
source: source:
type: string
format: uuid
source_obj:
allOf: allOf:
- $ref: '#/components/schemas/Source' - $ref: '#/components/schemas/Source'
readOnly: true readOnly: true
@ -56151,6 +56413,19 @@ components:
- created - created
- pk - pk
- source - source
- source_obj
- user
UserSourceConnectionRequest:
type: object
description: User source connection
properties:
user:
type: integer
source:
type: string
format: uuid
required:
- source
- user - user
UserTypeEnum: UserTypeEnum:
enum: enum:

View File

@ -192,5 +192,5 @@ class TestSourceOAuth2(SeleniumTestCase):
results = body_json["results"] results = body_json["results"]
self.assertEqual(len(results), 1) self.assertEqual(len(results), 1)
connection = results[0] connection = results[0]
self.assertEqual(connection["source"]["slug"], self.slug) self.assertEqual(connection["source_obj"]["slug"], self.slug)
self.assertEqual(connection["user"], self.user.pk) self.assertEqual(connection["user"], self.user.pk)

View File

@ -70,7 +70,7 @@ export class UserSourceSettingsPage extends AKElement {
let connectionPk = -1; let connectionPk = -1;
if (this.connections) { if (this.connections) {
const connections = this.connections.results.filter( const connections = this.connections.results.filter(
(con) => con.source.slug === source.objectUid, (con) => con.sourceObj.slug === source.objectUid,
); );
if (connections.length > 0) { if (connections.length > 0) {
connectionPk = connections[0].pk; connectionPk = connections[0].pk;