avsln
avsln

Reputation: 683

Windows Authentication - .NET Core Angular application

I am building an intranet application using Visual Studio 2017 and used the template for creating a .NET Core Web Application with Angular. Since it is an intranet application, we want to implement windows authentication. The users are already logged in to the network and we wouldnt want them to enter their credentials again when they access the application.

How can I setup my Angular application so that it can recognise the user that is already logged in to the network and pass it appropriately. We have a Web API Authentication API that can take this user id and determine which AD Groups the user exists in, in order to determine authorisation to the application.

The question i had specifically asked is about Angular Windows Authentication. Not Web API Windows authentication. Also the very specific point I made was that I would like to understand how to pass the logged in windows AD Account into a service used for authorisation without having to ask the users to specifically enter their credentials in a login form. The below question does not address my question.

How to configure ASP.NET Core application to use windows authentication?

Upvotes: 3

Views: 1184

Answers (1)

Morema
Morema

Reputation: 145

On client side have you tried setting withCredentials: true before sending out the request?

I'd create an angular interceptor and set the property there so on every request is always set. Something like this:

import { Injectable } from '@angular/core';
import { HttpInterceptor, HttpRequest, HttpHandler, HttpEvent } from '@angular/common/http';
import { Observable } from 'rxjs';

@Injectable()
export class CustomInterceptor implements HttpInterceptor {
    constructor() { }

    intercept(request: HttpRequest<any>, next: HttpHandler): Observable<HttpEvent<any>> {
        request = request.clone({
            withCredentials: true
        });

        return next.handle(request);
    }
}

Then on the server side check User.Identity which should get you the logged in user AD details.

I have done this and using Chrome I don't have to enter any login details. It doesn't seem to work on my Firefox as you have to login the first time.

Hope this helps.

Upvotes: 1

Related Questions