Resolve broken Pocket ID auth and occasional Authentik failures
This commit is contained in:
committed by
Aditya Chandel
parent
98bd69164b
commit
f7db157689
@@ -77,6 +77,6 @@ export class LoginComponent implements OnInit {
|
||||
}
|
||||
|
||||
loginWithOidc(): void {
|
||||
this.oAuthService.initImplicitFlow();
|
||||
this.oAuthService.initCodeFlow();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -28,7 +28,6 @@ export interface OidcProviderDetails {
|
||||
providerName: string;
|
||||
clientId: string;
|
||||
issuerUri: string;
|
||||
jwksUrl: string;
|
||||
claimMapping: {
|
||||
username: string;
|
||||
email: string;
|
||||
|
||||
+3
-12
@@ -79,16 +79,7 @@
|
||||
pInputText
|
||||
id="issuerUri"
|
||||
[(ngModel)]="oidcProvider.issuerUri"
|
||||
placeholder="e.g. https://authentik.your-domain.com/application/o/booklore/"
|
||||
class="w-full"/>
|
||||
</div>
|
||||
<div class="md:col-span-2">
|
||||
<label for="jwksUrl" class="mb-1">JWKS URL</label>
|
||||
<input
|
||||
pInputText
|
||||
id="jwksUrl"
|
||||
[(ngModel)]="oidcProvider.jwksUrl"
|
||||
placeholder="e.g. https://authentik.your-domain.com/application/o/booklore/jwks/"
|
||||
placeholder="e.g. https://authentik.domain.com/application/o/booklore/ or https://pocket-id.domain.com"
|
||||
class="w-full"/>
|
||||
</div>
|
||||
<div class="md:col-span-2">
|
||||
@@ -150,7 +141,7 @@
|
||||
<p-toggleswitch
|
||||
[(ngModel)]="autoUserProvisioningEnabled"
|
||||
inputId="autoProvision"
|
||||
(onChange)="saveAutoProvision()">
|
||||
(onChange)="saveOidcAutoProvisionSettings()">
|
||||
</p-toggleswitch>
|
||||
<div class="flex items-center gap-2 text-sm text-gray-400">
|
||||
<i class="pi pi-info-circle text-blue-500"></i>
|
||||
@@ -193,7 +184,7 @@
|
||||
</p-multiSelect>
|
||||
</div>
|
||||
<div class="mt-8">
|
||||
<p-button label="Save Settings" [outlined]="true" (click)="saveAutoProvisioningSettings()"></p-button>
|
||||
<p-button label="Save Settings" [outlined]="true" (click)="saveOidcAutoProvisionSettings()"></p-button>
|
||||
</div>
|
||||
</div>
|
||||
}
|
||||
|
||||
+2
-50
@@ -30,7 +30,7 @@ import {LibraryService} from '../../../book/service/library.service';
|
||||
Button,
|
||||
MultiSelect,
|
||||
ReactiveFormsModule
|
||||
],
|
||||
],
|
||||
styleUrls: ['./authentication-settings.component.scss']
|
||||
})
|
||||
export class AuthenticationSettingsComponent implements OnInit {
|
||||
@@ -52,7 +52,6 @@ export class AuthenticationSettingsComponent implements OnInit {
|
||||
providerName: '',
|
||||
clientId: '',
|
||||
issuerUri: '',
|
||||
jwksUrl: '',
|
||||
claimMapping: {
|
||||
username: '',
|
||||
email: '',
|
||||
@@ -98,7 +97,6 @@ export class AuthenticationSettingsComponent implements OnInit {
|
||||
providerName: settings.oidcProviderDetails?.providerName || '',
|
||||
clientId: settings.oidcProviderDetails?.clientId || '',
|
||||
issuerUri: settings.oidcProviderDetails?.issuerUri || '',
|
||||
jwksUrl: settings.oidcProviderDetails?.jwksUrl || '',
|
||||
claimMapping: settings.oidcProviderDetails?.claimMapping || defaultClaimMapping
|
||||
};
|
||||
|
||||
@@ -112,51 +110,6 @@ export class AuthenticationSettingsComponent implements OnInit {
|
||||
return !!(p.providerName && p.clientId && p.issuerUri && p.claimMapping.name && p.claimMapping.email && p.claimMapping.username);
|
||||
}
|
||||
|
||||
saveAutoProvision(): void {
|
||||
const payload = [
|
||||
{key: 'auto_provision_oidc_users', newValue: this.autoUserProvisioningEnabled}
|
||||
];
|
||||
this.appSettingsService.saveSettings(payload).subscribe({
|
||||
next: () => this.messageService.add({
|
||||
severity: 'success',
|
||||
summary: 'Saved',
|
||||
detail: 'Auto-provision setting saved.'
|
||||
}),
|
||||
error: () => this.messageService.add({
|
||||
severity: 'error',
|
||||
summary: 'Error',
|
||||
detail: 'Failed to save auto-provision setting.'
|
||||
})
|
||||
});
|
||||
}
|
||||
|
||||
onPermissionToggle(): void {
|
||||
this.selectedPermissions = [
|
||||
'permissionRead',
|
||||
...this.availablePermissions.filter(p => p.selected).map(p => p.value)
|
||||
];
|
||||
|
||||
const payload = [
|
||||
{
|
||||
key: 'default_oidc_user_permissions',
|
||||
newValue: this.selectedPermissions
|
||||
}
|
||||
];
|
||||
|
||||
this.appSettingsService.saveSettings(payload).subscribe({
|
||||
next: () => this.messageService.add({
|
||||
severity: 'success',
|
||||
summary: 'Saved',
|
||||
detail: 'Default permissions updated.'
|
||||
}),
|
||||
error: () => this.messageService.add({
|
||||
severity: 'error',
|
||||
summary: 'Error',
|
||||
detail: 'Failed to update default permissions.'
|
||||
})
|
||||
});
|
||||
}
|
||||
|
||||
toggleOidcEnabled(): void {
|
||||
if (!this.isOidcFormComplete()) return;
|
||||
const payload = [
|
||||
@@ -200,8 +153,7 @@ export class AuthenticationSettingsComponent implements OnInit {
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
saveAutoProvisioningSettings(): void {
|
||||
saveOidcAutoProvisionSettings(): void {
|
||||
const provisionDetails = {
|
||||
enableAutoProvisioning: this.autoUserProvisioningEnabled,
|
||||
defaultPermissions: [
|
||||
|
||||
@@ -15,21 +15,22 @@ export class OidcCallbackComponent implements OnInit {
|
||||
private authService = inject(AuthService);
|
||||
|
||||
ngOnInit(): void {
|
||||
this.oAuthService.loadDiscoveryDocumentAndTryLogin().then(() => {
|
||||
/*this.oAuthService.tryLoginCodeFlow().then(info => {
|
||||
if (this.oAuthService.hasValidAccessToken()) {
|
||||
this.authService.saveOidcTokens(
|
||||
this.oAuthService.getAccessToken(),
|
||||
this.oAuthService.getRefreshToken()
|
||||
);
|
||||
const accessToken = this.oAuthService.getAccessToken();
|
||||
const refreshToken = this.oAuthService.getRefreshToken();
|
||||
this.authService.saveOidcTokens(accessToken, refreshToken ?? '');
|
||||
|
||||
this.authService.getRxStompService().activate();
|
||||
this.oAuthService.setupAutomaticSilentRefresh();
|
||||
this.router.navigate(['/dashboard']);
|
||||
} else {
|
||||
console.error('Login failed or no valid tokens');
|
||||
console.error('OIDC code exchange failed');
|
||||
this.router.navigate(['/login']);
|
||||
}
|
||||
}).catch(err => {
|
||||
console.error('OIDC error during login:', err);
|
||||
console.error('OIDC error:', err);
|
||||
this.router.navigate(['/login']);
|
||||
});
|
||||
});*/
|
||||
}
|
||||
}
|
||||
|
||||
@@ -39,7 +39,7 @@ export class AppConfigService {
|
||||
return {
|
||||
preset: 'Aura',
|
||||
primary: 'green',
|
||||
surface: 'viva',
|
||||
surface: 'neutral',
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
@@ -4,6 +4,9 @@ import {Observable, tap} from 'rxjs';
|
||||
import {RxStompService} from '../../shared/websocket/rx-stomp.service';
|
||||
import {API_CONFIG} from '../../config/api-config';
|
||||
import {createRxStompConfig} from '../../shared/websocket/rx-stomp.config';
|
||||
import {OAuthService} from 'angular-oauth2-oidc';
|
||||
import {AppSettingsService} from './app-settings.service';
|
||||
import {Router} from '@angular/router';
|
||||
|
||||
@Injectable({
|
||||
providedIn: 'root',
|
||||
@@ -15,6 +18,8 @@ export class AuthService {
|
||||
|
||||
private http = inject(HttpClient);
|
||||
private injector = inject(Injector);
|
||||
private oAuthService = inject(OAuthService);
|
||||
private router = inject(Router);
|
||||
|
||||
internalLogin(credentials: { username: string; password: string }): Observable<{ accessToken: string; refreshToken: string, isDefaultPassword: string }> {
|
||||
return this.http.post<{ accessToken: string; refreshToken: string, isDefaultPassword: string }>(`${this.apiUrl}/login`, credentials).pipe(
|
||||
@@ -54,17 +59,12 @@ export class AuthService {
|
||||
localStorage.setItem('refreshToken_Internal', refreshToken);
|
||||
}
|
||||
|
||||
saveOidcTokens(accessToken: string, refreshToken: string): void {
|
||||
localStorage.setItem('accessToken_OIDC', accessToken);
|
||||
localStorage.setItem('refreshToken_OIDC', refreshToken);
|
||||
}
|
||||
|
||||
getInternalAccessToken(): string | null {
|
||||
return localStorage.getItem('accessToken_Internal');
|
||||
}
|
||||
|
||||
getOidcAccessToken(): string | null {
|
||||
return localStorage.getItem('accessToken_OIDC');
|
||||
return this.oAuthService.getIdToken();
|
||||
}
|
||||
|
||||
getInternalRefreshToken(): string | null {
|
||||
@@ -74,9 +74,12 @@ export class AuthService {
|
||||
logout(): void {
|
||||
localStorage.removeItem('accessToken_Internal');
|
||||
localStorage.removeItem('refreshToken_Internal');
|
||||
localStorage.removeItem('accessToken_OIDC');
|
||||
localStorage.removeItem('refreshToken_OIDC');
|
||||
this.getRxStompService().deactivate();
|
||||
if (this.oAuthService.clientId) {
|
||||
this.oAuthService.logOut();
|
||||
} else {
|
||||
this.router.navigate(['/login']);
|
||||
}
|
||||
}
|
||||
|
||||
getRxStompService(): RxStompService {
|
||||
|
||||
Reference in New Issue
Block a user