core: include more authenticator details when possible (#15224)
Signed-off-by: Jens Langhammer <jens@goauthentik.io>
This commit is contained in:
@ -1,6 +1,5 @@
|
|||||||
"""Authenticator Devices API Views"""
|
"""Authenticator Devices API Views"""
|
||||||
|
|
||||||
from django.utils.translation import gettext_lazy as _
|
|
||||||
from drf_spectacular.utils import extend_schema
|
from drf_spectacular.utils import extend_schema
|
||||||
from guardian.shortcuts import get_objects_for_user
|
from guardian.shortcuts import get_objects_for_user
|
||||||
from rest_framework.fields import (
|
from rest_framework.fields import (
|
||||||
@ -23,7 +22,7 @@ from authentik.stages.authenticator_webauthn.models import WebAuthnDevice
|
|||||||
|
|
||||||
|
|
||||||
class DeviceSerializer(MetaNameSerializer):
|
class DeviceSerializer(MetaNameSerializer):
|
||||||
"""Serializer for Duo authenticator devices"""
|
"""Serializer for authenticator devices"""
|
||||||
|
|
||||||
pk = CharField()
|
pk = CharField()
|
||||||
name = CharField()
|
name = CharField()
|
||||||
@ -33,22 +32,27 @@ class DeviceSerializer(MetaNameSerializer):
|
|||||||
last_updated = DateTimeField(read_only=True)
|
last_updated = DateTimeField(read_only=True)
|
||||||
last_used = DateTimeField(read_only=True, allow_null=True)
|
last_used = DateTimeField(read_only=True, allow_null=True)
|
||||||
extra_description = SerializerMethodField()
|
extra_description = SerializerMethodField()
|
||||||
|
external_id = SerializerMethodField()
|
||||||
|
|
||||||
def get_type(self, instance: Device) -> str:
|
def get_type(self, instance: Device) -> str:
|
||||||
"""Get type of device"""
|
"""Get type of device"""
|
||||||
return instance._meta.label
|
return instance._meta.label
|
||||||
|
|
||||||
def get_extra_description(self, instance: Device) -> str:
|
def get_extra_description(self, instance: Device) -> str | None:
|
||||||
"""Get extra description"""
|
"""Get extra description"""
|
||||||
if isinstance(instance, WebAuthnDevice):
|
if isinstance(instance, WebAuthnDevice):
|
||||||
return (
|
return instance.device_type.description if instance.device_type else None
|
||||||
instance.device_type.description
|
|
||||||
if instance.device_type
|
|
||||||
else _("Extra description not available")
|
|
||||||
)
|
|
||||||
if isinstance(instance, EndpointDevice):
|
if isinstance(instance, EndpointDevice):
|
||||||
return instance.data.get("deviceSignals", {}).get("deviceModel")
|
return instance.data.get("deviceSignals", {}).get("deviceModel")
|
||||||
return ""
|
return None
|
||||||
|
|
||||||
|
def get_external_id(self, instance: Device) -> str | None:
|
||||||
|
"""Get external Device ID"""
|
||||||
|
if isinstance(instance, WebAuthnDevice):
|
||||||
|
return instance.device_type.aaguid if instance.device_type else None
|
||||||
|
if isinstance(instance, EndpointDevice):
|
||||||
|
return instance.data.get("deviceSignals", {}).get("deviceModel")
|
||||||
|
return None
|
||||||
|
|
||||||
|
|
||||||
class DeviceViewSet(ViewSet):
|
class DeviceViewSet(ViewSet):
|
||||||
|
|||||||
@ -43953,7 +43953,7 @@ components:
|
|||||||
- name
|
- name
|
||||||
Device:
|
Device:
|
||||||
type: object
|
type: object
|
||||||
description: Serializer for Duo authenticator devices
|
description: Serializer for authenticator devices
|
||||||
properties:
|
properties:
|
||||||
verbose_name:
|
verbose_name:
|
||||||
type: string
|
type: string
|
||||||
@ -43992,11 +43992,18 @@ components:
|
|||||||
nullable: true
|
nullable: true
|
||||||
extra_description:
|
extra_description:
|
||||||
type: string
|
type: string
|
||||||
|
nullable: true
|
||||||
description: Get extra description
|
description: Get extra description
|
||||||
readOnly: true
|
readOnly: true
|
||||||
|
external_id:
|
||||||
|
type: string
|
||||||
|
nullable: true
|
||||||
|
description: Get external Device ID
|
||||||
|
readOnly: true
|
||||||
required:
|
required:
|
||||||
- confirmed
|
- confirmed
|
||||||
- created
|
- created
|
||||||
|
- external_id
|
||||||
- extra_description
|
- extra_description
|
||||||
- last_updated
|
- last_updated
|
||||||
- last_used
|
- last_used
|
||||||
|
|||||||
@ -7,7 +7,7 @@ import { PaginatedResponse } from "@goauthentik/elements/table/Table";
|
|||||||
import { Table, TableColumn } from "@goauthentik/elements/table/Table";
|
import { Table, TableColumn } from "@goauthentik/elements/table/Table";
|
||||||
|
|
||||||
import { msg, str } from "@lit/localize";
|
import { msg, str } from "@lit/localize";
|
||||||
import { TemplateResult, html } from "lit";
|
import { TemplateResult, html, nothing } from "lit";
|
||||||
import { customElement, property } from "lit/decorators.js";
|
import { customElement, property } from "lit/decorators.js";
|
||||||
|
|
||||||
import { AuthenticatorsApi, Device } from "@goauthentik/api";
|
import { AuthenticatorsApi, Device } from "@goauthentik/api";
|
||||||
@ -104,8 +104,11 @@ export class UserDeviceTable extends Table<Device> {
|
|||||||
row(item: Device): TemplateResult[] {
|
row(item: Device): TemplateResult[] {
|
||||||
return [
|
return [
|
||||||
html`${item.name}`,
|
html`${item.name}`,
|
||||||
html`${deviceTypeName(item)}
|
html`<div>
|
||||||
${item.extraDescription ? ` - ${item.extraDescription}` : ""}`,
|
${deviceTypeName(item)}
|
||||||
|
${item.extraDescription ? ` - ${item.extraDescription}` : ""}
|
||||||
|
</div>
|
||||||
|
${item.externalId ? html` <small>${item.externalId}</small> ` : nothing} `,
|
||||||
html`${item.confirmed ? msg("Yes") : msg("No")}`,
|
html`${item.confirmed ? msg("Yes") : msg("No")}`,
|
||||||
html`${item.created.getTime() > 0
|
html`${item.created.getTime() > 0
|
||||||
? html`<div>${formatElapsedTime(item.created)}</div>
|
? html`<div>${formatElapsedTime(item.created)}</div>
|
||||||
|
|||||||
@ -13,7 +13,7 @@ import "@goauthentik/user/user-settings/mfa/MFADeviceForm";
|
|||||||
import "@patternfly/elements/pf-tooltip/pf-tooltip.js";
|
import "@patternfly/elements/pf-tooltip/pf-tooltip.js";
|
||||||
|
|
||||||
import { msg, str } from "@lit/localize";
|
import { msg, str } from "@lit/localize";
|
||||||
import { TemplateResult, html } from "lit";
|
import { TemplateResult, html, nothing } from "lit";
|
||||||
import { customElement, property } from "lit/decorators.js";
|
import { customElement, property } from "lit/decorators.js";
|
||||||
import { ifDefined } from "lit/directives/if-defined.js";
|
import { ifDefined } from "lit/directives/if-defined.js";
|
||||||
|
|
||||||
@ -130,8 +130,14 @@ export class MFADevicesPage extends Table<Device> {
|
|||||||
row(item: Device): TemplateResult[] {
|
row(item: Device): TemplateResult[] {
|
||||||
return [
|
return [
|
||||||
html`${item.name}`,
|
html`${item.name}`,
|
||||||
html`${deviceTypeName(item)}
|
html`<div>${deviceTypeName(item)}</div>
|
||||||
${item.extraDescription ? ` - ${item.extraDescription}` : ""}`,
|
${item.extraDescription
|
||||||
|
? html`
|
||||||
|
<pf-tooltip position="top" content=${item.externalId || ""}>
|
||||||
|
<small>${item.extraDescription}</small>
|
||||||
|
</pf-tooltip>
|
||||||
|
`
|
||||||
|
: nothing} `,
|
||||||
html`${item.created.getTime() > 0
|
html`${item.created.getTime() > 0
|
||||||
? html`<div>${formatElapsedTime(item.created)}</div>
|
? html`<div>${formatElapsedTime(item.created)}</div>
|
||||||
<small>${item.created.toLocaleString()}</small>`
|
<small>${item.created.toLocaleString()}</small>`
|
||||||
|
|||||||
Reference in New Issue
Block a user