Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Access windows Authenticated Web API through Angular 2 without login prompt

I have already developed front-end application in Angular2 and back-end in ASP.net web APIs. I had used Windows authentication as enabled because I want to detect requesting user. Both applications are hosted in IIS server(Windows Server 2012). When I load angular app it load login prompt and when give correct user credentials data loading happen correctly. But I want to know a way to load them without login prompt, authenticate automatically.

This is the way I detect request user in web APIs.

string user = HttpContext.Current.Request.ServerVariables["LOGON_USER"]; //Get the current user...
userID = user.Split('\\')[1]; 

This is a sample TS script send request to Windows Authenticated Web APIs from Angular Services.

getPersonalInfo(): Observable<IPersonalInfo> {
        return this._http.get(localStorage.getItem('WebApiURL') +"api/PersonalInfo/" , { withCredentials: true })
            .map((response: Response) => <IPersonalInfo>response.json())
            .catch(this.handleError);
    }

When restart the browser this login ask every time.

I want to access them with out this login...

like image 494
Dhananjaya Avatar asked Feb 12 '18 11:02

Dhananjaya


1 Answers

Actually, this login prompt occurs because there is communication between two technologies (ASP.net & Angular 2) by passing windows windows credentials. So it need shake-hand authentication when call windows authenticated API.

I was lucky to find a solution by changing privacy settings through browser. So I got ability to call API's without login prompt.

Here is the way to do that.

Settings -> Open Proxy settings -> Privacy ->Sites

Screenshot is here...

In here you can add domain where your back-end APIs are already hosted as in example. After that it take as trusted domain and further more there is no any login prompt accruing.

like image 129
Dhananjaya Avatar answered Oct 13 '22 01:10

Dhananjaya