- Added JWT configuration to appsettings.json for secure token handling. - Updated config.json to include OAuth provider details for Microsoft, Google, and PocketId. - Added Microsoft icon SVG for UI representation. - Refactored app.config.ts to use a custom AuthInterceptor for managing access tokens. - Enhanced auth route guard to handle asynchronous authentication checks. - Created new auth models for structured request and response handling. - Developed a callback component to manage user login states and transitions. - Updated side-login component to support multiple OAuth providers with loading states. - Implemented authentication service methods for handling OAuth login flows and token management. - Added error handling and user feedback for authentication processes.
29 lines
1.0 KiB
TypeScript
29 lines
1.0 KiB
TypeScript
import { Injectable } from '@angular/core';
|
|
import { HttpEvent, HttpHandler, HttpInterceptor, HttpRequest } from '@angular/common/http';
|
|
import { Observable } from 'rxjs';
|
|
import { AuthenticationService } from './authentication.service';
|
|
|
|
@Injectable()
|
|
export class AuthInterceptor implements HttpInterceptor {
|
|
constructor(private authService: AuthenticationService) { }
|
|
|
|
intercept(req: HttpRequest<any>, next: HttpHandler): Observable<HttpEvent<any>> {
|
|
// Skip adding auth header for authentication endpoints
|
|
if (req.url.includes('/api/auth/authenticate') || req.url.includes('/assets/')) {
|
|
return next.handle(req);
|
|
}
|
|
|
|
// Get custom access token
|
|
const token = this.authService.getCustomAccessToken();
|
|
|
|
if (token) {
|
|
// Clone request and add Authorization header
|
|
const authReq = req.clone({
|
|
headers: req.headers.set('Authorization', `Bearer ${token}`)
|
|
});
|
|
return next.handle(authReq);
|
|
}
|
|
|
|
return next.handle(req);
|
|
}
|
|
} |