@rxap/oauth 16.0.0-dev.9 → 16.0.0

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.
Files changed (61) hide show
  1. package/CHANGELOG.md +98 -0
  2. package/README.md +1 -1
  3. package/esm2022/index.mjs +6 -13
  4. package/esm2022/lib/authentication-guard.mjs +20 -0
  5. package/esm2022/lib/authentication.service.mjs +131 -0
  6. package/esm2022/lib/provide-auth.mjs +20 -0
  7. package/fesm2022/rxap-oauth.mjs +135 -692
  8. package/fesm2022/rxap-oauth.mjs.map +1 -1
  9. package/index.d.ts +3 -12
  10. package/lib/authentication-guard.d.ts +2 -0
  11. package/lib/authentication.service.d.ts +25 -0
  12. package/lib/provide-auth.d.ts +4 -0
  13. package/package.json +37 -43
  14. package/theme.css +1 -1
  15. package/esm2022/lib/container/container.component.mjs +0 -38
  16. package/esm2022/lib/get-o-auth-profile.method.mjs +0 -40
  17. package/esm2022/lib/loading/loading.component.mjs +0 -13
  18. package/esm2022/lib/o-auth-extract.guard.mjs +0 -57
  19. package/esm2022/lib/o-auth-redirect.guard.mjs +0 -31
  20. package/esm2022/lib/o-auth.method.mjs +0 -116
  21. package/esm2022/lib/o-auth.module.mjs +0 -28
  22. package/esm2022/lib/o-auth.service.mjs +0 -320
  23. package/esm2022/lib/profile.resolve.mjs +0 -37
  24. package/esm2022/lib/routes.mjs +0 -26
  25. package/esm2022/lib/sign-in-with-redirect/sign-in-with-redirect.component.mjs +0 -50
  26. package/esm2022/lib/tokens.mjs +0 -17
  27. package/esm2022/single-sign-on/index.mjs +0 -8
  28. package/esm2022/single-sign-on/lib/continue/continue.component.mjs +0 -78
  29. package/esm2022/single-sign-on/lib/error/error.component.mjs +0 -46
  30. package/esm2022/single-sign-on/lib/o-auth-single-sign-on-routing.module.mjs +0 -36
  31. package/esm2022/single-sign-on/lib/o-auth-single-sign-on.guard.mjs +0 -69
  32. package/esm2022/single-sign-on/lib/o-auth-single-sign-on.service.mjs +0 -77
  33. package/esm2022/single-sign-on/lib/routes.mjs +0 -33
  34. package/esm2022/single-sign-on/lib/tokens.mjs +0 -10
  35. package/esm2022/single-sign-on/rxap-oauth-single-sign-on.mjs +0 -5
  36. package/fesm2022/rxap-oauth-single-sign-on.mjs +0 -325
  37. package/fesm2022/rxap-oauth-single-sign-on.mjs.map +0 -1
  38. package/lib/container/container.component.d.ts +0 -7
  39. package/lib/get-o-auth-profile.method.d.ts +0 -18
  40. package/lib/loading/loading.component.d.ts +0 -5
  41. package/lib/o-auth-extract.guard.d.ts +0 -11
  42. package/lib/o-auth-redirect.guard.d.ts +0 -11
  43. package/lib/o-auth.method.d.ts +0 -45
  44. package/lib/o-auth.module.d.ts +0 -12
  45. package/lib/o-auth.service.d.ts +0 -64
  46. package/lib/profile.resolve.d.ts +0 -12
  47. package/lib/routes.d.ts +0 -2
  48. package/lib/sign-in-with-redirect/sign-in-with-redirect.component.d.ts +0 -9
  49. package/lib/tokens.d.ts +0 -6
  50. package/single-sign-on/index.d.ts +0 -7
  51. package/single-sign-on/lib/continue/continue.component.d.ts +0 -17
  52. package/single-sign-on/lib/error/error.component.d.ts +0 -7
  53. package/single-sign-on/lib/o-auth-single-sign-on-routing.module.d.ts +0 -11
  54. package/single-sign-on/lib/o-auth-single-sign-on.guard.d.ts +0 -14
  55. package/single-sign-on/lib/o-auth-single-sign-on.service.d.ts +0 -13
  56. package/single-sign-on/lib/routes.d.ts +0 -2
  57. package/single-sign-on/lib/tokens.d.ts +0 -4
  58. package/single-sign-on/src/lib/continue/_continue.component.theme.scss +0 -39
  59. package/single-sign-on/src/lib/error/_error.component.theme.scss +0 -34
  60. package/src/lib/container/_container.component.theme.scss +0 -28
  61. package/src/lib/sign-in-with-redirect/_sign-in-with-redirect.component.theme.scss +0 -31
@@ -1,732 +1,175 @@
1
1
  import * as i0 from '@angular/core';
2
- import { InjectionToken, Injectable, Inject, Optional, NgModule, Component, ChangeDetectionStrategy } from '@angular/core';
3
- import * as i1 from '@angular/common/http';
4
- import { HttpClient, HttpHeaders } from '@angular/common/http';
5
- import { firstValueFrom, ReplaySubject } from 'rxjs';
6
- import * as i1$1 from '@angular/router';
7
- import { Router, RouterOutlet } from '@angular/router';
8
- import { AuthenticationEventType } from '@rxap/authentication';
9
- import { trigger, transition, style, animate, state } from '@angular/animations';
10
- import * as i1$2 from '@angular/material/progress-bar';
11
- import { MatProgressBarModule } from '@angular/material/progress-bar';
12
- import * as i4 from '@angular/material/button';
13
- import { MatButtonModule } from '@angular/material/button';
14
- import * as i3 from '@angular/material/icon';
15
- import { MatIconModule } from '@angular/material/icon';
16
- import * as i2 from '@angular/flex-layout/flex';
17
- import { FlexModule } from '@angular/flex-layout/flex';
2
+ import { Injectable, Optional, Inject, inject } from '@angular/core';
3
+ import { AuthenticationEventType, RXAP_AUTHENTICATION_ACCESS_TOKEN, RXAP_AUTHENTICATION_DEACTIVATED, RxapAuthenticationService } from '@rxap/authentication';
4
+ import { isDefined } from '@rxap/rxjs';
5
+ import * as i1 from 'angular-oauth2-oidc';
6
+ import { AUTH_CONFIG } from 'angular-oauth2-oidc';
7
+ import { JwksValidationHandler } from 'angular-oauth2-oidc-jwks';
8
+ import * as i2 from 'rxjs';
9
+ import { EMPTY, BehaviorSubject, Subject, distinctUntilChanged, startWith, firstValueFrom } from 'rxjs';
10
+ import { map } from 'rxjs/operators';
18
11
 
19
- const PROFILE_AUTH_ENDPOINT = new InjectionToken('PROFILE_AUTH_ENDPOINT');
20
- class GetOAuthProfileMethod {
21
- constructor(http, profileEndpoint = null) {
22
- this.http = http;
23
- this.profileEndpoint = profileEndpoint;
24
- }
25
- call(parameters) {
26
- const profileEndpoint = parameters.profileEndpoint ?? this.profileEndpoint;
27
- if (!profileEndpoint) {
28
- throw new Error('The profile endpoint is not defined');
29
- }
30
- return firstValueFrom(this.http
31
- .get(profileEndpoint, {
32
- headers: {
33
- Authorization: `Bearer ${parameters.accessToken}`,
34
- },
35
- withCredentials: parameters.withCredentials ?? true,
36
- }));
37
- }
38
- static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "16.1.4", ngImport: i0, type: GetOAuthProfileMethod, deps: [{ token: HttpClient }, { token: PROFILE_AUTH_ENDPOINT, optional: true }], target: i0.ɵɵFactoryTarget.Injectable }); }
39
- static { this.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "16.1.4", ngImport: i0, type: GetOAuthProfileMethod, providedIn: 'root' }); }
40
- }
41
- i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "16.1.4", ngImport: i0, type: GetOAuthProfileMethod, decorators: [{
42
- type: Injectable,
43
- args: [{ providedIn: 'root' }]
44
- }], ctorParameters: function () { return [{ type: i1.HttpClient, decorators: [{
45
- type: Inject,
46
- args: [HttpClient]
47
- }] }, { type: undefined, decorators: [{
48
- type: Optional
49
- }, {
50
- type: Inject,
51
- args: [PROFILE_AUTH_ENDPOINT]
52
- }] }]; } });
53
-
54
- function IsOAuthMethodWithRefreshTokenParameters(parameters) {
55
- // eslint-disable-next-line no-prototype-builtins
56
- return parameters.hasOwnProperty('refreshToken');
57
- }
58
- function IsOAuthMethodWithUsernamePasswordParameters(parameters) {
59
- // eslint-disable-next-line no-prototype-builtins
60
- return (!!parameters['username'] &&
61
- !!parameters['password']);
62
- }
63
- function AssertOAuthMethodWithUsernamePasswordParameters(parameters) {
64
- if (!IsOAuthMethodWithUsernamePasswordParameters(parameters)) {
65
- throw new Error('The grant type password requires the parameters username and password');
66
- }
67
- }
68
- function AssertOAuthMethodWithRefreshTokenParameters(parameters) {
69
- if (!IsOAuthMethodWithRefreshTokenParameters(parameters)) {
70
- throw new Error('The grant type refresh token requires the parameters refreshToken');
71
- }
72
- }
73
- function AssertOAuthMethodParameters(parameters) {
74
- if (!parameters.authEndpoint) {
75
- throw new Error('The authEndpoint parameter must be defined');
76
- }
77
- if (!parameters.secret) {
78
- throw new Error('The secret parameter must be defined');
79
- }
80
- if (parameters.grantType) {
81
- switch (parameters.grantType) {
82
- case 'password':
83
- AssertOAuthMethodWithUsernamePasswordParameters(parameters);
84
- break;
85
- case 'refresh_token':
86
- AssertOAuthMethodWithRefreshTokenParameters(parameters);
87
- break;
88
- default:
89
- throw new Error(`The grant type '${parameters.grantType}' is not supported`);
90
- }
91
- }
92
- else {
93
- if (!IsOAuthMethodWithRefreshTokenParameters(parameters) &&
94
- !IsOAuthMethodWithUsernamePasswordParameters(parameters)) {
95
- throw new Error('Either the refresh token or the username and password must be defined');
96
- }
97
- }
98
- }
99
- class OAuthMethod {
100
- constructor(http) {
101
- this.http = http;
102
- }
103
- async call(parameters) {
104
- AssertOAuthMethodParameters(parameters);
105
- const params = new URLSearchParams();
106
- const grantType = this.getGrantType(parameters);
107
- params.append('grant_type', grantType);
108
- switch (grantType) {
109
- case 'password':
110
- AssertOAuthMethodWithUsernamePasswordParameters(parameters);
111
- params.append('username', parameters.username);
112
- params.append('password', parameters.password);
113
- break;
114
- case 'refresh_token':
115
- AssertOAuthMethodWithRefreshTokenParameters(parameters);
116
- params.append('refresh_token', parameters.refreshToken);
117
- break;
118
- default:
119
- throw new Error('Not supported grant type');
120
- }
121
- let headers = new HttpHeaders();
122
- headers = headers.append('Content-type', 'application/x-www-form-urlencoded; charset=utf-8');
123
- if (parameters.secret && parameters.clientId) {
124
- params.append('client_id', parameters.clientId);
125
- params.append('client_secret', parameters.secret);
126
- }
127
- else {
128
- headers = headers.append('Authorization', `Basic ${parameters.secret}`);
129
- }
130
- const response = await firstValueFrom(this.http
131
- .post(parameters.authEndpoint, params.toString(), {
132
- headers,
133
- withCredentials: parameters.withCredentials ?? true,
134
- }));
135
- return {
136
- accessToken: response.access_token,
137
- refreshToken: response.refresh_token,
138
- expiresIn: response.expires_in,
139
- expiresAt: new Date(Date.now() + response.expires_in * 1000),
140
- };
141
- }
142
- getGrantType(parameters) {
143
- if (parameters.grantType) {
144
- return parameters.grantType;
145
- }
146
- if (IsOAuthMethodWithRefreshTokenParameters(parameters)) {
147
- return 'refresh_token';
148
- }
149
- if (IsOAuthMethodWithUsernamePasswordParameters(parameters)) {
150
- return 'password';
151
- }
152
- throw new Error('Could not guess the grant type');
153
- }
154
- static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "16.1.4", ngImport: i0, type: OAuthMethod, deps: [{ token: HttpClient }], target: i0.ɵɵFactoryTarget.Injectable }); }
155
- static { this.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "16.1.4", ngImport: i0, type: OAuthMethod, providedIn: 'root' }); }
156
- }
157
- i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "16.1.4", ngImport: i0, type: OAuthMethod, decorators: [{
158
- type: Injectable,
159
- args: [{ providedIn: 'root' }]
160
- }], ctorParameters: function () { return [{ type: i1.HttpClient, decorators: [{
161
- type: Inject,
162
- args: [HttpClient]
163
- }] }]; } });
164
-
165
- function DefaultRedirectSignInFactory() {
166
- return ['/', 'authentication', 'login'];
167
- }
168
- const RXAP_O_AUTH_REDIRECT_SIGN_IN = new InjectionToken('rxap/o-auth/redirect-sign-in', {
169
- providedIn: 'root',
170
- factory: DefaultRedirectSignInFactory,
171
- });
172
- const RXAP_O_AUTH_REDIRECT_SIGN_OUT = new InjectionToken('rxap/o-auth/redirect-sign-out');
173
- function DefaultRedirectUrl() {
174
- return location.origin + '/oauth';
175
- }
176
- const RXAP_O_AUTH_REDIRECT_URL = new InjectionToken('rxap/o-auth/redirect-url', {
177
- providedIn: 'root',
178
- factory: DefaultRedirectUrl,
179
- });
180
-
181
- const OAUTH_SECRET = new InjectionToken('OAUTH_SECRET');
182
- const OAUTH_AUTH_ENDPOINT = new InjectionToken('OAUTH_AUTH_ENDPOINT');
183
- const OAUTH_SSO_URL = new InjectionToken('OAUTH_SSO_URL');
184
- const OAUTH_CLIENT_ID = new InjectionToken('OAUTH_CLIENT_ID');
185
- const ACCESS_TOKEN_LOCAL_STORAGE_KEY = 'access_token';
186
- const REFRESH_TOKEN_LOCAL_STORAGE_KEY = 'refresh_token';
187
- const EXPIRES_AT_LOCAL_STORAGE_KEY = 'expires_at';
188
- const REMEMBER_LOCAL_STORAGE_KEY = 'remember';
189
- class OAuthService {
190
- constructor(oAuthMethod, getOAuthProfileMethod, router, profileEndpoint = null, authEndpoint = null, secret = null, ssoUrl = null, redirectSignOut = null, redirectUrl = null, clientId = null) {
191
- this.oAuthMethod = oAuthMethod;
192
- this.getOAuthProfileMethod = getOAuthProfileMethod;
193
- this.router = router;
194
- this.profileEndpoint = profileEndpoint;
195
- this.authEndpoint = authEndpoint;
196
- this.secret = secret;
197
- this.ssoUrl = ssoUrl;
198
- this.redirectSignOut = redirectSignOut;
199
- this.redirectUrl = redirectUrl;
200
- this.clientId = clientId;
201
- this.events$ = new ReplaySubject();
202
- this._isAuthenticated = null;
203
- }
204
- get expiresAt() {
205
- const expiresAt = this.getItem(EXPIRES_AT_LOCAL_STORAGE_KEY);
206
- if (expiresAt) {
207
- return new Date(parseInt(this.getItem(EXPIRES_AT_LOCAL_STORAGE_KEY), 10));
208
- }
209
- return null;
210
- }
211
- set expiresAt(value) {
212
- if (value) {
213
- this.setItem(EXPIRES_AT_LOCAL_STORAGE_KEY, value.getTime().toFixed(0));
214
- }
215
- else {
216
- this.removeItem(EXPIRES_AT_LOCAL_STORAGE_KEY);
217
- }
218
- }
219
- get refreshToken() {
220
- return this.getItem(REFRESH_TOKEN_LOCAL_STORAGE_KEY);
221
- }
222
- set refreshToken(value) {
223
- if (value) {
224
- this.setItem(REFRESH_TOKEN_LOCAL_STORAGE_KEY, value);
225
- }
226
- else {
227
- this.removeItem(REFRESH_TOKEN_LOCAL_STORAGE_KEY);
228
- }
229
- }
230
- get accessToken() {
231
- return this.getItem(ACCESS_TOKEN_LOCAL_STORAGE_KEY);
232
- }
233
- set accessToken(value) {
234
- if (value) {
235
- this.setItem(ACCESS_TOKEN_LOCAL_STORAGE_KEY, value);
236
- }
237
- else {
238
- this.removeItem(ACCESS_TOKEN_LOCAL_STORAGE_KEY);
239
- }
240
- }
241
- /**
242
- * The time until the access token expires in seconds
243
- */
244
- get expiresIn() {
245
- const expiresAt = this.expiresAt;
246
- if (expiresAt) {
247
- return Math.round((expiresAt.getTime() - Date.now()) / 1000);
248
- }
249
- return null;
250
- }
251
- get remember() {
252
- return !!this.getItem(REMEMBER_LOCAL_STORAGE_KEY);
253
- }
254
- set remember(value) {
255
- if (value) {
256
- this.setItem(REMEMBER_LOCAL_STORAGE_KEY, 'true');
12
+ const JONE_DOE_JWT = 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiIxMjM0NTY3ODkwIiwibmFtZSI6IkpvaG4gRG9lIiwiaWF0IjoxNTE2MjM5MDIyfQ.SflKxwRJSMeKKF2QT4fwpMeJf36POk6yJV_adQssw5c';
13
+ class AuthenticationService {
14
+ constructor(oauthService, authConfig, authenticationAccessToken, isAuthDisabled) {
15
+ this.oauthService = oauthService;
16
+ this.authConfig = authConfig;
17
+ this.authenticationAccessToken = authenticationAccessToken;
18
+ this.isAuthDisabled = isAuthDisabled;
19
+ this.events$ = EMPTY;
20
+ this.isAuthenticated$ = new BehaviorSubject(null);
21
+ /**
22
+ * Is only used when authentication is disabled to emit the events
23
+ * @private
24
+ */
25
+ this._events$ = new Subject();
26
+ if (this.isAuthDisabled) {
27
+ this.events$ = this._events$.asObservable();
28
+ this.linkEventsAndIsAuthenticated();
29
+ this._events$.next({
30
+ type: AuthenticationEventType.OnAuthSuccess,
31
+ payload: null,
32
+ });
33
+ this.authenticationAccessToken.next({
34
+ token: JONE_DOE_JWT,
35
+ valid: true,
36
+ });
257
37
  }
258
38
  else {
259
- this.removeItem(REMEMBER_LOCAL_STORAGE_KEY);
260
- }
261
- }
262
- get profile() {
263
- return this._profile;
264
- }
265
- signInWithRedirect(lastUrl) {
266
- if (!this.redirectUrl) {
267
- throw new Error('Redirect url is not defined');
268
- }
269
- location.replace(`${this.ssoUrl}?redirect=${btoa(this.redirectUrl)}&secret=${this.secret}&payload=${btoa(JSON.stringify({ lastUrl }))}`);
270
- }
271
- async isAuthenticated() {
272
- if (!this.secret) {
273
- throw new Error('The oauth secret is not defined');
274
- }
275
- if (!this.authEndpoint) {
276
- throw new Error('The oauth auth endpoint is not defined');
277
- }
278
- if (this._isAuthenticated !== null) {
279
- return this._isAuthenticated;
280
- }
281
- if (this.accessToken) {
282
- console.debug('Access token is defined: ' + this.accessToken);
283
- if (this.expiresIn && this.expiresIn > 60) {
284
- const profile = await this.getProfile();
285
- if (!profile) {
286
- console.log('profile is not defined');
287
- return (this._isAuthenticated = false);
288
- }
289
- this.authenticated({
290
- refreshToken: this.refreshToken,
291
- accessToken: this.accessToken,
292
- expiresAt: this.expiresAt ?? new Date(Date.now() + 60 * 1000),
293
- expiresIn: this.expiresIn,
294
- }, this.remember);
295
- return (this._isAuthenticated = true);
296
- }
297
- else {
298
- this.accessToken = null;
299
- this.expiresAt = null;
300
- console.warn('The access token expires soon. Use refresh token instead.');
301
- }
302
- }
303
- if (this.refreshToken) {
304
- console.debug('Refresh token is defined: ' + this.refreshToken);
305
- try {
306
- await this.signInWithRefreshToken(this.refreshToken);
307
- return (this._isAuthenticated = true);
39
+ this.init();
40
+ }
41
+ }
42
+ init() {
43
+ if (this.authConfig) {
44
+ this.oauthService.configure(this.authConfig);
45
+ }
46
+ this.events$ = this.oauthService.events.pipe(map(event => {
47
+ switch (true) {
48
+ case ['token_received', 'token_refreshed', 'silently_refreshed'].includes(event.type):
49
+ this.authenticationAccessToken.next({
50
+ token: this.oauthService.getAccessToken(),
51
+ valid: this.oauthService.hasValidAccessToken(),
52
+ });
53
+ return {
54
+ type: AuthenticationEventType.OnAuthSuccess,
55
+ payload: event,
56
+ };
57
+ case event.type.endsWith('_error') ||
58
+ ['silent_refresh_timeout', 'invalid_nonce_in_state'].includes(event.type):
59
+ this.authenticationAccessToken.next(null);
60
+ return {
61
+ type: AuthenticationEventType.OnAuthError,
62
+ payload: event,
63
+ };
64
+ case ['token_expires', 'logout', 'session_terminated'].includes(event.type):
65
+ this.authenticationAccessToken.next(null);
66
+ return {
67
+ type: AuthenticationEventType.OnLogout,
68
+ payload: event,
69
+ };
70
+ default:
71
+ console.warn('Unhandled event', event);
72
+ return null;
308
73
  }
309
- catch (e) {
310
- if (![401, 403, 400].includes(e.status)) {
311
- console.error('Could not sign in with refresh token', e.message);
312
- throw e;
313
- }
314
- console.warn('Refresh token is expired');
315
- }
316
- }
317
- console.warn('Unauthenticated');
318
- return (this._isAuthenticated = false);
319
- }
320
- async signInWithEmailAndPassword(email, password, remember) {
321
- if (!this.secret) {
322
- throw new Error('The oauth secret is not defined');
323
- }
324
- if (!this.authEndpoint) {
325
- throw new Error('The oauth auth endpoint is not defined');
326
- }
327
- const response = await this.oAuthMethod.call({
328
- username: email,
329
- password: password,
330
- authEndpoint: this.authEndpoint,
331
- secret: this.secret,
332
- clientId: this.clientId ?? undefined,
333
- }).catch(e => {
334
- this.events$.next({ type: AuthenticationEventType.OnAuthError });
335
- throw e;
74
+ }), isDefined());
75
+ this.linkEventsAndIsAuthenticated();
76
+ // Use setStorage to use sessionStorage or another implementation of the TS-type Storage
77
+ // instead of localStorage
78
+ this.oauthService.setStorage(sessionStorage);
79
+ if (this.oauthService.silentRefreshRedirectUri) {
80
+ this.oauthService.setupAutomaticSilentRefresh();
81
+ }
82
+ this.oauthService.tokenValidationHandler = new JwksValidationHandler();
83
+ this.oauthService.loadDiscoveryDocumentAndTryLogin().then(status => {
84
+ this.isAuthenticated$.next(status);
336
85
  });
337
- this.authenticated(response, remember);
338
- return response;
339
- }
340
- async getProfile() {
341
- let profile = null;
342
- if (!this.accessToken) {
343
- throw new Error('The access token is not defined');
344
- }
345
- if (this.profileEndpoint) {
346
- try {
347
- profile = await this.getOAuthProfileMethod.call({
348
- accessToken: this.accessToken,
349
- profileEndpoint: this.profileEndpoint,
350
- });
351
- }
352
- catch (e) {
353
- console.error('Could not request the user profile', e.message);
354
- }
355
- }
356
- else {
357
- console.warn('The profile endpoint is not defined!');
358
- }
359
- return (this._profile = profile);
360
86
  }
361
87
  async signOut() {
362
- this.clearStorage();
363
- this.accessToken = null;
364
- this.refreshToken = null;
365
- this.expiresAt = null;
366
- this._isAuthenticated = false;
367
- if (this.redirectSignOut) {
368
- await this.router.navigate(this.redirectSignOut);
88
+ if (this.isAuthDisabled) {
89
+ this._events$.next({
90
+ type: AuthenticationEventType.OnLogout,
91
+ payload: null,
92
+ });
369
93
  }
370
94
  else {
371
- if (!this.redirectUrl) {
372
- throw new Error('Redirect url is not defined');
373
- }
374
- location.replace(`${this.ssoUrl}?redirect=${btoa(this.redirectUrl)}&secret=${this.secret}&action=signOut`);
95
+ this.oauthService.logOut();
375
96
  }
376
- this.events$.next({ type: AuthenticationEventType.OnLogout });
377
97
  }
378
- authenticated(response, remember = this.remember ?? false) {
379
- this.accessToken = response.accessToken;
380
- this.refreshToken = response.refreshToken ?? null;
381
- this.expiresAt = response.expiresAt;
382
- console.log(`Authenticated until ${this.expiresAt.toISOString()}`);
383
- this.remember = remember;
384
- if (remember) {
385
- this.setItem(ACCESS_TOKEN_LOCAL_STORAGE_KEY, response.accessToken);
386
- if (response.refreshToken) {
387
- this.setItem(REFRESH_TOKEN_LOCAL_STORAGE_KEY, response.refreshToken);
388
- }
389
- this.setItem(REMEMBER_LOCAL_STORAGE_KEY, 'true');
390
- if (response.expiresAt) {
391
- console.log(`Authenticated until ${response.expiresAt.toISOString()}`);
392
- this.setItem(EXPIRES_AT_LOCAL_STORAGE_KEY, response.expiresAt.getTime().toFixed(0));
393
- }
98
+ signIn() {
99
+ if (this.isAuthDisabled) {
100
+ this._events$.next({
101
+ type: AuthenticationEventType.OnAuthSuccess,
102
+ payload: null,
103
+ });
394
104
  }
395
105
  else {
396
- this.removeItem(ACCESS_TOKEN_LOCAL_STORAGE_KEY);
397
- this.removeItem(REFRESH_TOKEN_LOCAL_STORAGE_KEY);
398
- this.removeItem(REMEMBER_LOCAL_STORAGE_KEY);
399
- this.removeItem(EXPIRES_AT_LOCAL_STORAGE_KEY);
106
+ this.oauthService.initLoginFlow();
400
107
  }
401
- this._isAuthenticated = true;
402
- this.events$.next({ type: AuthenticationEventType.OnAuthSuccess });
403
- }
404
- clearStorage() {
405
- this.removeItem(ACCESS_TOKEN_LOCAL_STORAGE_KEY);
406
- this.removeItem(REFRESH_TOKEN_LOCAL_STORAGE_KEY);
407
- this.removeItem(REMEMBER_LOCAL_STORAGE_KEY);
408
- this.removeItem(EXPIRES_AT_LOCAL_STORAGE_KEY);
409
- }
410
- getKey(key) {
411
- return [this.secret, key].join('__');
412
- }
413
- getItem(key) {
414
- return localStorage.getItem(this.getKey(key));
415
108
  }
416
- setItem(key, value) {
417
- localStorage.setItem(this.getKey(key), value);
109
+ linkEventsAndIsAuthenticated() {
110
+ this.events$.pipe(map(event => event ? event.type === AuthenticationEventType.OnAuthSuccess : null), distinctUntilChanged(), startWith(null)).subscribe(this.isAuthenticated$);
418
111
  }
419
- removeItem(key) {
420
- localStorage.removeItem(this.getKey(key));
421
- }
422
- async signInWithRefreshToken(refreshToken) {
423
- if (!this.secret) {
424
- throw new Error('The oauth secret is not defined');
425
- }
426
- if (!this.authEndpoint) {
427
- throw new Error('The oauth auth endpoint is not defined');
428
- }
429
- const response = await this.oAuthMethod.call({
430
- refreshToken,
431
- authEndpoint: this.authEndpoint,
432
- secret: this.secret,
433
- clientId: this.clientId ?? undefined,
434
- });
435
- this.authenticated(response);
436
- return response;
112
+ isAuthenticated() {
113
+ return firstValueFrom(this.isAuthenticated$.pipe(isDefined()));
437
114
  }
438
- static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "16.1.4", ngImport: i0, type: OAuthService, deps: [{ token: OAuthMethod }, { token: GetOAuthProfileMethod }, { token: Router }, { token: PROFILE_AUTH_ENDPOINT, optional: true }, { token: OAUTH_AUTH_ENDPOINT, optional: true }, { token: OAUTH_SECRET, optional: true }, { token: OAUTH_SSO_URL, optional: true }, { token: RXAP_O_AUTH_REDIRECT_SIGN_OUT, optional: true }, { token: RXAP_O_AUTH_REDIRECT_URL, optional: true }, { token: OAUTH_CLIENT_ID, optional: true }], target: i0.ɵɵFactoryTarget.Injectable }); }
439
- static { this.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "16.1.4", ngImport: i0, type: OAuthService, providedIn: 'root' }); }
115
+ static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "16.1.4", ngImport: i0, type: AuthenticationService, deps: [{ token: i1.OAuthService }, { token: AUTH_CONFIG, optional: true }, { token: RXAP_AUTHENTICATION_ACCESS_TOKEN }, { token: RXAP_AUTHENTICATION_DEACTIVATED }], target: i0.ɵɵFactoryTarget.Injectable }); }
116
+ static { this.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "16.1.4", ngImport: i0, type: AuthenticationService }); }
440
117
  }
441
- i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "16.1.4", ngImport: i0, type: OAuthService, decorators: [{
442
- type: Injectable,
443
- args: [{ providedIn: 'root' }]
444
- }], ctorParameters: function () { return [{ type: OAuthMethod, decorators: [{
445
- type: Inject,
446
- args: [OAuthMethod]
447
- }] }, { type: GetOAuthProfileMethod, decorators: [{
448
- type: Inject,
449
- args: [GetOAuthProfileMethod]
450
- }] }, { type: i1$1.Router, decorators: [{
451
- type: Inject,
452
- args: [Router]
453
- }] }, { type: undefined, decorators: [{
454
- type: Optional
455
- }, {
456
- type: Inject,
457
- args: [PROFILE_AUTH_ENDPOINT]
458
- }] }, { type: undefined, decorators: [{
459
- type: Optional
460
- }, {
461
- type: Inject,
462
- args: [OAUTH_AUTH_ENDPOINT]
463
- }] }, { type: undefined, decorators: [{
464
- type: Optional
465
- }, {
466
- type: Inject,
467
- args: [OAUTH_SECRET]
468
- }] }, { type: undefined, decorators: [{
469
- type: Optional
470
- }, {
471
- type: Inject,
472
- args: [OAUTH_SSO_URL]
473
- }] }, { type: undefined, decorators: [{
118
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "16.1.4", ngImport: i0, type: AuthenticationService, decorators: [{
119
+ type: Injectable
120
+ }], ctorParameters: function () { return [{ type: i1.OAuthService }, { type: i1.AuthConfig, decorators: [{
474
121
  type: Optional
475
122
  }, {
476
123
  type: Inject,
477
- args: [RXAP_O_AUTH_REDIRECT_SIGN_OUT]
478
- }] }, { type: undefined, decorators: [{
479
- type: Optional
480
- }, {
124
+ args: [AUTH_CONFIG]
125
+ }] }, { type: i2.BehaviorSubject, decorators: [{
481
126
  type: Inject,
482
- args: [RXAP_O_AUTH_REDIRECT_URL]
127
+ args: [RXAP_AUTHENTICATION_ACCESS_TOKEN]
483
128
  }] }, { type: undefined, decorators: [{
484
- type: Optional
485
- }, {
486
129
  type: Inject,
487
- args: [OAUTH_CLIENT_ID]
130
+ args: [RXAP_AUTHENTICATION_DEACTIVATED]
488
131
  }] }]; } });
489
132
 
490
- class OAuthExtractGuard {
491
- constructor(router, oAuthService) {
492
- this.router = router;
493
- this.oAuthService = oAuthService;
133
+ async function AuthenticationGuard(route, state) {
134
+ const isAuthDisabled = inject(RXAP_AUTHENTICATION_DEACTIVATED, { optional: true }) ?? false;
135
+ if (isAuthDisabled) {
136
+ console.warn('Authentication is disabled!');
137
+ return true;
494
138
  }
495
- canActivate(route) {
496
- if (route.queryParamMap.has('accessToken') &&
497
- route.queryParamMap.has('refreshToken') &&
498
- route.queryParamMap.has('expiresIn')) {
499
- // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
500
- const accessToken = route.queryParamMap.get('accessToken');
501
- // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
502
- const refreshToken = route.queryParamMap.get('refreshToken');
503
- // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
504
- const expiresIn = parseInt(route.queryParamMap.get('expiresIn'), 10);
505
- const payloadBase64 = route.queryParamMap.get('payload');
506
- const expiresAt = new Date(Date.now() + expiresIn * 1000);
507
- this.oAuthService.authenticated({
508
- accessToken,
509
- refreshToken,
510
- expiresIn,
511
- expiresAt,
512
- }, true);
513
- let redirectUrl = '/';
514
- if (payloadBase64) {
515
- try {
516
- const payload = JSON.parse(atob(payloadBase64));
517
- console.debug('sso redirect payload', payload);
518
- if (payload.lastUrl) {
519
- redirectUrl = payload.lastUrl;
520
- }
521
- }
522
- catch (e) {
523
- console.error('Could not parse redirect payload', e.message);
524
- }
525
- }
526
- return this.router.createUrlTree([redirectUrl]);
527
- }
528
- else {
529
- console.warn('Not every query parameter is defined!');
530
- }
531
- return this.router.createUrlTree([...route.url.map(url => url.path), 'redirect']);
532
- }
533
- static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "16.1.4", ngImport: i0, type: OAuthExtractGuard, deps: [{ token: i1$1.Router }, { token: OAuthService }], target: i0.ɵɵFactoryTarget.Injectable }); }
534
- static { this.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "16.1.4", ngImport: i0, type: OAuthExtractGuard, providedIn: 'root' }); }
535
- }
536
- i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "16.1.4", ngImport: i0, type: OAuthExtractGuard, decorators: [{
537
- type: Injectable,
538
- args: [{ providedIn: 'root' }]
539
- }], ctorParameters: function () { return [{ type: i1$1.Router }, { type: OAuthService }]; } });
540
-
541
- class OAuthRedirectGuard {
542
- constructor(oAuthService) {
543
- this.oAuthService = oAuthService;
544
- }
545
- async canActivate(route, state) {
546
- const isAuthenticated = await this.oAuthService.isAuthenticated();
547
- console.log(`isAuthenticated: ${isAuthenticated}`);
548
- if (isAuthenticated) {
549
- return true;
550
- }
551
- this.oAuthService.signInWithRedirect(state.url);
552
- return false;
553
- }
554
- canActivateChild(childRoute, state) {
555
- return this.canActivate(childRoute, state);
556
- }
557
- static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "16.1.4", ngImport: i0, type: OAuthRedirectGuard, deps: [{ token: OAuthService }], target: i0.ɵɵFactoryTarget.Injectable }); }
558
- static { this.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "16.1.4", ngImport: i0, type: OAuthRedirectGuard, providedIn: 'root' }); }
559
- }
560
- i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "16.1.4", ngImport: i0, type: OAuthRedirectGuard, decorators: [{
561
- type: Injectable,
562
- args: [{ providedIn: 'root' }]
563
- }], ctorParameters: function () { return [{ type: OAuthService, decorators: [{
564
- type: Inject,
565
- args: [OAuthService]
566
- }] }]; } });
567
-
568
- class OAuthModule {
569
- static forRoot(options = {}) {
570
- return {
571
- ngModule: OAuthModule,
572
- providers: [
573
- {
574
- provide: RXAP_O_AUTH_REDIRECT_SIGN_IN,
575
- useValue: options.signInPath ?? ['/', 'oauth', 'redirect'],
576
- },
577
- {
578
- provide: RXAP_O_AUTH_REDIRECT_SIGN_OUT,
579
- useValue: options.signOutPath ?? null,
580
- },
581
- ],
582
- };
139
+ const authService = inject(RxapAuthenticationService);
140
+ if (!(authService instanceof AuthenticationService)) {
141
+ throw new Error('The RxapAuthenticationService must be an instance of AuthenticationService. Ensure the ProvideAuth() function is used in the application config.');
583
142
  }
584
- static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "16.1.4", ngImport: i0, type: OAuthModule, deps: [], target: i0.ɵɵFactoryTarget.NgModule }); }
585
- static { this.ɵmod = i0.ɵɵngDeclareNgModule({ minVersion: "14.0.0", version: "16.1.4", ngImport: i0, type: OAuthModule }); }
586
- static { this.ɵinj = i0.ɵɵngDeclareInjector({ minVersion: "12.0.0", version: "16.1.4", ngImport: i0, type: OAuthModule }); }
587
- }
588
- i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "16.1.4", ngImport: i0, type: OAuthModule, decorators: [{
589
- type: NgModule,
590
- args: [{}]
591
- }] });
592
-
593
- class ContainerComponent {
594
- prepareRoute(outlet) {
595
- return outlet.isActivated ? outlet.activatedRoute : 'true';
143
+ if (await authService.isAuthenticated()) {
144
+ return true;
596
145
  }
597
- static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "16.1.4", ngImport: i0, type: ContainerComponent, deps: [], target: i0.ɵɵFactoryTarget.Component }); }
598
- static { this.ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "14.0.0", version: "16.1.4", type: ContainerComponent, isStandalone: true, selector: "rxap-container", host: { classAttribute: "rxap-container" }, ngImport: i0, template: "<div [@routeAnimations]=\"prepareRoute(outlet)\" class=\"container\">\n\n <div class=\"split mat-elevation-z3\"></div>\n\n <router-outlet #outlet=\"outlet\"></router-outlet>\n\n</div>\n", styles: [".container{height:100vh;width:100vw;display:flex;align-items:center;justify-content:center}.container .split{position:absolute;top:0;left:0;right:0;bottom:65vh;z-index:-10}\n"], dependencies: [{ kind: "directive", type: RouterOutlet, selector: "router-outlet", inputs: ["name"], outputs: ["activate", "deactivate", "attach", "detach"], exportAs: ["outlet"] }], animations: [
599
- trigger('routeAnimations', [
600
- transition(':enter', [
601
- style({ opacity: 0 }),
602
- animate('512ms', style({ opacity: 1 })),
603
- ]),
604
- transition(':leave', [
605
- style({ opacity: 1 }),
606
- animate('512ms', style({ opacity: 0 })),
607
- ]),
608
- ]),
609
- ], changeDetection: i0.ChangeDetectionStrategy.OnPush }); }
610
- }
611
- i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "16.1.4", ngImport: i0, type: ContainerComponent, decorators: [{
612
- type: Component,
613
- args: [{ selector: 'rxap-container', changeDetection: ChangeDetectionStrategy.OnPush, host: { class: 'rxap-container' }, animations: [
614
- trigger('routeAnimations', [
615
- transition(':enter', [
616
- style({ opacity: 0 }),
617
- animate('512ms', style({ opacity: 1 })),
618
- ]),
619
- transition(':leave', [
620
- style({ opacity: 1 }),
621
- animate('512ms', style({ opacity: 0 })),
622
- ]),
623
- ]),
624
- ], standalone: true, imports: [RouterOutlet], template: "<div [@routeAnimations]=\"prepareRoute(outlet)\" class=\"container\">\n\n <div class=\"split mat-elevation-z3\"></div>\n\n <router-outlet #outlet=\"outlet\"></router-outlet>\n\n</div>\n", styles: [".container{height:100vh;width:100vw;display:flex;align-items:center;justify-content:center}.container .split{position:absolute;top:0;left:0;right:0;bottom:65vh;z-index:-10}\n"] }]
625
- }] });
626
-
627
- class LoadingComponent {
628
- static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "16.1.4", ngImport: i0, type: LoadingComponent, deps: [], target: i0.ɵɵFactoryTarget.Component }); }
629
- static { this.ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "14.0.0", version: "16.1.4", type: LoadingComponent, isStandalone: true, selector: "rxap-loading", ngImport: i0, template: "<mat-progress-bar class=\"loading-bar\" mode=\"indeterminate\"></mat-progress-bar>\n", styles: [""], dependencies: [{ kind: "ngmodule", type: MatProgressBarModule }, { kind: "component", type: i1$2.MatProgressBar, selector: "mat-progress-bar", inputs: ["color", "value", "bufferValue", "mode"], outputs: ["animationEnd"], exportAs: ["matProgressBar"] }], changeDetection: i0.ChangeDetectionStrategy.OnPush }); }
146
+ authService.signIn();
147
+ return false;
630
148
  }
631
- i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "16.1.4", ngImport: i0, type: LoadingComponent, decorators: [{
632
- type: Component,
633
- args: [{ selector: 'rxap-loading', changeDetection: ChangeDetectionStrategy.OnPush, standalone: true, imports: [MatProgressBarModule], template: "<mat-progress-bar class=\"loading-bar\" mode=\"indeterminate\"></mat-progress-bar>\n" }]
634
- }] });
635
149
 
636
- class SignInWithRedirectComponent {
637
- constructor(authService) {
638
- this.authService = authService;
639
- }
640
- signIn() {
641
- this.authService.signInWithRedirect();
642
- }
643
- static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "16.1.4", ngImport: i0, type: SignInWithRedirectComponent, deps: [{ token: OAuthService }], target: i0.ɵɵFactoryTarget.Component }); }
644
- static { this.ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "14.0.0", version: "16.1.4", type: SignInWithRedirectComponent, isStandalone: true, selector: "rxap-sign-in-with-redirect", host: { classAttribute: "rxap-sign-in-with-redirect" }, ngImport: i0, template: "<div [@fadeAnimation]=\"'in'\" class=\"inner mat-elevation-z5\" fxLayout=\"column\" fxLayoutAlign=\"center center\"\n fxLayoutGap=\"32px\">\n\n <div class=\"header\" fxFlex=\"nogrow\" fxLayout=\"column\" fxLayoutAlign=\"center center\">\n\n <mat-icon class=\"avatar-icon\" color=\"primary\" fxFlex=\"nogrow\">account_circle</mat-icon>\n\n </div>\n\n <div fxFlex=\"nogrow\" fxLayout=\"row\" fxLayoutAlign=\"center center\">\n\n <div fxFlex=\"nogrow\">\n <button (click)=\"signIn()\" color=\"primary\" fxFlex=\"nogrow\" mat-raised-button>\n <span fxLayout=\"row\" fxLayoutAlign=\"start center\" fxLayoutGap=\"16px\">\n <mat-icon fxFlex=\"nogrow\">login</mat-icon>\n <span fxFlex=\"nogrow\">Sign In</span>\n </span>\n </button>\n </div>\n\n </div>\n\n</div>\n\n", styles: [".inner{padding:64px;position:relative}.inner .header .avatar-icon{width:100px;height:100px;font-size:100px}\n"], dependencies: [{ kind: "ngmodule", type: FlexModule }, { kind: "directive", type: i2.DefaultLayoutDirective, selector: " [fxLayout], [fxLayout.xs], [fxLayout.sm], [fxLayout.md], [fxLayout.lg], [fxLayout.xl], [fxLayout.lt-sm], [fxLayout.lt-md], [fxLayout.lt-lg], [fxLayout.lt-xl], [fxLayout.gt-xs], [fxLayout.gt-sm], [fxLayout.gt-md], [fxLayout.gt-lg]", inputs: ["fxLayout", "fxLayout.xs", "fxLayout.sm", "fxLayout.md", "fxLayout.lg", "fxLayout.xl", "fxLayout.lt-sm", "fxLayout.lt-md", "fxLayout.lt-lg", "fxLayout.lt-xl", "fxLayout.gt-xs", "fxLayout.gt-sm", "fxLayout.gt-md", "fxLayout.gt-lg"] }, { kind: "directive", type: i2.DefaultLayoutGapDirective, selector: " [fxLayoutGap], [fxLayoutGap.xs], [fxLayoutGap.sm], [fxLayoutGap.md], [fxLayoutGap.lg], [fxLayoutGap.xl], [fxLayoutGap.lt-sm], [fxLayoutGap.lt-md], [fxLayoutGap.lt-lg], [fxLayoutGap.lt-xl], [fxLayoutGap.gt-xs], [fxLayoutGap.gt-sm], [fxLayoutGap.gt-md], [fxLayoutGap.gt-lg]", inputs: ["fxLayoutGap", "fxLayoutGap.xs", "fxLayoutGap.sm", "fxLayoutGap.md", "fxLayoutGap.lg", "fxLayoutGap.xl", "fxLayoutGap.lt-sm", "fxLayoutGap.lt-md", "fxLayoutGap.lt-lg", "fxLayoutGap.lt-xl", "fxLayoutGap.gt-xs", "fxLayoutGap.gt-sm", "fxLayoutGap.gt-md", "fxLayoutGap.gt-lg"] }, { kind: "directive", type: i2.DefaultLayoutAlignDirective, selector: " [fxLayoutAlign], [fxLayoutAlign.xs], [fxLayoutAlign.sm], [fxLayoutAlign.md], [fxLayoutAlign.lg], [fxLayoutAlign.xl], [fxLayoutAlign.lt-sm], [fxLayoutAlign.lt-md], [fxLayoutAlign.lt-lg], [fxLayoutAlign.lt-xl], [fxLayoutAlign.gt-xs], [fxLayoutAlign.gt-sm], [fxLayoutAlign.gt-md], [fxLayoutAlign.gt-lg]", inputs: ["fxLayoutAlign", "fxLayoutAlign.xs", "fxLayoutAlign.sm", "fxLayoutAlign.md", "fxLayoutAlign.lg", "fxLayoutAlign.xl", "fxLayoutAlign.lt-sm", "fxLayoutAlign.lt-md", "fxLayoutAlign.lt-lg", "fxLayoutAlign.lt-xl", "fxLayoutAlign.gt-xs", "fxLayoutAlign.gt-sm", "fxLayoutAlign.gt-md", "fxLayoutAlign.gt-lg"] }, { kind: "directive", type: i2.DefaultFlexDirective, selector: " [fxFlex], [fxFlex.xs], [fxFlex.sm], [fxFlex.md], [fxFlex.lg], [fxFlex.xl], [fxFlex.lt-sm], [fxFlex.lt-md], [fxFlex.lt-lg], [fxFlex.lt-xl], [fxFlex.gt-xs], [fxFlex.gt-sm], [fxFlex.gt-md], [fxFlex.gt-lg]", inputs: ["fxFlex", "fxFlex.xs", "fxFlex.sm", "fxFlex.md", "fxFlex.lg", "fxFlex.xl", "fxFlex.lt-sm", "fxFlex.lt-md", "fxFlex.lt-lg", "fxFlex.lt-xl", "fxFlex.gt-xs", "fxFlex.gt-sm", "fxFlex.gt-md", "fxFlex.gt-lg"] }, { kind: "ngmodule", type: MatIconModule }, { kind: "component", type: i3.MatIcon, selector: "mat-icon", inputs: ["color", "inline", "svgIcon", "fontSet", "fontIcon"], exportAs: ["matIcon"] }, { kind: "ngmodule", type: MatButtonModule }, { kind: "component", type: i4.MatButton, selector: " button[mat-button], button[mat-raised-button], button[mat-flat-button], button[mat-stroked-button] ", inputs: ["disabled", "disableRipple", "color"], exportAs: ["matButton"] }], animations: [
645
- trigger('fadeAnimation', [
646
- // the "in" style determines the "resting" state of the element when it is visible.
647
- state('in', style({ opacity: 1 })),
648
- // fade in when created. this could also be written as transition('void => *')
649
- transition(':enter', [
650
- style({ opacity: 0 }),
651
- animate(300),
652
- ]),
653
- // fade out when destroyed. this could also be written as transition('void => *')
654
- transition(':leave', animate(300, style({ opacity: 0 }))),
655
- ]),
656
- ], changeDetection: i0.ChangeDetectionStrategy.OnPush }); }
150
+ function ProvideAuth(...withConfigs) {
151
+ return [
152
+ AuthenticationService,
153
+ {
154
+ provide: RxapAuthenticationService,
155
+ useExisting: AuthenticationService,
156
+ },
157
+ ...withConfigs.flat(),
158
+ ];
159
+ }
160
+ function withAuthConfig(config) {
161
+ return {
162
+ provide: AUTH_CONFIG,
163
+ useValue: config,
164
+ };
657
165
  }
658
- i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "16.1.4", ngImport: i0, type: SignInWithRedirectComponent, decorators: [{
659
- type: Component,
660
- args: [{ selector: 'rxap-sign-in-with-redirect', changeDetection: ChangeDetectionStrategy.OnPush, host: { class: 'rxap-sign-in-with-redirect' }, animations: [
661
- trigger('fadeAnimation', [
662
- // the "in" style determines the "resting" state of the element when it is visible.
663
- state('in', style({ opacity: 1 })),
664
- // fade in when created. this could also be written as transition('void => *')
665
- transition(':enter', [
666
- style({ opacity: 0 }),
667
- animate(300),
668
- ]),
669
- // fade out when destroyed. this could also be written as transition('void => *')
670
- transition(':leave', animate(300, style({ opacity: 0 }))),
671
- ]),
672
- ], standalone: true, imports: [FlexModule, MatIconModule, MatButtonModule], template: "<div [@fadeAnimation]=\"'in'\" class=\"inner mat-elevation-z5\" fxLayout=\"column\" fxLayoutAlign=\"center center\"\n fxLayoutGap=\"32px\">\n\n <div class=\"header\" fxFlex=\"nogrow\" fxLayout=\"column\" fxLayoutAlign=\"center center\">\n\n <mat-icon class=\"avatar-icon\" color=\"primary\" fxFlex=\"nogrow\">account_circle</mat-icon>\n\n </div>\n\n <div fxFlex=\"nogrow\" fxLayout=\"row\" fxLayoutAlign=\"center center\">\n\n <div fxFlex=\"nogrow\">\n <button (click)=\"signIn()\" color=\"primary\" fxFlex=\"nogrow\" mat-raised-button>\n <span fxLayout=\"row\" fxLayoutAlign=\"start center\" fxLayoutGap=\"16px\">\n <mat-icon fxFlex=\"nogrow\">login</mat-icon>\n <span fxFlex=\"nogrow\">Sign In</span>\n </span>\n </button>\n </div>\n\n </div>\n\n</div>\n\n", styles: [".inner{padding:64px;position:relative}.inner .header .avatar-icon{width:100px;height:100px;font-size:100px}\n"] }]
673
- }], ctorParameters: function () { return [{ type: OAuthService }]; } });
674
-
675
- const RXAP_O_AUTH_ROUTES = [
676
- {
677
- path: 'oauth',
678
- component: ContainerComponent,
679
- children: [
680
- {
681
- path: 'redirect',
682
- component: SignInWithRedirectComponent,
683
- },
684
- {
685
- canActivate: [OAuthExtractGuard],
686
- path: '',
687
- component: LoadingComponent,
688
- },
689
- {
690
- path: '**',
691
- redirectTo: '',
692
- },
693
- ],
694
- },
695
- ];
696
166
 
697
- class ProfileResolve {
698
- constructor(oAuthService, router, redirectLogin) {
699
- this.oAuthService = oAuthService;
700
- this.router = router;
701
- this.redirectLogin = redirectLogin;
702
- }
703
- async resolve() {
704
- const profile = await this.oAuthService.getProfile();
705
- if (!profile) {
706
- await this.router.navigate(this.redirectLogin);
707
- }
708
- return profile;
709
- }
710
- static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "16.1.4", ngImport: i0, type: ProfileResolve, deps: [{ token: OAuthService }, { token: Router }, { token: RXAP_O_AUTH_REDIRECT_SIGN_IN }], target: i0.ɵɵFactoryTarget.Injectable }); }
711
- static { this.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "16.1.4", ngImport: i0, type: ProfileResolve, providedIn: 'root' }); }
712
- }
713
- i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "16.1.4", ngImport: i0, type: ProfileResolve, decorators: [{
714
- type: Injectable,
715
- args: [{ providedIn: 'root' }]
716
- }], ctorParameters: function () { return [{ type: OAuthService, decorators: [{
717
- type: Inject,
718
- args: [OAuthService]
719
- }] }, { type: i1$1.Router, decorators: [{
720
- type: Inject,
721
- args: [Router]
722
- }] }, { type: undefined, decorators: [{
723
- type: Inject,
724
- args: [RXAP_O_AUTH_REDIRECT_SIGN_IN]
725
- }] }]; } });
167
+ // region
168
+ // endregion
726
169
 
727
170
  /**
728
171
  * Generated bundle index. Do not edit.
729
172
  */
730
173
 
731
- export { ACCESS_TOKEN_LOCAL_STORAGE_KEY, AssertOAuthMethodParameters, AssertOAuthMethodWithRefreshTokenParameters, AssertOAuthMethodWithUsernamePasswordParameters, ContainerComponent, DefaultRedirectSignInFactory, DefaultRedirectUrl, EXPIRES_AT_LOCAL_STORAGE_KEY, GetOAuthProfileMethod, IsOAuthMethodWithRefreshTokenParameters, IsOAuthMethodWithUsernamePasswordParameters, LoadingComponent, OAUTH_AUTH_ENDPOINT, OAUTH_CLIENT_ID, OAUTH_SECRET, OAUTH_SSO_URL, OAuthExtractGuard, OAuthMethod, OAuthModule, OAuthRedirectGuard, OAuthService, PROFILE_AUTH_ENDPOINT, ProfileResolve, REFRESH_TOKEN_LOCAL_STORAGE_KEY, REMEMBER_LOCAL_STORAGE_KEY, RXAP_O_AUTH_REDIRECT_SIGN_IN, RXAP_O_AUTH_REDIRECT_SIGN_OUT, RXAP_O_AUTH_REDIRECT_URL, RXAP_O_AUTH_ROUTES, SignInWithRedirectComponent };
174
+ export { AuthenticationGuard, AuthenticationService, ProvideAuth, withAuthConfig };
732
175
  //# sourceMappingURL=rxap-oauth.mjs.map