Build Angular 13 Token based Authentication & Authorization Application with Web Api and JWT (including HttpInterceptor, Router & Form Validation).
- JWT Authentication Flow for User Registration (Signup) & User Login
- Project Structure with HttpInterceptor, Router
- How to implement HttpInterceptor
- Creating Login, Signup Components with Form Validation
- Angular Components for accessing protected Resources
- How to add a dynamic Navigation Bar to Angular App
- Working with Browser Session Storage
For JWT – Token based Authentication with Web API, we’re gonna call 2 endpoints:
- POST
api/auth/signup
for User Registration - POST
api/auth/signin
for User Login
You can take a look at following flow to have an overview of Requests and Responses that Angular 13 JWT Authentication & Authorization Client will make or receive.
For more detail, please visit the tutorial:
Angular + Spring Boot: JWT Authentication and Authorization example
Angular + Node.js Express: JWT Authentication and Authorization example
Depending on the backend you choose, you need to open app/_helpers/auth.interceptor.js
, modify the code like this:
...
// const TOKEN_HEADER_KEY = 'Authorization'; // for Spring Boot back-end
const TOKEN_HEADER_KEY = 'x-access-token'; // for Node.js Express back-end
@Injectable()
export class AuthInterceptor implements HttpInterceptor {
...
intercept(req: HttpRequest<any>, next: HttpHandler): Observable<HttpEvent<any>> {
...
if (token != null) {
// for Spring Boot back-end
// authReq = req.clone({ headers: req.headers.set(TOKEN_HEADER_KEY, 'Bearer ' + token) });
// for Node.js Express back-end
authReq = req.clone({ headers: req.headers.set(TOKEN_HEADER_KEY, token) });
}
return next.handle(authReq);
}
}
...
Run ng serve --port 8081
for a dev server. Navigate to http://localhost:8081/
.
Fullstack with Node:
Fullstack with Spring Boot:
Fullstack with Django:
Serverless with Firebase:
Angular Firebase CRUD with Realtime DataBase | AngularFireDatabase
Angular Firebase Storage: File Upload/Display/Delete example
Integration (run back-end & front-end on same server/port)