Auth0 Angular2 library helps you easily integrate Auth0 with your Angular 2 application. Auth0 Angular2 is written in TypeScript.
npm install auth0-angular2
and in your index.html
<script src="http://cdn.auth0.com/js/lock/10.4/lock.min.js"></script>
(If you know how to include the Auth0 Lock dependency in the library, please contribute!)
Add provideAuthService
to the providers
array in your @NgModule
.
import { provideAuthService } from 'auth0-angular2';
...
@NgModule({
...
providers: [
provideAuthService('clientId', 'domain')
],
...
})
After a successful login, Auth0 Lock by default redirects to the path that triggers the Lock and you may override it by providing a /redirectPath
parameter. You may also provide a /homePath
parameter to indicate where to route the application to after a successful login.
provideAuthService('clientId', 'domain', '/homePath', '/redirectPath')
Using an authentication route guard as an example
import { Injectable } from '@angular/core';
import { CanActivate } from '@angular/router';
import { AuthService } from 'auth0-angular2';
@Injectable()
export class AuthGuard implements CanActivate {
constructor(private auth: AuthService) { }
canActivate() {
if(this.auth.loginIfNotAuthenticated()){
return false;
}
return true;
}
}
Please use angular2-jwt directly, which is already installed with this library. (More features on sending authenticated HTTP requests are currently under development.)
Pull requests are welcome!
npm install
and
npm run prepublish
to compile.
We currently ensure browser compatibility in Chrome only.
If you have found a bug or if you have a feature request, please report them at this repository issues section.
This project is licensed under the Apache 2.0 license. See the LICENSE file for more info.