angular-auth0-aside
This repository demonstrates the use of Auth0 with Angular (with the @angular/cli) and a sample Node API with a protected route.
Dependencies
- Node.js with npm, Node >= 8, npm >= 5
- @angular/cli, >= 8
Auth0 Application Setup
- Go to your Auth0 Dashboard: Applications section and click the "+ Create Application" button.
- Name your new app and select "Single Page Web Applications".
- In the Settings for your new Auth0 app, add
http://localhost:4200/callback
to the Allowed Callback URLs. - Add
http://localhost:4200
to both the Allowed Web Origins and Allowed Logout URLs. Click the "Save Changes" button. - If you'd like, you can set up some social connections. You can then enable them for your app in the Application options under the Connections tab. The example shown in the screenshot above uses username/password database, Facebook, Google, and Twitter.
Note: Set up your own social keys and do not leave social connections set to use Auth0 dev keys or you will encounter issues with token renewal.
Auth0 API Setup
- Go to APIs in your Auth0 dashboard and click on the "Create API" button. Enter a name for the API. Set the Identifier to your API endpoint URL. In this example, this is
http://localhost:3001/api/
. The Signing Algorithm should beRS256
. - You can consult the Node.js example under the Quick Start tab in your new API's settings. We'll implement our Node API in this fashion, using Express, express-jwt, and jwks-rsa.
We're now ready to implement Auth0 authentication on both our Angular client and Node backend API.
Installation
Clone this project. From the root directory, run the following commands to install dependencies for the server and client-side:
$ npm install
$ cd server
$ npm install
- Open
server/config.js.example
and remove.example
from the file name. Then replace[YOUR_AUTH0_DOMAIN]
with your Auth0 domain. - Open
src/app/environments/environment.example
and remove.example
from the file name. Then replace[YOUR_CLIENT_ID]
and[YOUR_AUTH0_DOMAIN]
with your Auth0 application's client ID and domain.
Serving the project
From the root of this project, run:
$ npm start
This will concurrently serve the Angular and API servers.
What is Auth0?
Auth0 helps you to:
- Add authentication with multiple authentication sources, either social like Google, Facebook, Microsoft Account, LinkedIn, GitHub, Twitter, Box, Salesforce, amont others, or enterprise identity systems like Windows Azure AD, Google Apps, Active Directory, ADFS or any SAML Identity Provider.
- Add authentication through more traditional username/password databases.
- Add support for linking different user accounts with the same user.
- Support for generating signed Json Web Tokens to call your APIs and flow the user identity securely.
- Analytics of how, when and where users are logging in.
- Pull data from other sources and add it to the user profile, through JavaScript rules.
Create a Free Auth0 Account
- Go to Auth0 and click Sign Up.
- Use Google, GitHub, or Microsoft Account to log in.
Issue Reporting
If you have found a bug or if you have a feature request, please report them at this repository issues section. Please do not report security vulnerabilities on the public GitHub issue tracker. The Responsible Disclosure Program details the procedure for disclosing security issues.
Author
License
This project is licensed under the MIT license. See the LICENSE file for more info.