forked from onecx/onecx-portal-ui-libs
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
2e50909
commit eac1a4b
Showing
22 changed files
with
622 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
import { getJestProjects } from '@nx/jest'; | ||
import { getJestProjects } from '@nx/jest' | ||
|
||
export default { | ||
projects: getJestProjects(), | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
{ | ||
"extends": ["../../.eslintrc.json"], | ||
"ignorePatterns": ["!**/*"], | ||
"overrides": [ | ||
{ | ||
"files": ["*.ts"], | ||
"extends": ["plugin:@nx/angular", "plugin:@angular-eslint/template/process-inline-templates"], | ||
"rules": { | ||
"@angular-eslint/directive-selector": [ | ||
"error", | ||
{ | ||
"type": "attribute", | ||
"prefix": "ocx", | ||
"style": "camelCase" | ||
} | ||
], | ||
"@angular-eslint/component-selector": [ | ||
"error", | ||
{ | ||
"type": "element", | ||
"prefix": "ocx", | ||
"style": "kebab-case" | ||
} | ||
] | ||
} | ||
}, | ||
{ | ||
"files": ["*.html"], | ||
"extends": ["plugin:@nx/angular-template"], | ||
"rules": {} | ||
}, | ||
{ | ||
"files": ["*.json"], | ||
"parser": "jsonc-eslint-parser", | ||
"rules": { | ||
"@nx/dependency-checks": "error" | ||
} | ||
} | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
# keycloak-auth | ||
|
||
This library was generated with [Nx](https://nx.dev). | ||
|
||
## Running unit tests | ||
|
||
Run `nx test keycloak-auth` to execute the unit tests. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
/* eslint-disable */ | ||
export default { | ||
displayName: 'keycloak-auth', | ||
preset: '../../jest.preset.js', | ||
setupFilesAfterEnv: ['<rootDir>/src/test-setup.ts'], | ||
coverageDirectory: '../../coverage/libs/keycloak-auth', | ||
transform: { | ||
'^.+\\.(ts|mjs|js|html)$': [ | ||
'jest-preset-angular', | ||
{ | ||
tsconfig: '<rootDir>/tsconfig.spec.json', | ||
stringifyContentPathRegex: '\\.(html|svg)$', | ||
}, | ||
], | ||
}, | ||
transformIgnorePatterns: ['node_modules/(?!.*\\.mjs$)'], | ||
snapshotSerializers: [ | ||
'jest-preset-angular/build/serializers/no-ng-attributes', | ||
'jest-preset-angular/build/serializers/ng-snapshot', | ||
'jest-preset-angular/build/serializers/html-comment', | ||
], | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
{ | ||
"$schema": "../../node_modules/ng-packagr/ng-package.schema.json", | ||
"dest": "../../dist/libs/keycloak-auth", | ||
"lib": { | ||
"entryFile": "src/index.ts" | ||
}, | ||
"assets": ["CHANGELOG.md", "./assets/**"] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
{ | ||
"name": "@onecx/keycloak-auth", | ||
"version": "0.0.1", | ||
"peerDependencies": { | ||
"@angular/common": ">=15.2.7", | ||
"@angular/core": ">=15.2.7", | ||
"@onecx/portal-integration-angular": "~3", | ||
"keycloak-angular": "^13.0.0", | ||
"keycloak-js": "^18.0.0", | ||
"rxjs": "~7.8.0" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
{ | ||
"name": "keycloak-auth", | ||
"$schema": "../../node_modules/nx/schemas/project-schema.json", | ||
"sourceRoot": "libs/keycloak-auth/src", | ||
"prefix": "ocx", | ||
"tags": [], | ||
"projectType": "library", | ||
"targets": { | ||
"build": { | ||
"executor": "@nx/angular:package", | ||
"outputs": ["{workspaceRoot}/dist/{projectRoot}"], | ||
"options": { | ||
"project": "libs/keycloak-auth/ng-package.json" | ||
}, | ||
"configurations": { | ||
"production": { | ||
"tsConfig": "libs/keycloak-auth/tsconfig.lib.prod.json" | ||
}, | ||
"development": { | ||
"tsConfig": "libs/keycloak-auth/tsconfig.lib.json" | ||
} | ||
}, | ||
"defaultConfiguration": "production" | ||
}, | ||
"test": { | ||
"executor": "@nx/jest:jest", | ||
"outputs": ["{workspaceRoot}/coverage/{projectRoot}"], | ||
"options": { | ||
"jestConfig": "libs/keycloak-auth/jest.config.ts", | ||
"passWithNoTests": true | ||
}, | ||
"configurations": { | ||
"ci": { | ||
"ci": true, | ||
"codeCoverage": true | ||
} | ||
} | ||
}, | ||
"lint": { | ||
"executor": "@nx/linter:eslint", | ||
"outputs": ["{options.outputFile}"], | ||
"options": { | ||
"lintFilePatterns": [ | ||
"libs/keycloak-auth/**/*.ts", | ||
"libs/keycloak-auth/**/*.html", | ||
"libs/keycloak-auth/package.json" | ||
] | ||
} | ||
}, | ||
"release": { | ||
"executor": "nx-release:build-update-publish", | ||
"options": { | ||
"libName": "portal-integration-angular" | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export * from './lib/keycloak-auth.module' |
24 changes: 24 additions & 0 deletions
24
libs/keycloak-auth/src/lib/keycloak-auth.app-initializer.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
// import { APP_INITIALIZER, Provider } from '@angular/core'; | ||
// import { KeycloakAuthService } from './keycloak-auth.service'; | ||
|
||
// function initializeKeycloak(authService: KeycloakAuthService) { | ||
// return () => | ||
// authService.init({ | ||
// config: { | ||
// url: 'http://localhost:8080/auth', | ||
// realm: 'your-realm', | ||
// clientId: 'your-client-id' | ||
// }, | ||
// initOptions: { | ||
// onLoad: 'check-sso', | ||
// silentCheckSsoRedirectUri: | ||
// window.location.origin + '/assets/silent-check-sso.html' | ||
// } | ||
// }); | ||
// } | ||
// export const KeycloakAuthAppInitializer : Provider = { | ||
// provide: APP_INITIALIZER, | ||
// useFactory: initializeKeycloak, | ||
// multi: true, | ||
// deps: [KeycloakAuthService] | ||
// } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
import { InjectionToken, NgModule, ModuleWithProviders } from '@angular/core' | ||
import { CommonModule } from '@angular/common' | ||
import { AUTH_SERVICE } from '@onecx/portal-integration-angular' | ||
import { KeycloakAuthService } from './keycloak-auth.service' | ||
import { KeycloakAngularModule } from 'keycloak-angular' | ||
import { HTTP_INTERCEPTORS } from '@angular/common/http' | ||
import { TokenInterceptor } from './token.interceptor' | ||
|
||
export interface KeycloakAuthModuleConfig { | ||
disablePermissionCheck: boolean | ||
tokenInterceptorWhitelist?: string[] | ||
} | ||
/** | ||
* Authentication module for keycloak. Requires @onecx/portal-integration-angular and keycloak-js to work. | ||
*/ | ||
@NgModule({ | ||
imports: [CommonModule, KeycloakAngularModule], | ||
providers: [ | ||
{ | ||
provide: AUTH_SERVICE, | ||
useClass: KeycloakAuthService, | ||
}, | ||
{ provide: HTTP_INTERCEPTORS, useClass: TokenInterceptor, multi: true }, | ||
], | ||
}) | ||
export class KeycloakAuthModule { | ||
static withConfig(config: KeycloakAuthModuleConfig): ModuleWithProviders<KeycloakAuthModule> { | ||
return { | ||
ngModule: KeycloakAuthModule, | ||
providers: [ | ||
{ | ||
provide: AUTH_SERVICE, | ||
useClass: KeycloakAuthService, | ||
}, | ||
{ provide: HTTP_INTERCEPTORS, useClass: TokenInterceptor, multi: true }, | ||
{ provide: KEYCLOAK_AUTH_CONFIG, useValue: config }, | ||
], | ||
} | ||
} | ||
} | ||
|
||
export const KEYCLOAK_AUTH_CONFIG: InjectionToken<KeycloakAuthModuleConfig> = new InjectionToken('KEYCLOAK_AUTH_CONFIG') |
Oops, something went wrong.