Thinkster
Angular
Simple AngularJS Authentication with JWT

Attatching Tokens to Authenticate Requests

Add an Authorization header with the JWT to authenticate HTTP requests with a backend.

Attaching the Token

Finally, let's attach the token to requests made to the API server. Authenticating with a JWT involves attaching an Authorization header to each request with a value consisting of the String "Bearer" and the JWT. This method relies on the use of SSL to prevent the token itself from being sniffed.

Use the request() function to automatically add the Authorization header to outgoing requests:
request: function(config) {
  var token = auth.getToken();
  if(config.url.indexOf(API) === 0 && token) {
    config.headers.Authorization = 'Bearer ' + token;
  }

  return config;
},

Notice how we're only adding the header to requests made to the API server.

You should now be able to hit the "get quote" button and see a motivational quote... or Star Wars.

The requests are being authenticated
 

I finished! On to the next chapter