feat(oidc): add configurable mobile redirect URI to the admin settings UI (#1287)

This commit is contained in:
Zach
2026-05-13 23:19:28 -04:00
committed by GitHub
parent ee3e21cd1d
commit ff5f054bd3
7 changed files with 241 additions and 3 deletions
@@ -210,6 +210,44 @@
</div>
</div>
<div class="claims-section">
<h4 class="subsection-title">{{ t('mobileRedirectUris.title') }}</h4>
<p class="subsection-description">
{{ t('mobileRedirectUris.description') }}
</p>
<div class="config-item full-width">
<label for="mobileRedirectUriInput">{{ t('mobileRedirectUris.label') }}</label>
<div class="redirect-uri-input">
<div class="redirect-uri-chip-list">
@for (redirectUri of mobileRedirectUris; track redirectUri; let index = $index) {
<p-chip
class="redirect-uri-chip"
[label]="redirectUri"
[removable]="true"
[attr.aria-label]="t('mobileRedirectUris.removeLabel', {uri: redirectUri})"
(onRemove)="removeMobileRedirectUri(index)">
</p-chip>
}
<input
pInputText
pSize="small"
id="mobileRedirectUriInput"
[(ngModel)]="mobileRedirectUriInput"
[placeholder]="mobileRedirectUris.length === 0 ? t('mobileRedirectUris.placeholder') : ''"
(keydown)="onMobileRedirectUriKeydown($event)"
(blur)="addMobileRedirectUriFromInput()"
/>
</div>
</div>
<span class="field-hint">
{{ t('mobileRedirectUris.hintPrefix') }}
<code>{{ defaultMobileRedirectUri }}</code>
{{ '. ' + t('mobileRedirectUris.hintSuffix') }}
<code>{{ wildcardMobileRedirectUri }}</code>
</span>
</div>
</div>
<div class="provider-actions-row">
<div class="test-results-inline">
@if (testConnectionResult) {
@@ -230,6 +230,12 @@
line-height: 1.4;
}
.field-error {
font-size: 0.75rem;
color: var(--p-red-400);
line-height: 1.4;
}
// Claims Section
.claims-section {
margin-top: 1rem;
@@ -251,6 +257,71 @@
margin: 0 0 0.75rem;
}
.redirect-uri-input {
display: flex;
align-items: center;
width: 100%;
min-height: 2.25rem;
padding: 0.25rem 0.5rem;
border: 1px solid var(--p-content-border-color);
border-radius: 6px;
background: var(--p-inputtext-background);
transition: border-color 0.2s ease, box-shadow 0.2s ease;
&:focus-within {
border-color: var(--p-primary-color);
box-shadow: 0 0 0 1px color-mix(in srgb, var(--p-primary-color) 35%, transparent);
}
&.has-error {
border-color: var(--p-red-400);
}
input {
border: 0;
box-shadow: none;
background: transparent;
min-width: 11rem;
flex: 1 1 11rem;
padding: 0.25rem 0;
&:focus {
box-shadow: none;
}
}
}
.redirect-uri-chip-list {
display: flex;
align-items: center;
gap: 0.375rem;
flex-wrap: wrap;
width: 100%;
}
.redirect-uri-chip {
max-width: 100%;
flex-shrink: 1;
font-size: 0.8125rem;
::ng-deep .p-chip {
padding: 0.1563rem 0.4063rem;
border-radius: 0.375rem;
line-height: 1.125rem;
}
::ng-deep .p-chip-label {
overflow: hidden;
text-overflow: ellipsis;
white-space: nowrap;
}
::ng-deep .p-chip-remove-icon {
font-size: 0.65rem;
opacity: 0.6;
}
}
.claims-grid {
display: grid;
grid-template-columns: repeat(4, 1fr);
@@ -18,6 +18,7 @@ function createSettings(overrides: Partial<AppSettings> = {}): AppSettings {
oidcEnabled: false,
oidcAutoProvisionDetails: undefined,
oidcProviderDetails: undefined,
oidcRedirectUris: ['grimmory://oauth2-callback'],
oidcSessionDurationHours: null,
oidcGroupSyncMode: null,
oidcForceOnlyMode: false,
@@ -127,6 +128,7 @@ describe('AuthenticationSettingsComponent', () => {
name: 'given_name',
groups: '',
});
expect(component.mobileRedirectUris).toEqual(['grimmory://oauth2-callback']);
expect(groupMappingService.getAll).not.toHaveBeenCalled();
});
@@ -174,6 +176,7 @@ describe('AuthenticationSettingsComponent', () => {
name: 'displayName',
groups: 'memberOf',
});
expect(component.mobileRedirectUris).toEqual(['grimmory://oauth2-callback']);
expect(component.groupMappings).toEqual(mappings);
expect(groupMappingService.getAll).toHaveBeenCalledOnce();
});
@@ -272,6 +275,7 @@ describe('AuthenticationSettingsComponent', () => {
it('saves OIDC provider settings with the session duration only when OIDC is enabled', () => {
appSettingsService.saveSettings.mockReturnValue(of(void 0));
component.oidcProvider = completeProvider();
component.mobileRedirectUris = ['grimmory://oauth2-callback', 'grimmory://auth/return'];
component.oidcEnabled = false;
component.sessionDurationHours = 24;
@@ -281,6 +285,10 @@ describe('AuthenticationSettingsComponent', () => {
{
key: AppSettingKey.OIDC_PROVIDER_DETAILS,
newValue: component.oidcProvider,
},
{
key: AppSettingKey.OIDC_REDIRECT_URIS,
newValue: ['grimmory://oauth2-callback', 'grimmory://auth/return'],
}
]);
@@ -292,6 +300,10 @@ describe('AuthenticationSettingsComponent', () => {
key: AppSettingKey.OIDC_PROVIDER_DETAILS,
newValue: component.oidcProvider,
},
{
key: AppSettingKey.OIDC_REDIRECT_URIS,
newValue: ['grimmory://oauth2-callback', 'grimmory://auth/return'],
},
{
key: AppSettingKey.OIDC_SESSION_DURATION_HOURS,
newValue: 24,
@@ -299,6 +311,64 @@ describe('AuthenticationSettingsComponent', () => {
]);
});
it('adds a mobile redirect URI from input and clears the field', () => {
component.mobileRedirectUris = ['grimmory://oauth2-callback'];
component.mobileRedirectUriInput = 'grimmory://auth/return';
component.addMobileRedirectUriFromInput();
expect(component.mobileRedirectUris).toEqual(['grimmory://oauth2-callback', 'grimmory://auth/return']);
expect(component.mobileRedirectUriInput).toBe('');
});
it('adds the pending mobile redirect URI before saving', () => {
appSettingsService.saveSettings.mockReturnValue(of(void 0));
component.oidcProvider = completeProvider();
component.mobileRedirectUris = ['grimmory://oauth2-callback'];
component.mobileRedirectUriInput = 'grimmory://auth/return';
component.saveOidcProvider();
expect(appSettingsService.saveSettings).toHaveBeenCalledWith(expect.arrayContaining([
{
key: AppSettingKey.OIDC_REDIRECT_URIS,
newValue: ['grimmory://oauth2-callback', 'grimmory://auth/return'],
}
]));
expect(component.mobileRedirectUriInput).toBe('');
});
it('removes the last mobile redirect URI when delete is pressed on an empty input', () => {
component.mobileRedirectUris = ['grimmory://oauth2-callback', 'grimmory://auth/return'];
const preventDefault = vi.fn();
component.onMobileRedirectUriKeydown({
key: 'Delete',
preventDefault,
} as unknown as KeyboardEvent);
expect(preventDefault).toHaveBeenCalledOnce();
expect(component.mobileRedirectUris).toEqual(['grimmory://oauth2-callback']);
});
it('surfaces backend redirect URI validation failures in the toast', () => {
component.oidcProvider = completeProvider();
component.mobileRedirectUris = ['grimmory://oauth2-callback'];
appSettingsService.saveSettings.mockReturnValue(
throwError(() => new HttpErrorResponse({
status: 400,
error: {message: 'Wildcard redirect URI must be the only value'}
}))
);
component.saveOidcProvider();
expect(messageService.add).toHaveBeenCalledWith(expect.objectContaining({
severity: 'error',
detail: 'Wildcard redirect URI must be the only value',
}));
});
it('saves the group sync mode and reports failures', () => {
appSettingsService.saveSettings.mockReturnValueOnce(of(void 0));
component.groupSyncMode = 'ON_LOGIN_ADDITIVE';
@@ -1,3 +1,4 @@
import {HttpErrorResponse} from '@angular/common/http';
import {Component, effect, inject} from '@angular/core';
import {FormsModule, ReactiveFormsModule} from '@angular/forms';
import {InputText} from 'primeng/inputtext';
@@ -18,6 +19,7 @@ import {Select} from 'primeng/select';
import {TableModule} from 'primeng/table';
import {Dialog} from 'primeng/dialog';
import {TagComponent} from '../../../shared/components/tag/tag.component';
import {Chip} from 'primeng/chip';
@Component({
selector: 'app-authentication-settings',
@@ -38,11 +40,14 @@ import {TagComponent} from '../../../shared/components/tag/tag.component';
Select,
TableModule,
Dialog,
TagComponent
TagComponent,
Chip
],
styleUrls: ['./authentication-settings.component.scss']
})
export class AuthenticationSettingsComponent {
readonly defaultMobileRedirectUri = 'grimmory://oauth2-callback';
readonly wildcardMobileRedirectUri = '*';
availablePermissions = [
{label: 'Upload Books', value: 'permissionUpload', selected: false, translationKey: 'perms.uploadBooks'},
{label: 'Download Books', value: 'permissionDownload', selected: false, translationKey: 'perms.downloadBooks'},
@@ -82,6 +87,8 @@ export class AuthenticationSettingsComponent {
sessionDurationHours: number | null = null;
backchannelLogoutUri = `${window.location.origin}/api/v1/auth/oidc/backchannel-logout`;
oidcForceOnlyMode = false;
mobileRedirectUris: string[] = [this.defaultMobileRedirectUri];
mobileRedirectUriInput = '';
infoItems = [
{labelKey: 'infoPanel.redirectUri', value: `${window.location.origin}/oauth2-callback`},
@@ -158,6 +165,10 @@ export class AuthenticationSettingsComponent {
this.sessionDurationHours = settings.oidcSessionDurationHours ?? null;
this.groupSyncMode = settings.oidcGroupSyncMode ?? 'DISABLED';
this.oidcForceOnlyMode = settings.oidcForceOnlyMode ?? false;
this.mobileRedirectUris = settings.oidcRedirectUris?.length
? [...settings.oidcRedirectUris]
: [this.defaultMobileRedirectUri];
this.mobileRedirectUriInput = '';
this.oidcProvider = {
providerName: settings.oidcProviderDetails?.providerName || '',
@@ -198,10 +209,16 @@ export class AuthenticationSettingsComponent {
}
saveOidcProvider(): void {
this.addMobileRedirectUriFromInput();
const payload: {key: AppSettingKey; newValue: unknown}[] = [
{
key: AppSettingKey.OIDC_PROVIDER_DETAILS,
newValue: this.oidcProvider
},
{
key: AppSettingKey.OIDC_REDIRECT_URIS,
newValue: this.mobileRedirectUris
}
];
if (this.oidcEnabled) {
@@ -216,10 +233,10 @@ export class AuthenticationSettingsComponent {
summary: this.t.translate('settingsAuth.toast.saved'),
detail: this.t.translate('settingsAuth.toast.providerSaved')
}),
error: () => this.messageService.add({
error: (error: HttpErrorResponse) => this.messageService.add({
severity: 'error',
summary: this.t.translate('common.error'),
detail: this.t.translate('settingsAuth.toast.providerError')
detail: error?.error?.message || this.t.translate('settingsAuth.toast.providerError')
})
});
}
@@ -259,6 +276,36 @@ export class AuthenticationSettingsComponent {
});
}
addMobileRedirectUriFromInput(): void {
const value = this.mobileRedirectUriInput.trim();
if (!value) {
this.mobileRedirectUriInput = '';
return;
}
this.mobileRedirectUris = [...this.mobileRedirectUris, value];
this.mobileRedirectUriInput = '';
}
removeMobileRedirectUri(index: number): void {
this.mobileRedirectUris = this.mobileRedirectUris.filter((_, currentIndex) => currentIndex !== index);
}
onMobileRedirectUriKeydown(event: KeyboardEvent): void {
if ((event.key === 'Enter' || event.key === ',') && this.mobileRedirectUriInput.trim()) {
event.preventDefault();
this.addMobileRedirectUriFromInput();
return;
}
if ((event.key === 'Backspace' || event.key === 'Delete')
&& !this.mobileRedirectUriInput
&& this.mobileRedirectUris.length > 0) {
event.preventDefault();
this.removeMobileRedirectUri(this.mobileRedirectUris.length - 1);
}
}
saveOidcAutoProvisionSettings(): void {
const provisionDetails = {
enableAutoProvisioning: this.autoUserProvisioningEnabled,
@@ -184,6 +184,7 @@ export interface AppSettings {
remoteAuthEnabled: boolean;
oidcEnabled: boolean;
oidcProviderDetails: OidcProviderDetails;
oidcRedirectUris: string[];
oidcAutoProvisionDetails: OidcAutoProvisionDetails;
maxFileUploadSizeInMb: number;
metadataProviderSettings: MetadataProviderSettings;
@@ -233,6 +234,7 @@ export enum AppSettingKey {
KOMGA_GROUP_UNKNOWN = 'KOMGA_GROUP_UNKNOWN',
OIDC_ENABLED = 'OIDC_ENABLED',
OIDC_PROVIDER_DETAILS = 'OIDC_PROVIDER_DETAILS',
OIDC_REDIRECT_URIS = 'OIDC_REDIRECT_URIS',
OIDC_AUTO_PROVISION_DETAILS = 'OIDC_AUTO_PROVISION_DETAILS',
MAX_FILE_UPLOAD_SIZE_IN_MB = 'MAX_FILE_UPLOAD_SIZE_IN_MB',
METADATA_PROVIDER_SETTINGS = 'METADATA_PROVIDER_SETTINGS',
@@ -43,6 +43,7 @@ function buildAppSettings(overrides: Partial<AppSettings> = {}): AppSettings {
remoteAuthEnabled: publicSettings.remoteAuthEnabled,
oidcEnabled: publicSettings.oidcEnabled,
oidcProviderDetails: publicSettings.oidcProviderDetails,
oidcRedirectUris: ['grimmory://oauth2-callback'],
oidcAutoProvisionDetails: {
enableAutoProvisioning: false,
allowLocalAccountLinking: false,
+9
View File
@@ -47,6 +47,15 @@
"backchannelLogoutUri": "Back-Channel Logout URI",
"backchannelLogoutHint": "Configure this URI in your OIDC provider to enable server-initiated session revocation."
},
"mobileRedirectUris": {
"title": "Mobile Redirect URIs",
"description": "Whitelist the mobile redirect URIs your OIDC flow is allowed to return to.",
"label": "Allowed Mobile Redirect URIs",
"placeholder": "Add a redirect URI or *",
"hintPrefix": "The default redirect URI is",
"hintSuffix": "To allow any URI, just use",
"removeLabel": "Remove {{uri}}"
},
"provisioning": {
"sectionTitle": "User Provisioning",
"sectionDesc": "Configure how new OIDC users are created and what permissions they receive.",