style: Fix formatting and spacing in multiple files
Some checks failed
Some checks failed
This commit is contained in:
parent
fa09a8533f
commit
617654caeb
5 changed files with 102 additions and 82 deletions
|
@ -9,7 +9,7 @@ import { OAuthStorage, provideOAuthClient } from 'angular-oauth2-oidc';
|
||||||
import { httpInterceptor } from './shared/interceptor/http.interceptor';
|
import { httpInterceptor } from './shared/interceptor/http.interceptor';
|
||||||
|
|
||||||
function storageFactory() {
|
function storageFactory() {
|
||||||
return new class implements OAuthStorage {
|
return new (class implements OAuthStorage {
|
||||||
private data: { [key: string]: string } = {};
|
private data: { [key: string]: string } = {};
|
||||||
|
|
||||||
getItem(key: string): string | null {
|
getItem(key: string): string | null {
|
||||||
|
@ -17,13 +17,13 @@ function storageFactory() {
|
||||||
}
|
}
|
||||||
|
|
||||||
removeItem(key: string): void {
|
removeItem(key: string): void {
|
||||||
delete this.data[key]
|
delete this.data[key];
|
||||||
}
|
}
|
||||||
|
|
||||||
setItem(key: string, data: string): void {
|
setItem(key: string, data: string): void {
|
||||||
this.data[key] = data;
|
this.data[key] = data;
|
||||||
}
|
}
|
||||||
}
|
})();
|
||||||
}
|
}
|
||||||
|
|
||||||
export const appConfig: ApplicationConfig = {
|
export const appConfig: ApplicationConfig = {
|
||||||
|
@ -37,6 +37,6 @@ export const appConfig: ApplicationConfig = {
|
||||||
{
|
{
|
||||||
provide: OAuthStorage,
|
provide: OAuthStorage,
|
||||||
useFactory: () => localStorage,
|
useFactory: () => localStorage,
|
||||||
}
|
},
|
||||||
],
|
],
|
||||||
};
|
};
|
||||||
|
|
|
@ -6,7 +6,6 @@ import { Router } from '@angular/router';
|
||||||
import { environment } from '../../environments/environment';
|
import { environment } from '../../environments/environment';
|
||||||
import { catchError, from, of, tap } from 'rxjs';
|
import { catchError, from, of, tap } from 'rxjs';
|
||||||
|
|
||||||
|
|
||||||
@Injectable({
|
@Injectable({
|
||||||
providedIn: 'root',
|
providedIn: 'root',
|
||||||
})
|
})
|
||||||
|
@ -44,7 +43,8 @@ export class AuthService {
|
||||||
this.setupEventHandling();
|
this.setupEventHandling();
|
||||||
|
|
||||||
// Check if we're on the callback page
|
// Check if we're on the callback page
|
||||||
const hasAuthParams = window.location.search.includes('code=') ||
|
const hasAuthParams =
|
||||||
|
window.location.search.includes('code=') ||
|
||||||
window.location.search.includes('token=') ||
|
window.location.search.includes('token=') ||
|
||||||
window.location.search.includes('id_token=');
|
window.location.search.includes('id_token=');
|
||||||
|
|
||||||
|
@ -61,26 +61,31 @@ export class AuthService {
|
||||||
|
|
||||||
private processCodeFlow() {
|
private processCodeFlow() {
|
||||||
// Try to exchange the authorization code for tokens
|
// Try to exchange the authorization code for tokens
|
||||||
this.oauthService.tryLogin({
|
this.oauthService
|
||||||
onTokenReceived: context => {
|
.tryLogin({
|
||||||
|
onTokenReceived: (context) => {
|
||||||
console.log('Token received in code flow:', context);
|
console.log('Token received in code flow:', context);
|
||||||
// Manually create a token_received event
|
// Manually create a token_received event
|
||||||
this.handleSuccessfulLogin();
|
this.handleSuccessfulLogin();
|
||||||
}
|
},
|
||||||
}).catch(err => {
|
})
|
||||||
|
.catch((err) => {
|
||||||
console.error('Error processing code flow:', err);
|
console.error('Error processing code flow:', err);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
private checkExistingSession() {
|
private checkExistingSession() {
|
||||||
// Try login on startup
|
// Try login on startup
|
||||||
this.oauthService.loadDiscoveryDocumentAndTryLogin().then((isLoggedIn) => {
|
this.oauthService
|
||||||
|
.loadDiscoveryDocumentAndTryLogin()
|
||||||
|
.then((isLoggedIn) => {
|
||||||
console.log('Initial login attempt result:', isLoggedIn);
|
console.log('Initial login attempt result:', isLoggedIn);
|
||||||
|
|
||||||
if (isLoggedIn && !this.user) {
|
if (isLoggedIn && !this.user) {
|
||||||
this.handleSuccessfulLogin();
|
this.handleSuccessfulLogin();
|
||||||
}
|
}
|
||||||
}).catch(err => {
|
})
|
||||||
|
.catch((err) => {
|
||||||
console.error('Error during initial login attempt:', err);
|
console.error('Error during initial login attempt:', err);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
@ -116,9 +121,10 @@ export class AuthService {
|
||||||
|
|
||||||
// Otherwise try to load user profile
|
// Otherwise try to load user profile
|
||||||
try {
|
try {
|
||||||
from(this.oauthService.loadUserProfile()).pipe(
|
from(this.oauthService.loadUserProfile())
|
||||||
tap(profile => console.log('User profile loaded:', profile)),
|
.pipe(
|
||||||
catchError(error => {
|
tap((profile) => console.log('User profile loaded:', profile)),
|
||||||
|
catchError((error) => {
|
||||||
console.error('Error loading user profile:', error);
|
console.error('Error loading user profile:', error);
|
||||||
// If we can't load the profile but have a token, create a minimal profile
|
// If we can't load the profile but have a token, create a minimal profile
|
||||||
if (this.oauthService.hasValidAccessToken()) {
|
if (this.oauthService.hasValidAccessToken()) {
|
||||||
|
@ -126,13 +132,14 @@ export class AuthService {
|
||||||
// Create a basic profile from the token
|
// Create a basic profile from the token
|
||||||
const minimalProfile = {
|
const minimalProfile = {
|
||||||
sub: 'user-' + Math.random().toString(36).substring(2, 10),
|
sub: 'user-' + Math.random().toString(36).substring(2, 10),
|
||||||
preferred_username: 'user' + Date.now()
|
preferred_username: 'user' + Date.now(),
|
||||||
};
|
};
|
||||||
return of({ info: minimalProfile });
|
return of({ info: minimalProfile });
|
||||||
}
|
}
|
||||||
return of(null);
|
return of(null);
|
||||||
})
|
})
|
||||||
).subscribe(profile => {
|
)
|
||||||
|
.subscribe((profile) => {
|
||||||
if (profile) {
|
if (profile) {
|
||||||
this.processUserProfile(profile);
|
this.processUserProfile(profile);
|
||||||
} else {
|
} else {
|
||||||
|
@ -166,7 +173,7 @@ export class AuthService {
|
||||||
} else {
|
} else {
|
||||||
this.router.navigate(['/']);
|
this.router.navigate(['/']);
|
||||||
}
|
}
|
||||||
}
|
},
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -174,10 +181,13 @@ export class AuthService {
|
||||||
console.log('Initiating login flow');
|
console.log('Initiating login flow');
|
||||||
try {
|
try {
|
||||||
// First ensure discovery document is loaded
|
// First ensure discovery document is loaded
|
||||||
this.oauthService.loadDiscoveryDocument().then(() => {
|
this.oauthService
|
||||||
|
.loadDiscoveryDocument()
|
||||||
|
.then(() => {
|
||||||
console.log('Discovery document loaded, starting login flow');
|
console.log('Discovery document loaded, starting login flow');
|
||||||
this.oauthService.initLoginFlow();
|
this.oauthService.initLoginFlow();
|
||||||
}).catch(err => {
|
})
|
||||||
|
.catch((err) => {
|
||||||
console.error('Error loading discovery document:', err);
|
console.error('Error loading discovery document:', err);
|
||||||
// Try login anyway with configured endpoints
|
// Try login anyway with configured endpoints
|
||||||
this.oauthService.initLoginFlow();
|
this.oauthService.initLoginFlow();
|
||||||
|
|
|
@ -35,10 +35,12 @@ export class UserService {
|
||||||
}
|
}
|
||||||
|
|
||||||
public createUser(id: string, username: string): Observable<User> {
|
public createUser(id: string, username: string): Observable<User> {
|
||||||
return this.http.post<User>('/backend/user', {
|
return this.http
|
||||||
|
.post<User>('/backend/user', {
|
||||||
authentikId: id,
|
authentikId: id,
|
||||||
username: username,
|
username: username,
|
||||||
}).pipe(tap((user) => this.currentUserSubject.next(user)));
|
})
|
||||||
|
.pipe(tap((user) => this.currentUserSubject.next(user)));
|
||||||
}
|
}
|
||||||
|
|
||||||
public getOrCreateUser(profile: any): Observable<User> {
|
public getOrCreateUser(profile: any): Observable<User> {
|
||||||
|
@ -46,7 +48,11 @@ export class UserService {
|
||||||
// Authentik format might differ from Keycloak
|
// Authentik format might differ from Keycloak
|
||||||
// Check different possible locations for the ID and username
|
// Check different possible locations for the ID and username
|
||||||
const id = profile.info?.sub || profile['sub'];
|
const id = profile.info?.sub || profile['sub'];
|
||||||
const username = profile.info?.preferred_username || profile['preferred_username'] || profile['email'] || profile['name'];
|
const username =
|
||||||
|
profile.info?.preferred_username ||
|
||||||
|
profile['preferred_username'] ||
|
||||||
|
profile['email'] ||
|
||||||
|
profile['name'];
|
||||||
|
|
||||||
if (!id || !username) {
|
if (!id || !username) {
|
||||||
console.error('Could not extract user ID or username from profile', profile);
|
console.error('Could not extract user ID or username from profile', profile);
|
||||||
|
|
|
@ -6,13 +6,15 @@ export const httpInterceptor: HttpInterceptorFn = (req, next) => {
|
||||||
const oauthStorage = inject(OAuthStorage);
|
const oauthStorage = inject(OAuthStorage);
|
||||||
|
|
||||||
if (oauthStorage.getItem('access_token')) {
|
if (oauthStorage.getItem('access_token')) {
|
||||||
return next(req.clone({
|
return next(
|
||||||
|
req.clone({
|
||||||
setHeaders: {
|
setHeaders: {
|
||||||
'Authorization': 'Bearer ' + oauthStorage.getItem('access_token'),
|
Authorization: 'Bearer ' + oauthStorage.getItem('access_token'),
|
||||||
'Access-Control-Allow-Origin': '*',
|
'Access-Control-Allow-Origin': '*',
|
||||||
'Referrer-Policy': 'no-referrer',
|
'Referrer-Policy': 'no-referrer',
|
||||||
}
|
},
|
||||||
}));
|
})
|
||||||
|
);
|
||||||
} else {
|
} else {
|
||||||
return next(req);
|
return next(req);
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,5 +1,7 @@
|
||||||
export const environment = {
|
export const environment = {
|
||||||
STRIPE_KEY: 'pk_test_51QrePYIvCfqz7ANgMizBorPpVjJ8S6gcaL4yvcMQnVaKyReqcQ6jqaQEF7aDZbDu8rNVsTZrw8ABek4ToxQX7KZe00jpGh8naG',
|
STRIPE_KEY:
|
||||||
|
'pk_test_51QrePYIvCfqz7ANgMizBorPpVjJ8S6gcaL4yvcMQnVaKyReqcQ6jqaQEF7aDZbDu8rNVsTZrw8ABek4ToxQX7KZe00jpGh8naG',
|
||||||
OAUTH_CLIENT_ID: 'MDqjm1kcWKuZfqHJXjxwAV20i44aT7m4VhhTL3Nm',
|
OAUTH_CLIENT_ID: 'MDqjm1kcWKuZfqHJXjxwAV20i44aT7m4VhhTL3Nm',
|
||||||
OAUTH_CLIENT_SECRET: 'GY2F8te6iAVYt1TNAUVLzWZEXb6JoMNp6chbjqaXNq4gS5xTDL54HqBiAlV1jFKarN28LQ7FUsYX4SbwjfEhZhgeoKuBnZKjR9eiu7RawnGgxIK9ffvUfMkjRxnmiGI5'
|
OAUTH_CLIENT_SECRET:
|
||||||
|
'GY2F8te6iAVYt1TNAUVLzWZEXb6JoMNp6chbjqaXNq4gS5xTDL54HqBiAlV1jFKarN28LQ7FUsYX4SbwjfEhZhgeoKuBnZKjR9eiu7RawnGgxIK9ffvUfMkjRxnmiGI5',
|
||||||
};
|
};
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue