angular-http-interceptors

How to prioritize requests in angular $http service?

走远了吗. 提交于 2019-11-30 15:48:16
I'm working on an application with a large amount of lazy data loading. I would like to prioritize http requests based on 'priority' param. This is the concept of using it. $http.get(url, {params: query, priority: 1}) I was thinking of using $http interceptors. Something like that: angular.module('myModule') .factory('httpPriorityInterceptor', function ($interval, $q) { var requestStack = []; return { request: function (config) { config.priority = config.priority || 3; requestStack.push(config); requestStack.sort(sortByPriority); if (isFirstToGo(item)) return requestStack.pop(); deferred = $q

Angular HTTP Interceptor - Display spinner in multi-module app

烈酒焚心 提交于 2019-11-30 13:35:50
问题 I'm trying to display the ng4-loading-spinner spinner for HTTP calls made to my API. I based my code on the examples in the following links: https://angular.io/guide/http#intercepting-all-requests-or-responses Angular4: Using HttpClient's interceptor to setup a spinner My Angular 5 app has multiple multiple modules. The HTTP interceptor is in the "services" module. I think I'm having a dependency injection problem because the code HTTP interceptor code doesn't get executed when I debug my

Angular 4.3 - HTTP Interceptor - refresh JWT token

送分小仙女□ 提交于 2019-11-30 09:56:34
I need to react (in interceptor class) on 403 Forbidden HTTP status (to obtain/refresh) JWT token and retry the request with fresh token. In the code below, when server return error response it goes to success callback (not into the error callback as I expect) and the event is typeof object (which is useless in reaction on error response). The event object looks like this: {type:0}. Question: -How to properly handle httpErrorResponse (403 Forbidden) in HttpInterceptor when I need refresh accessToken and retry the http request? import { HttpInterceptor, HttpRequest, HttpResponse, HttpHandler,

AngularJS Authentication + RESTful API

≯℡__Kan透↙ 提交于 2019-11-30 06:09:34
问题 Angular+RESTful Client-side Communication w/ API for Auth/(re)Routing This has been covered in a few different questions, and in a few different tutorials, but all of the previous resources I've encountered don't quite hit the nail on the head. In a nut-shell, I need to Login via POST from http://client.foo to http://api.foo/login Have a "logged in" GUI/component state for the user that provides a logout route Be able to "update" the UI when the user logs out / logs out. This has been the

Add multiple HTTP Interceptors to Angular Application

て烟熏妆下的殇ゞ 提交于 2019-11-29 20:23:12
How to add multiple, independent HTTP interceptors to an Angular 4 application? I tried to add them by extending the providers array with more than one interceptors. But only the last one is actually executed, Interceptor1 is ignored. @NgModule({ declarations: [ /* ... */ ], imports: [ /* ... */ HttpModule ], providers: [ { provide: Http, useFactory: (xhrBackend: XHRBackend, requestOptions: RequestOptions) => new Interceptor1(xhrBackend, requestOptions), deps: [XHRBackend, RequestOptions], }, { provide: Http, useFactory: (xhrBackend: XHRBackend, requestOptions: RequestOptions) => new

angular 4.3x dynamic http interceptor

寵の児 提交于 2019-11-29 12:56:15
I followed this article from medium to create a http interceptor which lets me add headers to each http call @Injectable() export class TokenInterceptor implements HttpInterceptor { constructor(public auth: AuthService) {} intercept(request: HttpRequest<any>, next: HttpHandler): Observable<HttpEvent<any>> { request = request.clone({ setHeaders: { Authorization: `Bearer ${this.auth.getToken()}` } }); return next.handle(request); } } The article uses the authService to get a token dynamically. However as soon as I inject HttpClient into the AuthService I get a circular injection error. Are there

Add multiple HTTP Interceptors to Angular Application

≯℡__Kan透↙ 提交于 2019-11-28 15:54:55
问题 How to add multiple, independent HTTP interceptors to an Angular 4 application? I tried to add them by extending the providers array with more than one interceptors. But only the last one is actually executed, Interceptor1 is ignored. @NgModule({ declarations: [ /* ... */ ], imports: [ /* ... */ HttpModule ], providers: [ { provide: Http, useFactory: (xhrBackend: XHRBackend, requestOptions: RequestOptions) => new Interceptor1(xhrBackend, requestOptions), deps: [XHRBackend, RequestOptions], },

AngularJS Authentication + RESTful API

五迷三道 提交于 2019-11-28 15:01:34
Angular+RESTful Client-side Communication w/ API for Auth/(re)Routing This has been covered in a few different questions, and in a few different tutorials, but all of the previous resources I've encountered don't quite hit the nail on the head. In a nut-shell, I need to Login via POST from http://client.foo to http://api.foo/login Have a "logged in" GUI/component state for the user that provides a logout route Be able to "update" the UI when the user logs out / logs out. This has been the most frustrating Secure my routes to check for authenticated-state (should they need it) and redirect the

Refresh Token OAuth Authentication Angular 4+

纵然是瞬间 提交于 2019-11-28 10:38:43
I was working with the Http clase from Angular but I decide to make the migration and work with the new HttpClient , and I was trying to create a solution with Interceptors to manage the cases when I need to refresh the token and when I need to modify the header to put the Authorization Token. First I found these post and so many others : https://medium.com/@amcdnl/the-new-http-client-in-angular-4-3-754bd3ff83a8 https://medium.com/@ryanchenkie_40935/angular-authentication-using-the-http-client-and-http-interceptors-2f9d1540eb8 ... but those solutions are perfect if you just want to handle the

angular 4.3x dynamic http interceptor

杀马特。学长 韩版系。学妹 提交于 2019-11-28 06:43:42
问题 I followed this article from medium to create a http interceptor which lets me add headers to each http call @Injectable() export class TokenInterceptor implements HttpInterceptor { constructor(public auth: AuthService) {} intercept(request: HttpRequest<any>, next: HttpHandler): Observable<HttpEvent<any>> { request = request.clone({ setHeaders: { Authorization: `Bearer ${this.auth.getToken()}` } }); return next.handle(request); } } The article uses the authService to get a token dynamically.