sources/oauth: fix OAuth source type serializer (#8140)

* sources/oauth: fix OAuth source type serializer

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

* format

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

---------

Signed-off-by: Jens Langhammer <jens@goauthentik.io>
This commit is contained in:
Jens L 2024-01-12 16:20:29 +01:00 committed by GitHub
parent 24c87a47a6
commit d9eb4c5248
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 22 additions and 8 deletions

View file

@ -24,7 +24,7 @@ class SourceTypeSerializer(PassiveSerializer):
"""Serializer for SourceType"""
name = CharField(required=True)
slug = CharField(required=True)
verbose_name = CharField(required=True)
urls_customizable = BooleanField()
request_token_url = CharField(read_only=True, allow_null=True)
authorization_url = CharField(read_only=True, allow_null=True)

View file

@ -1,13 +1,14 @@
"""OAuth Source tests"""
from django.test import TestCase
from django.urls import reverse
from requests_mock import Mocker
from rest_framework.test import APITestCase
from authentik.core.tests.utils import create_test_admin_user
from authentik.sources.oauth.api.source import OAuthSourceSerializer
from authentik.sources.oauth.models import OAuthSource
class TestOAuthSource(TestCase):
class TestOAuthSource(APITestCase):
"""OAuth Source tests"""
def setUp(self):
@ -20,6 +21,19 @@ class TestOAuthSource(TestCase):
consumer_key="",
)
def test_api_read(self):
"""Test reading a source"""
self.client.force_login(create_test_admin_user())
response = self.client.get(
reverse(
"authentik_api:oauthsource-detail",
kwargs={
"slug": self.source.slug,
},
)
)
self.assertEqual(response.status_code, 200)
def test_api_validate(self):
"""Test API validation"""
self.assertTrue(

View file

@ -42368,7 +42368,7 @@ components:
properties:
name:
type: string
slug:
verbose_name:
type: string
urls_customizable:
type: boolean
@ -42404,8 +42404,8 @@ components:
- oidc_well_known_url
- profile_url
- request_token_url
- slug
- urls_customizable
- verbose_name
SpBindingEnum:
enum:
- redirect

View file

@ -64,7 +64,7 @@ export class OAuthSourceForm extends WithCapabilitiesConfig(BaseSourceForm<OAuth
clearIcon = false;
async send(data: OAuthSource): Promise<OAuthSource> {
data.providerType = (this.providerType?.slug || "") as ProviderTypeEnum;
data.providerType = (this.providerType?.name || "") as ProviderTypeEnum;
let source: OAuthSource;
if (this.instance) {
source = await new SourcesApi(DEFAULT_CONFIG).sourcesOauthPartialUpdate({
@ -178,7 +178,7 @@ export class OAuthSourceForm extends WithCapabilitiesConfig(BaseSourceForm<OAuth
</p>
</ak-form-element-horizontal> `
: html``}
${this.providerType.slug === ProviderTypeEnum.Openidconnect ||
${this.providerType.name === ProviderTypeEnum.Openidconnect ||
this.providerType.oidcWellKnownUrl !== ""
? html`<ak-form-element-horizontal
label=${msg("OIDC Well-known URL")}
@ -200,7 +200,7 @@ export class OAuthSourceForm extends WithCapabilitiesConfig(BaseSourceForm<OAuth
</p>
</ak-form-element-horizontal>`
: html``}
${this.providerType.slug === ProviderTypeEnum.Openidconnect ||
${this.providerType.name === ProviderTypeEnum.Openidconnect ||
this.providerType.oidcJwksUrl !== ""
? html`<ak-form-element-horizontal
label=${msg("OIDC JWKS URL")}