This is the sample code for the Auth0 tutorial Adding Authentication to NgRx.
This project was generated with Angular CLI version 6.1.5.
To get started, clone the repo, install the dependencies, and check out the "Starting point" commit to follow along with the tutorial.
git clone https://github.com/auth0-blog/ngrx-auth.git
cd ngrx-auth
npm install
git checkout 23c1b25
Run ng serve
for a dev server. Navigate to http://localhost:4200/
. The app will automatically reload if you change any of the source files.
Run ng generate component component-name
to generate a new component. You can also use ng generate directive|pipe|service|class|guard|interface|enum|module
, as well as the NgRx schematics like feature
or reducer
.
This app uses Auth0 to manage authentication.
You'll first need to sign up for an Auth0 account. You can sign up for a free Auth0 account here.
Once you've got your account, you can set up an application to use with our NgRx project. We'll only be setting up a Single Page Application (SPA) in Auth0 since we're using the Google Books API as our back end.
Here's how to set that up:
- Go to your Auth0 Applications and click the "Create Application" button.
- Name your new app, select "Single Page Web Applications," and click the "Create" button. You can skip the Quick Start and click on Settings.
- In the Settings for your new Auth0 app, add
http://localhost:4200/callback
to the Allowed Callback URLs. (We're usinglocalhost:4200
since it's the default port for the Angular CLIserve
command.) - Add
http://localhost:4200
to the Allowed Logout URLs. - Click the "Save Changes" button.
- Copy down your Domain and Client ID. We'll use them in just a minute.
- 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 utilizes username/password database, Facebook, Google, and Twitter.
Note: Under the OAuth tab of Advanced Settings (at the bottom of the Settings section) you should see that the JsonWebToken Signature Algorithm is set to
RS256
. This is the default for new applications. If it is set toHS256
, please change it toRS256
. You can read more about RS256 vs. HS256 JWT signing algorithms here.
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.
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.
This project is licensed under the MIT license. See the LICENSE file for more info.