Angular 17 MSAL Interceptor Not Adding Token to HTTP Request header when called from a service

I am trying to build an Angular 17 standalone app that can perform a GET request to my Flask REST API backend.

The Angular app has been set up with authentication using MSAL and is functioning with the redirect method for authentication.

Now I am trying to use the MsalInterceptor to append an access token to http.get request to the sites listed in the protectedResourceMap.

I have a class called AuthFactories where the snippet below is from.

auth.factories.ts

public MSALInterceptorConfigFactory(config: AppConfigService): MsalInterceptorConfiguration {
    console.log("MSALInterceptorConfigFactory");
    const protectedResourceMap = new Map<string, Array<string>>();
    const apiUrl = config.getConfig("apiUrl");
    const clientId = config.getConfig("clientId");

    protectedResourceMap.set(`/`, [
        `${clientId}/Flask.Access`,
    ]);

    console.log("Protected Resource Map:", protectedResourceMap);

    return {
        interactionType: InteractionType.Redirect,
        protectedResourceMap: protectedResourceMap
    };
}

This is then added to the bootstrapApplication providers as below.

main.ts code

{
    provide: MSAL_INTERCEPTOR_CONFIG,
    useFactory: authFactories.MSALInterceptorConfigFactory,
    deps: [AppConfigService]
}

I believe the providers and protectedResourceMap are set up correctly, because the header is added when I run my http.get() command from in the component called db.components.ts. However, if I put the same call in a function within db.service.ts and then call that it fails to be intercepted. What changes are required to service.ts for the HTTP request to be successfully intercepted so the authorisation token can be added to the header?

db.components.ts code

import { Component, OnInit } from '@angular/core';
import { DBService } from '~/services/db.service';
import { HttpClient } from '@angular/common/http';
import { CommonModule } from '@angular/common';

@Component({
  selector: 'app-db-cnxn',
  standalone: true,
  imports: [CommonModule],
  templateUrl: './db-cnxn.component.html',
  styleUrls: ['./db-cnxn.component.css']
})
export class DbCnxnComponent implements OnInit {
  public responseData: any;
  public errorMessage: string | null = null;

  constructor(
    private dbService: DBService,
    private http: HttpClient
  ) {}

  ngOnInit(): void {
    this.testConnection();
  }

  public async testConnection(): Promise<void> {
    try {
      this.responseData = await this.dbService.testConnection(); // VERSION A. This call does not get intercepted so no Auth token is added to the header
      
      this.responseData = this.dbService.testConnection();

      this.http.get("http://127.0.0.1:5000/health")
      .subscribe(responseData => {
        this.responseData = responseData;
      }); // VERSION B. This call is successfully intercepted and the Auth token is added to the header

      console.log("Flask Backend Connection Successful");

    } catch (error) {
      this.errorMessage = 'Failed to connect to the database. Please try again later.';
      console.error(error);
    }
  }
}

db.service.ts code

import { Injectable } from '@angular/core';
import { HttpClient, HttpBackend } from '@angular/common/http';
import { lastValueFrom } from 'rxjs';

@Injectable({
    providedIn: 'root'
})
export class DBService {
    private apiUrl = 'http://127.0.0.1:5000/health';
    private http: HttpClient;

    constructor(private httpHandler: HttpBackend) {
        this.http = new HttpClient(this.httpHandler);
    }

    public async testConnection(): Promise<any> {
        const p = new Promise<any>((resolve, reject) => {
            try {
                console.log("Getting API"); // DEBUG COMMENT
                let stream$ = this.http.get(this.apiUrl); // The MSALInterceptorConfigFactory should add header tokens

                lastValueFrom(stream$).then((data: any) => {
                    resolve(data);
                });
            } catch(error: any) {
                reject(error);
            }
        });

        return await p;
    }
}

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật