How can I use Aurelia Fetch Client to request a Windows Authentication protected API?

We have a web server serving static Aurelia 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 will successfully remove the API without any problems. Here we use the configuration:

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

However, when we use the Aurelia Fetch Client , we get 401 (Unauthorized)(it 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 solve this problem are greatly appreciated.

+4
source share
1 answer

It turned out that I was missing 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'
                }
            })
+3
source

Source: https://habr.com/ru/post/1651287/


All Articles