Projekt

Obecné

Profil

« Předchozí | Další » 

Revize 76eb842a

Přidáno uživatelem Jakub Danek před více než 5 roky(ů)

re #29 crude login page

Zobrazit rozdíly:

webapp/src/app/auth/basic-auth.interceptor.ts
2 2
import {HttpEvent, HttpHandler, HttpInterceptor, HttpRequest} from '@angular/common/http';
3 3
import {Observable} from 'rxjs';
4 4

  
5
import {ProfileService} from '../services/util/profile.service';
6

  
7 5
/**
8 6
 * Adds authentication token to each request.
9 7
 */
10 8
@Injectable()
11 9
export class BasicAuthInterceptor implements HttpInterceptor {
12
  constructor(private profileService: ProfileService) {
10
  constructor() {
13 11
  }
14 12

  
15 13
  intercept(request: HttpRequest<any>, next: HttpHandler): Observable<HttpEvent<any>> {
16
    // add authorization header with basic auth credentials if available
17
    const currentUser = window.btoa(this.profileService.currentUserValue + ":");
18
    if (currentUser) {
19
      request = request.clone({
20
        withCredentials: true,
21
        setHeaders: {
22
          authorization: `Basic ${currentUser}`
23
        }
24
      });
25
    }
14
    request = request.clone({
15
      withCredentials: true,
16
    });
26 17

  
27 18
    return next.handle(request);
28 19
  }

Také k dispozici: Unified diff