Introduction is a development platform for building WEB, mobile, and desktop applications using HTML, CSS and TypeScript (JavaScript). Currently, Angular is at version 14 and Google is the main maintainer of the project. Angular is an easy-to-implement, adaptable authentication and authorization platform. Auth0 Prerequisites Before you start, you need to install and configure the tools: git Node.js and npm Angular CLI IDE (e.g. ) Visual Studio Code Getting started Create and configure the account on the Auth0 Let's create the account. Access the site and click on the button . 1. https://auth0.com/ Sign up Fill in the field and click on the button . 2. Email SIGN UP Fill in the fields , and click on the button . 3. Email Password Continue Click on the option and click on the button . 4. Personal NEXT Let's create the application. Click on the menu and click on the menu . 5. Applications Applications Click on the link with the application name. 6. Copy the domain that has been generated, in my case, the domain was copied, copy the that has been generated, in my case, the was copied, select the option in the field , fill in the fields , , and click on the button . 7. dev-5tf99p7c.us.auth0.com Client ID Client ID GBPB42qhMWCtvrwGmYxvm5cbHXU68nzG Single Page Application Application Type Allowed Callback URLs Allowed Logout URLs Allowed Web Origins, Save Changes Check the registered email. 8. Ready! Account is created and is application configured. 9. Create the Angular application Let's create the application with the Angular base structure using the with the route file and the SCSS style format. 1. @angular/cli ng new angular-auth0 --routing true --style scss CREATE angular-auth0/README.md (1058 bytes) CREATE angular-auth0/.editorconfig (274 bytes) CREATE angular-auth0/.gitignore (620 bytes) CREATE angular-auth0/angular.json (3249 bytes) CREATE angular-auth0/package.json (1077 bytes) CREATE angular-auth0/tsconfig.json (863 bytes) CREATE angular-auth0/.browserslistrc (600 bytes) CREATE angular-auth0/karma.conf.js (1430 bytes) CREATE angular-auth0/tsconfig.app.json (287 bytes) CREATE angular-auth0/tsconfig.spec.json (333 bytes) CREATE angular-auth0/src/favicon.ico (948 bytes) CREATE angular-auth0/src/index.html (298 bytes) CREATE angular-auth0/src/main.ts (372 bytes) CREATE angular-auth0/src/polyfills.ts (2338 bytes) CREATE angular-auth0/src/styles.scss (80 bytes) CREATE angular-auth0/src/test.ts (745 bytes) CREATE angular-auth0/src/assets/.gitkeep (0 bytes) CREATE angular-auth0/src/environments/environment.prod.ts (51 bytes) CREATE angular-auth0/src/environments/environment.ts (658 bytes) CREATE angular-auth0/src/app/app-routing.module.ts (245 bytes) CREATE angular-auth0/src/app/app.module.ts (393 bytes) CREATE angular-auth0/src/app/app.component.scss (0 bytes) CREATE angular-auth0/src/app/app.component.html (23364 bytes) CREATE angular-auth0/src/app/app.component.spec.ts (1094 bytes) CREATE angular-auth0/src/app/app.component.ts (218 bytes) ✔ Packages installed successfully. Successfully initialized git. Install and configure the Bootstrap CSS framework. Do steps 2 and 3 of the post . 2. Adding the Bootstrap CSS framework to an Angular application Configure the variable with the Auth0 domain and the variable with the Auth0 Client ID in the and files as below. 3. auth0.domain auth0.clientId src/environments/environment.ts src/environments/environment.prod.ts auth0: { domain: 'dev-5tf99p7c.us.auth0.com', clientId: 'GBPB42qhMWCtvrwGmYxvm5cbHXU68nzG', redirectUri: 'http://localhost:4200/profile', }, Install the library. 4. @auth0/auth0-angular npm install @auth0/auth0-angular Create the component. 5. SignInComponent ng generate component sign-in --skip-tests=true CREATE src/app/sign-in/sign-in.component.scss (0 bytes) CREATE src/app/sign-in/sign-in.component.html (22 bytes) CREATE src/app/sign-in/sign-in.component.ts (279 bytes) UPDATE src/app/app.module.ts (477 bytes) Change the file. Import the service and create the method as below. 6. src/app/sign-in/sign-in.component.ts Router signIn import { Component } from '@angular/core'; import { Router } from '@angular/router'; @Component({ selector: 'app-sign-in', templateUrl: './sign-in.component.html', styleUrls: ['./sign-in.component.scss'], }) export class SignInComponent { constructor(private router: Router) { } public signIn(): void { this.router.navigate(['/profile']); } } Change the file. Add the lines as below. 7. src/app/sign-in/sign-in.component.html <div class="row justify-content-center my-5"> <div class="col-4"> <div class="card"> <div class="card-body"> <div class="row"> <div class="col d-grid"> <button type="button" (click)="signIn()" class="btn btn-sm btn-success"> Sign in </button> </div> </div> </div> </div> </div> </div> Create the component. 8. ProfileComponent ng generate component profile --skip-tests=true CREATE src/app/profile/profile.component.scss (0 bytes) CREATE src/app/profile/profile.component.html (22 bytes) CREATE src/app/profile/profile.component.ts (280 bytes) UPDATE src/app/app.module.ts (710 bytes) Change the file. Import the service and add the lines as below. 9. src/app/profile/profile.component.ts AuthService import { Component, OnInit } from '@angular/core'; import { AuthService } from '@auth0/auth0-angular'; @Component({ selector: 'app-profile', templateUrl: './profile.component.html', styleUrls: ['./profile.component.scss'], }) export class ProfileComponent implements OnInit { user: any; constructor(private authService: AuthService) { this.user = {}; } public ngOnInit(): void { this.authService.user$.subscribe((success: any) => { this.user = success; }); } } Change the file and add the lines as below. 10. src/app/profile/profile.component.html <div class="row justify-content-center my-5"> <div class="col-4"> <div class="row" *ngIf="user.picture"> <div class="col mb-2 text-center"> <img [src]="user.picture" class="rounded-circle w-25"> </div> </div> <div class="row"> <div class="col mb-2"> <label for="email" class="form-label">Email:</label> <input type="email" id="email" name="email" #email="ngModel" [ngModel]="user.email" class="form-control form-control-sm"> </div> </div> <div class="row"> <div class="col mb-2"> <label for="nickname" class="form-label">Nickname:</label> <input type="text" id="nickname" name="nickname" #nickname="ngModel" [(ngModel)]="user.nickname" class="form-control form-control-sm"> </div> </div> </div> </div> Change the file. Import the service and create the method as below. 11. src/app/app.component.ts AuthService signOut import { Component, Inject, OnInit } from '@angular/core'; import { DOCUMENT } from '@angular/common'; import { AuthService } from '@auth0/auth0-angular'; @Component({ selector: 'app-root', templateUrl: './app.component.html', styleUrls: ['./app.component.scss'], }) export class AppComponent implements OnInit { isAuthenticated: boolean; constructor(@Inject(DOCUMENT) private document: Document, private authService: AuthService) { this.isAuthenticated = false; } public ngOnInit(): void { this.authService.isAuthenticated$.subscribe((success: boolean) => { this.isAuthenticated = success; }); } public signOut(): void { this.authService.logout({ returnTo: this.document.location.origin, }); } } Change the file and add the menu as below. 12. src/app/app.component.html <nav class="navbar navbar-expand-sm navbar-light bg-light"> <div class="container-fluid"> <a class="navbar-brand" href="#">Angular Auth0</a> <button class="navbar-toggler" type="button" data-bs-toggle="collapse" data-bs-target="#navbarContent" aria-controls="navbarSupportedContent" aria-expanded="false" aria-label="Toggle navigation"> <span class="navbar-toggler-icon"></span> </button> <div id="navbarContent" class="collapse navbar-collapse"> <ul class="navbar-nav me-auto mb-2 mb-lg-0"> <li class="nav-item"> <a class="nav-link" routerLink="/signIn" routerLinkActive="active" *ngIf="!isAuthenticated">Sign in</a> </li> <li class="nav-item"> <a class="nav-link" routerLink="/profile" routerLinkActive="active" *ngIf="isAuthenticated">Profile</a> </li> <li class="nav-item"> <a class="nav-link" routerLink="" (click)="signOut()" *ngIf="isAuthenticated">Sign out</a> </li> </ul> </div> </div> </nav> <router-outlet></router-outlet> Change the file and add the routes as below. 13. src/app/app-routing.module.ts import { AuthGuard } from '@auth0/auth0-angular'; import { ProfileComponent } from './profile/profile.component'; import { SignInComponent } from './sign-in/sign-in.component'; const routes: Routes = [ { path: '', redirectTo: 'signIn', pathMatch: 'full', }, { path: 'profile', component: ProfileComponent, canActivate: [AuthGuard], }, { path: 'signIn', component: SignInComponent, }, { path: '**', redirectTo: 'signIn', }, ]; Change the file. Import the and modules, the and components and configure the module as below. 14. src/app/app.module.ts FormsModule AuthModule ProfileComponent SignInComponent AuthModule import { FormsModule } from '@angular/forms'; import { AuthModule } from '@auth0/auth0-angular'; import { environment } from '../environments/environment'; import { SignInComponent } from './sign-in/sign-in.component'; import { ProfileComponent } from './profile/profile.component'; declarations: [ AppComponent, SignInComponent, ProfileComponent ], imports: [ BrowserModule, FormsModule, AuthModule.forRoot(environment.auth0), AppRoutingModule ], Run the application with the command below. 15. npm start > angular-auth0@1.0.0 start > ng serve ✔ Browser application bundle generation complete. Initial Chunk Files | Names | Size vendor.js | vendor | 2.57 MB styles.css, styles.js | styles | 486.69 kB polyfills.js | polyfills | 339.08 kB scripts.js | scripts | 76.33 kB main.js | main | 23.11 kB runtime.js | runtime | 6.86 kB | Initial Total | 3.48 MB Build at: 2021-11-15T13:21:02.234Z - Hash: 6dbd594c55acc213 - Time: 11172ms ** Angular Live Development Server is listening on localhost:4200, open your browser on http://localhost:4200/ ** ✔ Compiled successfully. Ready! Access the URL and check if the application is working. See the application working on and . 16. http://localhost:4200/ GitHub Pages Stackblitz Testing the application sign in Let's test the application sign-in. Access the URL and click on the button . 1. http://localhost:4200/ Sign in Click on the button . 2. Sign up Fill in the fields , and click on the button . 3. Email Address Password Continue Click on the button . 4. Accept You will be redirected to the application. 5. Check the registered email. 6. Ready! We have tested the application sign-in and profile view. Auth0 documentation is available at . 7. https://auth0.com/docs The application repository is available at . https://github.com/rodrigokamada/angular-auth0 This tutorial was posted on my in portuguese. blog