Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Angular 5 httpInterceptors not firing on fetchMetadata #24

Closed
alexisread opened this issue May 4, 2018 · 10 comments
Closed

Angular 5 httpInterceptors not firing on fetchMetadata #24

alexisread opened this issue May 4, 2018 · 10 comments

Comments

@alexisread
Copy link

Hi, I can get interceptors firing on just the breeze-client but not for odata4. I need them to add a withCredentials header.
Test with commenting out (from your test documentation):
OData4UriBuilder.register();
OData4DataService.register();
config.initializeAdapterInstance('uriBuilder', 'OData4', true);
config.initializeAdapterInstance('dataService', 'OData4', true);
to see any interceptor you've added in be hit.
Is this as the odata4 lib uses a different instance of HttpClient compared to the main app? I've had a play at getting HttpClient injected in the constructor, but don't have the time at the moment to fully debug.

Thanks

@tschettler
Copy link
Owner

Unfortunately, the olingo-odata4 library uses an httpclient that directly requires http. I have not played around with injecting a custom httpClient yet, but I am planning an update to expose headers through the OData4DataService, Will that work for you?

@alexisread
Copy link
Author

Thanks for the very quick response! Yes I think that would work fine for me. Really I'd need to change the Accept header (currently /) and Authorization header (withCredentials: true), so that I can connect to an NTLM/Kerberos API.

@alexisread
Copy link
Author

FYI this is how I've done it previously with Jaydata (though Jaydata doesn't support webpack and hasn't been updated in a while, hence the move to breeze).

@tschettler
Copy link
Owner

tschettler commented May 4, 2018

Please update to version 0.9.13 and the headers property should now be getting used on all requests. You can access the headers from the adapter instance:

    const ds = <OData4DataService>config.getAdapterInstance('dataService', 'OData4');
    ds.headers.Authorization = 'Basic YWxhZ...';

The adapter uses a specific Accept header for accessing metadata, "application/json;odata.metadata=full". If you need to change the Accept header to something else, you may need to do it after the metadata is retrieved, as the headers property will overwrite any headers used in the adapter.

@alexisread
Copy link
Author

Hi, unfortunately while the headers can be set, the underlying xhr request doesn't have the withCredentials tag propagated. Looking into the olingo library, I can see that it was patched for Jaydata (jaystack/jaydata#294) which keeps an olingo fork, but not for olingo itself (awaiting merge apache/olingo-odata4-js@8c2bb6f). So for my use i'll need to maintain an olingo fork, and create a ds.withCredentials adapter property.

Thanks

@tschettler
Copy link
Owner

I see, would you consider submitting a PR for this?

@alexisread
Copy link
Author

Happy to, but it'll take a while to develop as this is very much a side project at work :)

@tschettler
Copy link
Owner

No problem, I know how that goes. I'll add it to the list, looks like creating a custom httpClient should be doable.

@alexisread
Copy link
Author

I've had a look into this, and have it working locally, the patch needs to be in ts-odatajs, in node_modules ie. in olingo-odata4-js. I've created a PR for this, and if accepted, I will add in the withCredentials passthrough option here.

Thanks

@tschettler
Copy link
Owner

Please update to version 0.9.14, after this you can create a class that extends ODataHttpClient. Override the request method to get access to the request object. From there, you can set the withCredentials property. Register the class with the data adapter using the following:

    const ds = <OData4DataService>config.getAdapterInstance('dataService', 'OData4');
    ds.httpClient = new MyODataHttpClient();

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants