Description
This is module of angular 5 destributed as folder.
Modul based on adal.js library and support authorization throw receiving roles and privileges throw http request.
npmrc
Create a .npmrc file in your project and add below scoped repository
@honeywell:registry=https://artifactory-na.honeywell.com/artifactory/api/npm/Honeywell.CBP.IOT.API-8588-unstable-npm-local/
Install
npm install @honeywell/ccs-security-ng5
Integrate to project
add module to ts compiling paths
" include " : [
" src/**/* " ,
" @honeywell/node_modules/ccs-security-ng5/authorisation.module.ts "
]
add module to app
import { AuthorisationModule } from ' @honeywell/ccs-security-ng5/authorisation.module ' ;
@ NgModule ( {
...
imports : [
...
AuthorisationModule
] ,
...
Initialize
import { AuthorisationService } from ' @honeywell/ccs-security-ng5/authorisation.module ' ;
...
export class AppComponent {
constructor ( service : AuthorisationService ) {
service . init ( {
tenant : ' <guid> ' ,
clientId : ' <guid> ' ,
redirectUri : ' <url> ' ,
endpoints : {
' <url> ' : ' <unique url or guid> ' ,
' <url> ' : ' <unique url or guid> '
} ,
ocpApimSubscriptionKey : ' <id> ' ,
organizationId : ' <id> ' ,
getRoleUrl : ' <url> ' ,
getRoleResource : ' <unique url or guid> '
}
}
...
}
Guard
AuthorisationGuard is protecting pages of app
import { AuthorisationGuard } from ' @honeywell/ccs-security-ng5/authorisation.module ' ;
const siteRouting : ModuleWithProviders = RouterModule . forChild ( [
{
path : ' <url> ' ,
canActivate : [ AuthorisationGuard ] ,
data : {
privileges : [ ' read ' ] ,
roles : [ ' admin ' ]
}
}
] ) ;
@ NgModule ( {
imports : [
siteRouting ,
...
Interceptor
AuthorisationInterceptor add access token to all requests described in config of module (endpoints section)
import { AuthorisationInterceptor } from ' @honeywell/ccs-security-ng5/authorisation.module ' ;
@ NgModule ( {
...
providers : [
{
provide : HTTP_INTERCEPTORS ,
useClass : AuthorisationInterceptor ,
multi : true
}
]
...
} )