@indigina/ui-kit 1.1.661 → 1.1.662
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -1,6 +1,7 @@
|
|
|
1
|
+
import { Location } from '@angular/common';
|
|
1
2
|
import * as i0 from '@angular/core';
|
|
2
3
|
import { inject, Injectable, makeEnvironmentProviders } from '@angular/core';
|
|
3
|
-
import { AuthService, authHttpInterceptorFn, provideAuth0 } from '@auth0/auth0-angular';
|
|
4
|
+
import { AuthService, AuthClientConfig, authHttpInterceptorFn, provideAuth0 } from '@auth0/auth0-angular';
|
|
4
5
|
import { EMPTY } from 'rxjs';
|
|
5
6
|
import { filter, take, switchMap } from 'rxjs/operators';
|
|
6
7
|
import { withInterceptors } from '@angular/common/http';
|
|
@@ -8,6 +9,8 @@ import { withInterceptors } from '@angular/common/http';
|
|
|
8
9
|
class KitAuthService {
|
|
9
10
|
constructor() {
|
|
10
11
|
this.auth0 = inject(AuthService);
|
|
12
|
+
this.location = inject(Location);
|
|
13
|
+
this.authConfig = inject(AuthClientConfig, { optional: true });
|
|
11
14
|
this.loggingIn = false;
|
|
12
15
|
this.loggingOut = false;
|
|
13
16
|
}
|
|
@@ -27,7 +30,7 @@ class KitAuthService {
|
|
|
27
30
|
if (this.loggingIn || this.loggingOut) {
|
|
28
31
|
return;
|
|
29
32
|
}
|
|
30
|
-
const target = targetPath ??
|
|
33
|
+
const target = targetPath ?? (this.location.path(true) || '/');
|
|
31
34
|
this.loggingIn = true;
|
|
32
35
|
this.auth0.loginWithRedirect({ appState: { target } }).subscribe({
|
|
33
36
|
error: () => {
|
|
@@ -40,7 +43,7 @@ class KitAuthService {
|
|
|
40
43
|
this.auth0
|
|
41
44
|
.logout({
|
|
42
45
|
logoutParams: {
|
|
43
|
-
returnTo: window.location.origin,
|
|
46
|
+
returnTo: this.authConfig?.get()?.authorizationParams?.redirect_uri ?? window.location.origin,
|
|
44
47
|
},
|
|
45
48
|
})
|
|
46
49
|
.subscribe({
|
|
@@ -112,9 +115,9 @@ const buildAllowedList = (apiUrls) => {
|
|
|
112
115
|
];
|
|
113
116
|
});
|
|
114
117
|
};
|
|
115
|
-
const buildAuthorizationParams = (settings) => {
|
|
118
|
+
const buildAuthorizationParams = (settings, appUrl) => {
|
|
116
119
|
const authorizationParams = {
|
|
117
|
-
redirect_uri:
|
|
120
|
+
redirect_uri: appUrl,
|
|
118
121
|
audience: settings.audience,
|
|
119
122
|
scope: 'openid profile email offline_access',
|
|
120
123
|
};
|
|
@@ -134,6 +137,7 @@ const provideKitAuth0 = (settings, options) => {
|
|
|
134
137
|
if (!normalizedSettings.domain || !normalizedSettings.clientId || !normalizedSettings.audience) {
|
|
135
138
|
throw new Error('Auth0 settings are incomplete: domain, clientId, and audience are required');
|
|
136
139
|
}
|
|
140
|
+
const appUrl = options.appUrl ?? window.location.origin;
|
|
137
141
|
return makeEnvironmentProviders([
|
|
138
142
|
provideAuth0({
|
|
139
143
|
domain: normalizedSettings.domain,
|
|
@@ -141,7 +145,7 @@ const provideKitAuth0 = (settings, options) => {
|
|
|
141
145
|
cacheLocation: options.cacheLocation ?? DEFAULT_CACHE_LOCATION,
|
|
142
146
|
useRefreshTokens: true,
|
|
143
147
|
useRefreshTokensFallback: false,
|
|
144
|
-
authorizationParams: buildAuthorizationParams(normalizedSettings),
|
|
148
|
+
authorizationParams: buildAuthorizationParams(normalizedSettings, appUrl),
|
|
145
149
|
httpInterceptor: {
|
|
146
150
|
allowedList: buildAllowedList(options.allowedApiUrls),
|
|
147
151
|
},
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"indigina-ui-kit-auth0.mjs","sources":["../../../projects/ui-kit/auth0/src/lib/services/kit-auth.service.ts","../../../projects/ui-kit/auth0/src/lib/services/kit-auth-http.interceptor.ts","../../../projects/ui-kit/auth0/src/lib/services/provide-kit-auth.ts","../../../projects/ui-kit/auth0/indigina-ui-kit-auth0.ts"],"sourcesContent":["import { inject, Injectable } from '@angular/core';\nimport { AuthService } from '@auth0/auth0-angular';\nimport { EMPTY, Observable } from 'rxjs';\nimport { filter, switchMap, take } from 'rxjs/operators';\n\n@Injectable()\nexport class KitAuthService {\n private readonly auth0: AuthService = inject(AuthService);\n private loggingIn: boolean = false;\n private loggingOut: boolean = false;\n\n isAuthenticated$(): Observable<boolean> {\n return this.auth0.isLoading$.pipe(\n filter((loading: boolean) => !loading),\n take(1),\n switchMap(() => this.auth0.isAuthenticated$),\n );\n }\n\n getAccessToken$(): Observable<string> {\n if (this.loggingOut) {\n return EMPTY;\n }\n\n return this.auth0.getAccessTokenSilently();\n }\n\n isLoggingOut(): boolean {\n return this.loggingOut;\n }\n\n login(targetPath?: string): void {\n if (this.loggingIn || this.loggingOut) {\n return;\n }\n\n const target: string = targetPath ?? `${window.location.pathname}${window.location.search}${window.location.hash}`;\n this.loggingIn = true;\n this.auth0.loginWithRedirect({ appState: { target } }).subscribe({\n error: () => {\n this.loggingIn = false;\n },\n });\n }\n\n logout(): void {\n this.loggingOut = true;\n this.auth0\n .logout({\n logoutParams: {\n returnTo: window.location.origin,\n },\n })\n .subscribe({\n error: () => {\n this.loggingOut = false;\n },\n });\n }\n}\n","import { HttpInterceptorFn } from '@angular/common/http';\nimport { inject } from '@angular/core';\nimport { authHttpInterceptorFn } from '@auth0/auth0-angular';\nimport { EMPTY } from 'rxjs';\nimport { KitAuthService } from './kit-auth.service';\n\nexport const kitAuthHttpInterceptor: HttpInterceptorFn = (request, next) => {\n if (request.headers.has('Authorization')) {\n return next(request);\n }\n\n const session: KitAuthService | null = inject(KitAuthService, {\n optional: true,\n });\n if (session?.isLoggingOut()) {\n return EMPTY;\n }\n\n return authHttpInterceptorFn(request, next);\n};\n","import { HttpFeature, HttpFeatureKind, withInterceptors } from '@angular/common/http';\nimport {\n EnvironmentProviders,\n makeEnvironmentProviders,\n} from '@angular/core';\nimport { AuthorizationParams, provideAuth0 } from '@auth0/auth0-angular';\nimport {\n KitAuth0CacheLocation,\n KitAuth0Options,\n KitAuth0Settings,\n} from '../models/kit-auth0-settings.model';\nimport { kitAuthHttpInterceptor } from './kit-auth-http.interceptor';\nimport { KitAuthService } from './kit-auth.service';\n\nconst DEFAULT_CACHE_LOCATION: KitAuth0CacheLocation = 'localstorage';\n\nconst stripTrailingSlashes = (value: string): string => {\n let end: number = value.length;\n while (end > 0 && value[end - 1] === '/') {\n end -= 1;\n }\n\n return value.slice(0, end);\n};\n\nconst isValidApiBaseUrl = (value: string, parsed: URL): boolean =>\n /^https?:\\/\\/[^/]/i.test(value) &&\n !!parsed.hostname &&\n !value.includes('*') &&\n !value.includes('\\\\') &&\n !/\\s/.test(value) &&\n !parsed.username &&\n !parsed.password &&\n !value.includes('?') &&\n !value.includes('#');\n\nconst buildAllowedList = (apiUrls: readonly string[]): string[] => {\n if (apiUrls.length === 0) {\n throw new Error('Auth0 API allowlist must contain at least one URL');\n }\n\n return apiUrls.flatMap((apiUrl) => {\n const normalized: string = apiUrl.trim();\n if (!normalized) {\n throw new Error('Auth0 API allowlist contains an empty URL');\n }\n\n let parsed: URL;\n try {\n parsed = new URL(normalized);\n } catch {\n throw new Error('Auth0 API allowlist must contain absolute HTTP(S) URLs without wildcards, credentials, queries, or fragments');\n }\n\n if (!isValidApiBaseUrl(normalized, parsed)) {\n throw new Error('Auth0 API allowlist must contain absolute HTTP(S) URLs without wildcards, credentials, queries, or fragments');\n }\n\n const baseUrl: string = stripTrailingSlashes(parsed.href);\n\n return [\n baseUrl,\n `${baseUrl}/*`,\n ];\n });\n};\n\nconst buildAuthorizationParams = (\n settings: KitAuth0Settings,\n): AuthorizationParams => {\n const authorizationParams: AuthorizationParams = {\n redirect_uri: window.location.origin,\n audience: settings.audience,\n scope: 'openid profile email offline_access',\n };\n if (settings.connection) {\n authorizationParams.connection = settings.connection;\n }\n\n return authorizationParams;\n};\n\nexport const withKitAuthHttpInterceptor = (): HttpFeature<HttpFeatureKind.Interceptors> =>\n withInterceptors([kitAuthHttpInterceptor]);\n\nexport const provideKitAuth0 = (\n settings: KitAuth0Settings,\n options: KitAuth0Options,\n): EnvironmentProviders => {\n const normalizedSettings: KitAuth0Settings = {\n domain: settings.domain?.trim(),\n clientId: settings.clientId?.trim(),\n audience: settings.audience?.trim(),\n connection: settings.connection?.trim() || undefined,\n };\n if (!normalizedSettings.domain || !normalizedSettings.clientId || !normalizedSettings.audience) {\n throw new Error(\n 'Auth0 settings are incomplete: domain, clientId, and audience are required',\n );\n }\n\n return makeEnvironmentProviders([\n provideAuth0({\n domain: normalizedSettings.domain,\n clientId: normalizedSettings.clientId,\n cacheLocation: options.cacheLocation ?? DEFAULT_CACHE_LOCATION,\n useRefreshTokens: true,\n useRefreshTokensFallback: false,\n authorizationParams: buildAuthorizationParams(normalizedSettings),\n httpInterceptor: {\n allowedList: buildAllowedList(options.allowedApiUrls),\n },\n }),\n KitAuthService,\n ]);\n};\n","/**\n * Generated bundle index. Do not edit.\n */\n\nexport * from './public-api';\n"],"names":[],"mappings":";;;;;;;MAMa,cAAc,CAAA;AAD3B,IAAA,WAAA,GAAA;AAEmB,QAAA,IAAA,CAAA,KAAK,GAAgB,MAAM,CAAC,WAAW,CAAC;QACjD,IAAA,CAAA,SAAS,GAAY,KAAK;QAC1B,IAAA,CAAA,UAAU,GAAY,KAAK;AAkDpC,IAAA;IAhDC,gBAAgB,GAAA;AACd,QAAA,OAAO,IAAI,CAAC,KAAK,CAAC,UAAU,CAAC,IAAI,CAC/B,MAAM,CAAC,CAAC,OAAgB,KAAK,CAAC,OAAO,CAAC,EACtC,IAAI,CAAC,CAAC,CAAC,EACP,SAAS,CAAC,MAAM,IAAI,CAAC,KAAK,CAAC,gBAAgB,CAAC,CAC7C;IACH;IAEA,eAAe,GAAA;AACb,QAAA,IAAI,IAAI,CAAC,UAAU,EAAE;AACnB,YAAA,OAAO,KAAK;QACd;AAEA,QAAA,OAAO,IAAI,CAAC,KAAK,CAAC,sBAAsB,EAAE;IAC5C;IAEA,YAAY,GAAA;QACV,OAAO,IAAI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AAA,QAAQ,EAAE,QAAQ,CAAC,QAAQ,EAAE,IAAI,EAAE;AACnC,QAAA,QAAQ,EAAE,QAAQ,CAAC,QAAQ,EAAE,IAAI,EAAE;QACnC,UAAU,EAAE,QAAQ,CAAC,UAAU,EAAE,IAAI,EAAE,IAAI,SAAS;KACrD;AACD,IAAA,IAAI,CAAC,kBAAkB,CAAC,MAAM,IAAI,CAAC,kBAAkB,CAAC,QAAQ,IAAI,CAAC,kBAAkB,CAAC,QAAQ,EAAE;AAC9F,QAAA,MAAM,IAAI,KAAK,CACb,4EAA4E,CAC7E;IACH;AAEA,IAAA,OAAO,wBAAwB,CAAC;AAC9B,QAAA,YAAY,CAAC;YACX,MAAM,EAAE,kBAAkB,CAAC,MAAM;YACjC,QAAQ,EAAE,kBAAkB,CAAC,QAAQ;AACrC,YAAA,aAAa,EAAE,OAAO,CAAC,aAAa,IAAI,sBAAsB;AAC9D,YAAA,gBAAgB,EAAE,IAAI;AACtB,YAAA,wBAAwB,EAAE,KAAK;AAC/B,YAAA,mBAAmB,EAAE,wBAAwB,CAAC,kBAAkB,CAAC;AACjE,YAAA,eAAe,EAAE;AACf,gBAAA,WAAW,EAAE,gBAAgB,CAAC,OAAO,CAAC,cAAc,CAAC;AACtD,aAAA;SACF,CAAC;QACF,cAAc;AACf,KAAA,CAAC;AACJ;;ACnHA;;AAEG;;;;"}
|
|
1
|
+
{"version":3,"file":"indigina-ui-kit-auth0.mjs","sources":["../../../projects/ui-kit/auth0/src/lib/services/kit-auth.service.ts","../../../projects/ui-kit/auth0/src/lib/services/kit-auth-http.interceptor.ts","../../../projects/ui-kit/auth0/src/lib/services/provide-kit-auth.ts","../../../projects/ui-kit/auth0/indigina-ui-kit-auth0.ts"],"sourcesContent":["import { Location } from '@angular/common';\nimport { inject, Injectable } from '@angular/core';\nimport { AuthClientConfig, AuthService } from '@auth0/auth0-angular';\nimport { EMPTY, Observable } from 'rxjs';\nimport { filter, switchMap, take } from 'rxjs/operators';\n\n@Injectable()\nexport class KitAuthService {\n private readonly auth0: AuthService = inject(AuthService);\n private readonly location: Location = inject(Location);\n private readonly authConfig: AuthClientConfig | null = inject(AuthClientConfig, { optional: true });\n private loggingIn: boolean = false;\n private loggingOut: boolean = false;\n\n isAuthenticated$(): Observable<boolean> {\n return this.auth0.isLoading$.pipe(\n filter((loading: boolean) => !loading),\n take(1),\n switchMap(() => this.auth0.isAuthenticated$),\n );\n }\n\n getAccessToken$(): Observable<string> {\n if (this.loggingOut) {\n return EMPTY;\n }\n\n return this.auth0.getAccessTokenSilently();\n }\n\n isLoggingOut(): boolean {\n return this.loggingOut;\n }\n\n login(targetPath?: string): void {\n if (this.loggingIn || this.loggingOut) {\n return;\n }\n\n const target: string = targetPath ?? (this.location.path(true) || '/');\n this.loggingIn = true;\n this.auth0.loginWithRedirect({ appState: { target } }).subscribe({\n error: () => {\n this.loggingIn = false;\n },\n });\n }\n\n logout(): void {\n this.loggingOut = true;\n this.auth0\n .logout({\n logoutParams: {\n returnTo: this.authConfig?.get()?.authorizationParams?.redirect_uri ?? window.location.origin,\n },\n })\n .subscribe({\n error: () => {\n this.loggingOut = false;\n },\n });\n }\n}\n","import { HttpInterceptorFn } from '@angular/common/http';\nimport { inject } from '@angular/core';\nimport { authHttpInterceptorFn } from '@auth0/auth0-angular';\nimport { EMPTY } from 'rxjs';\nimport { KitAuthService } from './kit-auth.service';\n\nexport const kitAuthHttpInterceptor: HttpInterceptorFn = (request, next) => {\n if (request.headers.has('Authorization')) {\n return next(request);\n }\n\n const session: KitAuthService | null = inject(KitAuthService, {\n optional: true,\n });\n if (session?.isLoggingOut()) {\n return EMPTY;\n }\n\n return authHttpInterceptorFn(request, next);\n};\n","import { HttpFeature, HttpFeatureKind, withInterceptors } from '@angular/common/http';\nimport {\n EnvironmentProviders,\n makeEnvironmentProviders,\n} from '@angular/core';\nimport { AuthorizationParams, provideAuth0 } from '@auth0/auth0-angular';\nimport {\n KitAuth0CacheLocation,\n KitAuth0Options,\n KitAuth0Settings,\n} from '../models/kit-auth0-settings.model';\nimport { kitAuthHttpInterceptor } from './kit-auth-http.interceptor';\nimport { KitAuthService } from './kit-auth.service';\n\nconst DEFAULT_CACHE_LOCATION: KitAuth0CacheLocation = 'localstorage';\n\nconst stripTrailingSlashes = (value: string): string => {\n let end: number = value.length;\n while (end > 0 && value[end - 1] === '/') {\n end -= 1;\n }\n\n return value.slice(0, end);\n};\n\nconst isValidApiBaseUrl = (value: string, parsed: URL): boolean =>\n /^https?:\\/\\/[^/]/i.test(value) &&\n !!parsed.hostname &&\n !value.includes('*') &&\n !value.includes('\\\\') &&\n !/\\s/.test(value) &&\n !parsed.username &&\n !parsed.password &&\n !value.includes('?') &&\n !value.includes('#');\n\nconst buildAllowedList = (apiUrls: readonly string[]): string[] => {\n if (apiUrls.length === 0) {\n throw new Error('Auth0 API allowlist must contain at least one URL');\n }\n\n return apiUrls.flatMap((apiUrl) => {\n const normalized: string = apiUrl.trim();\n if (!normalized) {\n throw new Error('Auth0 API allowlist contains an empty URL');\n }\n\n let parsed: URL;\n try {\n parsed = new URL(normalized);\n } catch {\n throw new Error('Auth0 API allowlist must contain absolute HTTP(S) URLs without wildcards, credentials, queries, or fragments');\n }\n\n if (!isValidApiBaseUrl(normalized, parsed)) {\n throw new Error('Auth0 API allowlist must contain absolute HTTP(S) URLs without wildcards, credentials, queries, or fragments');\n }\n\n const baseUrl: string = stripTrailingSlashes(parsed.href);\n\n return [\n baseUrl,\n `${baseUrl}/*`,\n ];\n });\n};\n\nconst buildAuthorizationParams = (\n settings: KitAuth0Settings,\n appUrl: string,\n): AuthorizationParams => {\n const authorizationParams: AuthorizationParams = {\n redirect_uri: appUrl,\n audience: settings.audience,\n scope: 'openid profile email offline_access',\n };\n if (settings.connection) {\n authorizationParams.connection = settings.connection;\n }\n\n return authorizationParams;\n};\n\nexport const withKitAuthHttpInterceptor = (): HttpFeature<HttpFeatureKind.Interceptors> =>\n withInterceptors([kitAuthHttpInterceptor]);\n\nexport const provideKitAuth0 = (\n settings: KitAuth0Settings,\n options: KitAuth0Options,\n): EnvironmentProviders => {\n const normalizedSettings: KitAuth0Settings = {\n domain: settings.domain?.trim(),\n clientId: settings.clientId?.trim(),\n audience: settings.audience?.trim(),\n connection: settings.connection?.trim() || undefined,\n };\n if (!normalizedSettings.domain || !normalizedSettings.clientId || !normalizedSettings.audience) {\n throw new Error(\n 'Auth0 settings are incomplete: domain, clientId, and audience are required',\n );\n }\n\n const appUrl: string = options.appUrl ?? window.location.origin;\n\n return makeEnvironmentProviders([\n provideAuth0({\n domain: normalizedSettings.domain,\n clientId: normalizedSettings.clientId,\n cacheLocation: options.cacheLocation ?? DEFAULT_CACHE_LOCATION,\n useRefreshTokens: true,\n useRefreshTokensFallback: false,\n authorizationParams: buildAuthorizationParams(normalizedSettings, appUrl),\n httpInterceptor: {\n allowedList: buildAllowedList(options.allowedApiUrls),\n },\n }),\n KitAuthService,\n ]);\n};\n","/**\n * Generated bundle index. Do not edit.\n */\n\nexport * from './public-api';\n"],"names":[],"mappings":";;;;;;;;MAOa,cAAc,CAAA;AAD3B,IAAA,WAAA,GAAA;AAEmB,QAAA,IAAA,CAAA,KAAK,GAAgB,MAAM,CAAC,WAAW,CAAC;AACxC,QAAA,IAAA,CAAA,QAAQ,GAAa,MAAM,CAAC,QAAQ,CAAC;QACrC,IAAA,CAAA,UAAU,GAA4B,MAAM,CAAC,gBAAgB,EAAE,EAAE,QAAQ,EAAE,IAAI,EAAE,CAAC;QAC3F,IAAA,CAAA,SAAS,GAAY,KAAK;QAC1B,IAAA,CAAA,UAAU,GAAY,KAAK;AAkDpC,IAAA;IAhDC,gBAAgB,GAAA;AACd,QAAA,OAAO,IAAI,CAAC,KAAK,CAAC,UAAU,CAAC,IAAI,CAC/B,MAAM,CAAC,CAAC,OAAgB,KAAK,CAAC,OAAO,CAAC,EACtC,IAAI,CAAC,CAAC,CAAC,EACP,SAAS,CAAC,MAAM,IAAI,CAAC,KAAK,CAAC,gBAAgB,CAAC,CAC7C;I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
14
|
allowedApiUrls: readonly string[];
|
|
15
15
|
cacheLocation?: KitAuth0CacheLocation;
|
|
16
|
+
appUrl?: string;
|
|
16
17
|
}
|
|
17
18
|
|
|
18
19
|
declare class KitAuthService {
|
|
19
20
|
private readonly auth0;
|
|
21
|
+
private readonly location;
|
|
22
|
+
private readonly authConfig;
|
|
20
23
|
private loggingIn;
|
|
21
24
|
private loggingOut;
|
|
22
25
|
isAuthenticated$(): Observable<boolean>;
|