I had a similar question and never found a good answer.
I ended up creating my own service which is just a wrapper around the HTTP
service. It's a bit of boiler plate, but it works. Additionally, because
I'm using OAuth2 tokens instead of JWT, I was able to add in the
functionality of renewing the access token when it expires using the reply
token and delaying any requests until after the initial authentication is
completed (assuming there were no tokens in session storage). The caller
does not need to worry about any of this.






On Fri, Aug 26, 2016 at 12:26 PM Kyle Thomas <[email protected]>
wrote:

> Is there a way to attach the Bearer token for each /api/ call out through
> something similar to an $httpProvider.interceptors in Angular 1?
>
> Right now I'm attaching it at every function call
>
>     getUsers() {
>         let jwt = Cookie.get('token');
>         let authHeader = new Headers();
>         if (jwt){
>             authHeader.append('Authorization', 'Bearer ' + jwt);
>         }
>         return this.http.get('/api/users',{
>             headers: authHeader
>         }).map(res => res.json());
>     }
>
>
> --
> You received this message because you are subscribed to the Google Groups
> "AngularJS" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to [email protected].
> To post to this group, send email to [email protected].
> Visit this group at https://groups.google.com/group/angular.
> For more options, visit https://groups.google.com/d/optout.
>
-- 
Lucas Lacroix
Computer Scientist
Advanced Technology Division, MEDITECH <http://ehr.meditech.com/>
781-774-2293

-- 
You received this message because you are subscribed to the Google Groups 
"AngularJS" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at https://groups.google.com/group/angular.
For more options, visit https://groups.google.com/d/optout.

Reply via email to