You can use angular-jwt
to always send the Authorization
header with the JWT when calling an API to make authenticated requests.
In this tutorial, you'll learn how to do this.
The first thing you should do is adding angular-jwt
dependency. Follow this link to learn how to install it via npm, bower or manually. Once you've done that, just include angular-storage
module to your application:
angular.module('myApp', ['auth0', 'angular-jwt']);
You should configure the jwtInterceptor
to always send the JWT. You can get that JWT from the auth
service or if we're using angular-storage
to store the user information, we can get it from there. To learn how to store the profile and token information, please follow this other guide
angular.module('myApp', ['auth0', 'angular-jwt'])
.config(function($httpProvider, jwtInterceptorProvider) {
jwtInterceptorProvider.tokenGetter = function(auth) {
return auth.idToken;
// or
// return store.get('token');
}
$httpProvider.interceptors.push('jwtInterceptor');
});
That's it :). Now, you can check out some of our examples.