Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I use Aurelia Fetch Client to query an API protected by Windows Authentication?

We have a web server serving our Aurelia static files as well as an API, the server is protected by NTLM (using Integrated Windows Authentication on OWIN).

When using the Aurelia Fetch Client we can successfully hit the API with not problem. Here's the config we use:

constructor(private http: HttpClient){
        http.configure(config => {
            config
            .withBaseUrl('api/')
            .useStandardConfiguration();
        });

However when we use the Aurelia Fetch Client we get the 401 (Unauthorized) (seems the authorization header is missing)

constructor(private client: HttpClient) {
        client.configure(cfg => {
            cfg
            .withBaseUrl('http://localhost:80/api/someEndpoint')
            .withDefaults({
                headers: {
                    'Accept' : 'application/json',
                    'X-Requested-With': 'Fetch'
                }
            })

Any ideas on how to resolve this are very much appreciated.

like image 717
MaYaN Avatar asked Aug 15 '16 13:08

MaYaN


1 Answers

It turned out I was missing the credentials:

constructor(private client: HttpClient) {
        client.configure(cfg => {
            cfg
            .withBaseUrl('http://localhost:80/someEndpoint')
            .withDefaults({
                credentials: 'same-origin',
                headers: {
                    'Accept' : 'application/json',
                    'X-Requested-With': 'Fetch'
                }
            })
like image 189
MaYaN Avatar answered Nov 14 '22 03:11

MaYaN