Enable Windows Authentication between Angular and ASPNet WebAPI
---
---
How to enable Windows credentials between Angular and ASPNET WebAPI
- Create the WebAPI with windows authentication enabled
- You might need to enable CORS
- In your http calls of your Angular app, send a request options object, in this object, set withCredentials = true
import { HttpClient } from '@angular/common/http'; import { Injectable } from '@angular/core'; @Injectable({ providedIn: 'root' }) export class ItemsService { constructor(private httpClient: HttpClient) { } getItems = () => { return this.httpClient.get('http://localhost:49288/api/items', { withCredentials: true }); } }
- In your WebAPI service, one way to get the current user is:
public class ItemsController : ApiController { public string Get() { return User.Identity.Name; } }
Comments
Post a Comment