最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

angular - MsalInterceptor is not setting the bearer token to the http requests made from the img, video, audio and pdf viewer co

programmeradmin2浏览0评论

I am developing an angular application in which I have integrated EntraID app for authentication and used the MsalInterceptor and configured the required providers as follows:

    providers: [
    {
      provide: HTTP_INTERCEPTORS,
      useClass: MsalInterceptor,
      multi: true
    },
    {
      provide: MSAL_INSTANCE,
      useFactory: MSALInstanceFactory,
    },
    {
      provide: MSAL_GUARD_CONFIG,
      useFactory: MSALGuardConfigFactory
    },
    {
      provide: MSAL_INTERCEPTOR_CONFIG,
      useFactory: MSALInterceptorConfigFactory
    },
    MsalService,
    MsalGuard,
    MsalBroadcastService
  ]

This configuration works (adding required bearer token) for making http requests from service classes and for downloading the file as follows:

    export class FileDownloadService {

  constructor(private http: HttpClient) { }

  downloadFile(url: string): Observable<Blob> {
    return this.http.get(url, { responseType: 'blob' });
  }
}


    this.fileDownloadService.downloadFile(fileUrl).subscribe(
            {
            next:blob => {
            const a = document.createElement('a');
            const objectUrl = URL.createObjectURL(blob);
            a.href = objectUrl;
            a.download = file.fileName;
            a.click();
            URL.revokeObjectURL(objectUrl);
            this.gridApi.deselectAll();
          },
          error: (error) => {
            
          }});

However, it is not working (not setting the bearer token to the header) when the filePath was set as src for the img, video, audio and pdf viewers as follows:

<img [src]="filePath" />

Am I missing any configuration?

与本文相关的文章

发布评论

评论列表(0)

  1. 暂无评论