1 |
- {"version":3,"sources":["../../src/app/keycloak-service/keycloak.service.ts"],"names":["KeycloakService","constructor","keycloak","keycloakAuth","authenticated","audiencePresent","tokenParsed","audience","Array","isArray","indexOf","login","options","logout","redirectUri","baseUrl","account","accountManagement","authServerUrl","charAt","length","realm","getToken","Promise","resolve","reject","token","updateToken","success","error"],"mappings":";;AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AAMA,OAAO,MAAMA,eAAN,CAAsB;AAGlBC,EAAAA,WAAW,CAACC,QAAD,EAA2B;AAAA;;AACzC,SAAKC,YAAL,GAAoBD,QAApB;AACH;;AAEME,EAAAA,aAAa,GAAY;AAC5B,WAAO,KAAKD,YAAL,CAAkBC,aAAlB,GAAkC,KAAKD,YAAL,CAAkBC,aAApD,GAAoE,KAA3E;AACH;;AAEMC,EAAAA,eAAe,GAAY;AAC9B,QAAI,KAAKF,YAAL,CAAkBG,WAAtB,EAAmC;AAC/B,YAAMC,QAAQ,GAAG,KAAKJ,YAAL,CAAkBG,WAAlB,CAA8B,KAA9B,CAAjB;AACA,aAAOC,QAAQ,KAAK,SAAb,IAA2BC,KAAK,CAACC,OAAN,CAAcF,QAAd,KAA2BA,QAAQ,CAACG,OAAT,CAAiB,SAAjB,KAA+B,CAA5F;AACH;;AACD,WAAO,KAAP;AACH;;AAEMC,EAAAA,KAAK,CAACC,OAAD,EAAuC;AAC/C,SAAKT,YAAL,CAAkBQ,KAAlB,CAAwBC,OAAxB;AACH;;AAEMC,EAAAA,MAAM,CAACC,WAAmB,GAAGC,OAAvB,EAAsC;AAC/C,SAAKZ,YAAL,CAAkBU,MAAlB,CAAyB;AAACC,MAAAA,WAAW,EAAEA;AAAd,KAAzB;AACH;;AAEME,EAAAA,OAAO,GAAS;AACnB,SAAKb,YAAL,CAAkBc,iBAAlB;AACH;;AAEMC,EAAAA,aAAa,GAAuB;AACvC,UAAMA,aAAa,GAAG,KAAKf,YAAL,CAAkBe,aAAxC;AACA,WAAOA,aAAa,CAAEC,MAAf,CAAsBD,aAAa,CAAEE,MAAf,GAAwB,CAA9C,MAAqD,GAArD,GAA2DF,aAA3D,GAA2EA,aAAa,GAAG,GAAlG;AACH;;AAEMG,EAAAA,KAAK,GAAuB;AAC/B,WAAO,KAAKlB,YAAL,CAAkBkB,KAAzB;AACH;;AAEMC,EAAAA,QAAQ,GAAoB;AAC/B,WAAO,IAAIC,OAAJ,CAAoB,CAACC,OAAD,EAAUC,MAAV,KAAqB;AAC5C,UAAI,KAAKtB,YAAL,CAAkBuB,KAAtB,EAA6B;AACzB,aAAKvB,YAAL,CACKwB,WADL,CACiB,CADjB,EAEKC,OAFL,CAEa,MAAM;AACXJ,UAAAA,OAAO,CAAC,KAAKrB,YAAL,CAAkBuB,KAAnB,CAAP;AACH,SAJL,EAKKG,KALL,CAKW,MAAM;AACTJ,UAAAA,MAAM,CAAC,yBAAD,CAAN;AACH,SAPL;AAQH,OATD,MASO;AACHA,QAAAA,MAAM,CAAC,eAAD,CAAN;AACH;AACJ,KAbM,CAAP;AAcH;;AAvDwB","sourcesContent":["/*\n * Copyright 2017 Red Hat, Inc. and/or its affiliates\n * and other contributors as indicated by the @author tags.\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\nimport {KeycloakLoginOptions} from \"../../../../../../../../../../adapters/oidc/js/src/main/resources/keycloak\";\n\ndeclare const baseUrl: string;\nexport type KeycloakClient = Keycloak.KeycloakInstance;\n\nexport class KeycloakService {\n private keycloakAuth: KeycloakClient;\n\n public constructor(keycloak: KeycloakClient) {\n this.keycloakAuth = keycloak;\n }\n\n public authenticated(): boolean {\n return this.keycloakAuth.authenticated ? this.keycloakAuth.authenticated : false;\n }\n\n public audiencePresent(): boolean {\n if (this.keycloakAuth.tokenParsed) {\n const audience = this.keycloakAuth.tokenParsed['aud'];\n return audience === 'account' || (Array.isArray(audience) && audience.indexOf('account') >= 0);\n }\n return false;\n }\n\n public login(options?: KeycloakLoginOptions): void {\n this.keycloakAuth.login(options);\n }\n\n public logout(redirectUri: string = baseUrl): void {\n this.keycloakAuth.logout({redirectUri: redirectUri});\n }\n\n public account(): void {\n this.keycloakAuth.accountManagement();\n }\n\n public authServerUrl(): string | undefined {\n const authServerUrl = this.keycloakAuth.authServerUrl;\n return authServerUrl!.charAt(authServerUrl!.length - 1) === '/' ? authServerUrl : authServerUrl + '/';\n }\n\n public realm(): string | undefined {\n return this.keycloakAuth.realm;\n }\n\n public getToken(): Promise<string> {\n return new Promise<string>((resolve, reject) => {\n if (this.keycloakAuth.token) {\n this.keycloakAuth\n .updateToken(5)\n .success(() => {\n resolve(this.keycloakAuth.token as string);\n })\n .error(() => {\n reject('Failed to refresh token');\n });\n } else {\n reject('Not logged in');\n }\n });\n }\n}\n"],"file":"keycloak.service.js"}
|