Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

angular cli + windows authentication backend

I created an Angular CLI project with a proxy reference to my backend project that contains the web api services.

launchSettings.json (backend project):

...
  "iisSettings": {
    "windowsAuthentication": true,
    "anonymousAuthentication": false,
    "iisExpress": {
      "applicationUrl": "http://localhost:10863/",
      "sslPort": 0
    }
  },
...

proxy.conf.json (frontend project):

{
  "/api": {
    "target": "http://localhost:10863",
    "secure": false,
    "logLevel": "debug"
  }
}

package.json (frontend project):

...
"scripts": {
    "ng": "ng",
    "start": "start http://localhost:4200 && ng serve --proxy-config proxy.conf.json",
    "build": "ng build --prod --output-path=..\\CoreTest\\wwwroot",
    "test": "ng test",
    "lint": "ng lint",
    "e2e": "ng e2e"
  },
...

Then I fire up the back-end and launch the Kestrel webserver by running npm start. With an angular2 service I do a http-get to one of the back-end services. Since back-end services run in IISExpress with Windows Authentication (I want windows authentication), I get a 401 error.

I could do npm run build and browse to my IISExpress url and load the index.html as published by ng build but I would like to use the ng serve method since development is much smoother because ng serve works in-memory.

My question is: how can I use Angular CLI with Windows Authentication during development?

like image 200
Mcanic Avatar asked Mar 23 '17 16:03

Mcanic


People also ask

How to enable Windows Authentication in Angular?

Go to the properties window of the API project, in the Debug tab, enable SSL, Anonymous Authentication, and Windows Authentication. You can set the App URL as https.

Does angular support Windows Authentication?

Select 'Authentication' and in this window Enable Windows Authentication and Anonymous Authentication. And that is it. We now have a WebApi secured by Windows Authentication.

Can we use Windows Authentication in Web API?

a) To create a web api project in windows authentication mode, follow below steps: After choosing ASP.Net Web Application, select Web API template and from the right side click Change Authentication button and select Windows Authentication.


1 Answers

For what it's worth, a better solution is to use a proxy js file https://github.com/angular/angular-cli/issues/5627#issuecomment-289381319

like image 198
Mcanic Avatar answered Sep 22 '22 07:09

Mcanic