mdds-angular-auth
v0.7.110
Published
Augular Authentication and Authorization Module
Downloads
24
Maintainers
Readme
Augular Authentication and Authorization Module
Usage:
- Add 'mdds-angular-auth" package as dependency in your project in file package.json:
For example:
"dependencies": { "@angular/common": "^6.0.3", "@angular/core": "^6.0.3", "@angular/forms": "^6.0.3", "@angular/http": "^6.0.3", "@angular/router": "^6.0.3", "rxjs": "^6.0.0", "zone.js": "^0.8.26", ... ... "mdds-angular-auth": "" },
- Create a auth.config.ts to add the following two configuration variables required by 'mdds-angular-auth' logic:
export const authentication_login_page_uri: string = '/auth/login'; export const authentication_server_root_uri: string = '/api/auth';
- Declare two providers in your app.module.ts:
import { AUTHENTICATION_LOGIN_PAGE_URI, AUTHENTICATION_SERVER_ROOT_URI } from 'mdds-angular-auth'; import { authentication_login_page_uri, authentication_server_root_uri } from './auth.config'; ... @NgModule( ... providers: [ ... { provide: AUTHENTICATION_LOGIN_PAGE_URI, useValue: authentication_login_page_uri }, { provide: AUTHENTICATION_SERVER_ROOT_URI, useValue: authentication_server_root_uri }
] ...
- Import 'AuthenticationModule' in app.module.ts:
import { AuthenticationModule } from 'mdds-angular-auth'; ...
@NgModule( ... imports: [ ... AuthenticationModule ], ...
- Use AuthGuard to application routers:
import {AuthGuard} from 'mdds-angular-auth'; ... routes: Routes = [ { path: 'path/to/guard', component: ComponentToGuard, canActivate: [AuthGuard], } ... ] ...
- Use the authenticaiton icon in your HTML:
app.component.html