Giter VIP home page Giter VIP logo

angular-auth0-aside's Introduction

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

Auth0 Application Setup

  1. Go to your Auth0 Dashboard: Applications section and click the "+ Create Application" button.
  2. Name your new app and select "Single Page Web Applications".
  3. In the Settings for your new Auth0 app, add http://localhost:4200/callback to the Allowed Callback URLs.
  4. Add http://localhost:4200 to both the Allowed Web Origins and Allowed Logout URLs. Click the "Save Changes" button.
  5. 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

  1. 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 be RS256.
  2. 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
  1. Open server/config.js.example and remove .example from the file name. Then replace [YOUR_AUTH0_DOMAIN] with your Auth0 domain.
  2. 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

  1. Go to Auth0 and click Sign Up.
  2. 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

Auth0

License

This project is licensed under the MIT license. See the LICENSE file for more info.

angular-auth0-aside's People

Contributors

angular-cli avatar kmaida avatar samjulien avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar

angular-auth0-aside's Issues

Error Access Denied

I have configured everything as per the instructions. I made the callback settings properly in the application settings. When I do the ng serve application runs fine when you hit the login

I am getting Error: Access Denied.

image

HttpInterceptor should take the first token then unsubscribe

The InterceptorService currently (AFAICT) creates a new subscription for each http request and never unsubscribes - this causes 3 issues:

  1. Memory leak
  2. If the token ever gets refreshed all of the previous http requests will be repeated
  3. It's impossible to chain requests because the observable never completes

Adding a call to first after the filter resolves this (and changing the BehaviorSubjects to ReplaySubjects in the Auth Service removes the need for the filter).

return this.auth.token$
      .pipe(
        filter(token => typeof token === 'string'),
        first(),
        mergeMap(token => {
          const tokenReq = req.clone({
            setHeaders: { Authorization: `Bearer ${token}` }
          });
          return next.handle(tokenReq);
        })
);

Double encoding of redirect URL in callback

If the auth.handleAuth(); is performed in the constructor of the callback component - then the url will contain double encoded characters. Try adding ":" to a scope in the auth0 configuration. This will be returned as %253A. It should be %3A. This is because an encoded % is %25. It doesn't occur if the auth.handleAuth(); is placed in another component, e.g., home.

Refresh page breaks example

After I successfully login, I see my name and the Logout button.

However, if I refresh the browser page, my name and the Logout button is no longer visible. All I see is the "Angular with Auth0" header.

Does anyone know why this is happening? I would expect that after I refresh the token is rediscovered from the window.

Testing home.component.ts

I'm looking for a way to test HomeComponent without using the real ApiService or AuthService using Angular 7 and rxjs 6.5. Use of Observable.of appears to be deprecated in v6.5.

Home component initializes twice

Home component is being initialized twice, but ONLY after redirecting back to the app after a fresh successful login. This does not occur when there is a currently active session and checkSession runs. I suspect this has to do with updates to Angular's router, and made some changes but the changes seemed ineffective.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.