Demonstrating Angular JSON Web Tokens
Runs locally, no database required.
From terminal type cd server
then type node server.js
and browse to port 7171
The Chrome Postman plugin can be used to test the APIs. Import the collection from postman.api.tests.json
to run them. The authentication token in the imported collection is specific for the hardcoded secret in the demo.
The node server middleware secures all api routes by checking for a auth token (JWT). If present, the API route is allowed.
The token is retrieved from the \authenticate
route and stuffed into sessionStorage in the browser with an expiration. See code in server/auth.js
An AngularJS httpInterceptor
places the token in every request to the server. The same interceptor checks all responses to see which were unauthorized, so it can taken action. See code in app/services/authInterceptor.js
Enter john.papa
and secret
and click the login button.
Enter john.papa
and foo
and click the login button. Notice the network traffic and the failure response.
If logged in successfully, the restricted data hyperlink returns a message.
If not logged in, the restricted data hyperlink returns an error.
##References
###Express 4