@tilde-nlp/ngx-user-access
v8.0.14
Published
This library is designed to include shared user access services, such as Authentication, Permissions, and Keycloak. Here, we store all the user-related resources used across different projects.
Readme
NgxUserAccess
This library is designed to include shared user access services, such as Authentication, Permissions, and Keycloak. Here, we store all the user-related resources used across different projects.
Implementation
To integrate this library into your project, add @tilde-nlp/ngx-user-access to your dependencies.
Review the
UserAccessConfiginterface and supply the required fields in the configuration tokenUSER_ACCESS_CONFIG_TOKEN.To configure custom user permissions you should provide
UserConfigurationServicein your application.The
KEYCLOAK_PROVIDERshould be provided in each app config, but only after you've set upUSER_ACCESS_CONFIG_TOKEN.
Required configuration example below:
` class AppUserCustomConfigurationService implements UserCustomConfiguration { updateUserConfiguration(currentConfiguration: UserConfiguration, newConfiguration: UserConfiguration): UserConfiguration { let configuration: UserConfiguration = {};
return configuration;
}}
function USER_CUSTOM_CONFIGURATION_SERVICE_PROVIDER() { return { provide: UserConfigurationService, useClass: AppUserCustomConfigurationService }; }
function USER_ACCESS_CONFIG_PROVIDER() { return { provide: USER_ACCESS_CONFIG_TOKEN, useFactory: (configService: ConfigurationService): UserAccessConfig => { const config = configService.configuration;
// kc token makes strapi return 401, so no need to send it to strapi.
if (!config?.strapi?.disabled) {
EXCLUDE_AUTH_HEADERS_URLS.push(config.strapi!.url!);
}
return {
keycloak: { ...config.auth.keycloak!, bearerExcludedUrls: EXCLUDE_AUTH_HEADERS_URLS },
plans: Object.values([]),
subscriptions: config.subscription,
alwaysAuth: config.auth.alwaysAuth
};
},
deps: [ConfigurationService]
};const USER_ACCESS_PROVIDERS: Provider[] = [USER_ACCESS_CONFIG_PROVIDER(), USER_CUSTOM_CONFIGURATION_SERVICE_PROVIDER()];
providers: [ KeycloakService, USER_ACCESS_PROVIDERS, provideAppInitializer(async () => { return await KEYCLOAK_PROVIDER() }), ] `
