我具有由固定Keycloak角2應用,舉例here完成。角2,Keycloak:固定某些路線
我想知道,我怎樣才能確保某些路線。
main.ts:
KeycloakService.init()
.then(() => {
const platform = platformBrowserDynamic();
platform.bootstrapModule(AppModule);
})
.catch(() => window.location.reload());
keycloak.service.ts:
@Injectable()
export class KeycloakService {
static auth: any = {};
static loginUser: KeycloakUser;
static init(): Promise<any> {
let keycloakAuth: Keycloak.KeycloakInstance = Keycloak('keycloak/keycloak.json');
KeycloakService.auth.loggedIn = false;
return new Promise((resolve, reject) => {
keycloakAuth.init({ onLoad: 'login-required' })
.success(() => {
KeycloakService.auth.loggedIn = true;
KeycloakService.auth.authz = keycloakAuth;
KeycloakService.auth.logoutUrl = keycloakAuth.authServerUrl + "/realms/demo/protocol/openid-connect/logout?redirect_uri=/angular2-product/index.html";
resolve();
})
.error(() => {
reject();
});
});
}
....
請改善您的問題。問題應該直接包含代碼的基本部分,而不僅僅是一個到外部資源的鏈接。你試過了什麼,你哪裏失敗了?實際和預期的行爲是什麼?錯誤消息,...? –