2
votes

I am trying to implement MSAL authentication in angular application. So when application starting its login correctly using Azure AD.

Also I am using msal_interceptor as provider in app.module

 providers: [
  LoaderService,
  {
    provide: HTTP_INTERCEPTORS,useClass: MsalInterceptor, multi: true
  },
  { 
    provide: HTTP_INTERCEPTORS, useClass: LoaderInterceptor, multi: true 
  }
]

So I tried to call a test API like this

return this.client.get(url+'weatherforecast', {
  responseType: 'json'
});

API is returning correctly since its not an Authorization enabled API. I checked the Request header in chrome. But there is no token header anywhere mentioned. So whats wrong I did

This is the Request I copied from Chrome

curl "https://localhost:44331/weatherforecast" ^
  -H "authority: localhost:44331" ^
  -H "accept: application/json, text/plain, */*" ^
  -H "user-agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/81.0.4044.92 Safari/537.36" ^
  -H "origin: http://localhost:4200" ^
  -H "sec-fetch-site: cross-site" ^
  -H "sec-fetch-mode: cors" ^
  -H "sec-fetch-dest: empty" ^
  -H "referer: http://localhost:4200/" ^
  -H "accept-language: en-GB,en-US;q=0.9,en;q=0.8" ^
  --compressed
1
curl doesn't add Authorization header. You should check chrome network tab - yurzui

1 Answers

2
votes

You need to declare your api routes and scopes required using protectedResources.