Simple project to demonstrate how to use Auth0 in Angular project, download code on Github.
To get started, you must have Auth0 account.
To setup the project, update following value in `environment.ts`:
1. Client ID. This is the id of your app you created in Auth0 dashboard. See here.
2. Client Domain. Your Auth0 domain to authenticate user. See here.
3. Callback Url. This is url Auth0 will redirect to after user is authenticated. This url must be white-listed in Auth0 dashboard. See here.
4. Logout Url. This is url Auth0 will redirect to after user logout. This url must be white-listed in Auth0 dashboard. See here.
The juice is on `service/auth.service.ts`, following are explanations of each methods:
Call Auth0 authorize method to authenticate users. The method will redirect user to Auth0, if user is not authenticated, a login screen will displated, if user is authenticated Auth0 will redirect to callback endpoint and pass id token.
Parse response object from Auth0 which contain id token, access token, expiration time and other information. Redirect user to appropriate url depend on the authorization results.
Set authentication tokens and expiration in browser’s storage. User is authenticated.
Remove authentication tokens and expiration from browser’s storage. User is not authenticated anymore.
Check browser’s storage to see if user is authenticated.