@meshmakers/shared-auth 0.0.0-0 → 2.0.2211-13005

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.
@@ -8,261 +8,261 @@ import * as i2 from '@angular/common';
8
8
  import { CommonModule } from '@angular/common';
9
9
  import { HttpClientModule } from '@angular/common/http';
10
10
 
11
- class AuthorizeOptions {
12
- }
13
- class AuthorizeService {
14
- constructor(authorizeOptions, oauthService) {
15
- this.authorizeOptions = authorizeOptions;
16
- this.oauthService = oauthService;
17
- this.isAuthenticated = new BehaviorSubject(false);
18
- this.isAdmin = new BehaviorSubject(false);
19
- this.authority = new BehaviorSubject(null);
20
- this.accessToken = new BehaviorSubject(null);
21
- this.user = new BehaviorSubject(null);
22
- console.debug("AuthorizeService::created");
23
- this.getUser().subscribe(s => {
24
- this.isAuthenticated.next(!!s);
25
- this.isAdmin.next(!!s && s.role === "Administrators");
26
- });
27
- }
28
- getServiceUris() {
29
- return this.authorizeOptions.wellKnownServiceUris;
30
- }
31
- getAuthority() {
32
- return this.authority;
33
- }
34
- getIsAuthenticated() {
35
- return this.isAuthenticated;
36
- }
37
- getIsAdmin() {
38
- return this.isAdmin;
39
- }
40
- getAccessToken() {
41
- return this.accessToken;
42
- }
43
- getUser() {
44
- return this.user;
45
- }
46
- login() {
47
- this.oauthService.initImplicitFlow();
48
- }
49
- logout() {
50
- this.oauthService.logOut(false);
51
- }
52
- initialize() {
53
- console.debug("AuthorizeService::initialize::started");
54
- const config = {
55
- responseType: 'code',
56
- issuer: this.authorizeOptions.issuer,
57
- redirectUri: this.authorizeOptions.redirectUri,
58
- postLogoutRedirectUri: this.authorizeOptions.postLogoutRedirectUri,
59
- clientId: this.authorizeOptions.clientId,
60
- scope: this.authorizeOptions.scope,
61
- showDebugInformation: this.authorizeOptions.showDebugInformation,
62
- sessionChecksEnabled: this.authorizeOptions.sessionChecksEnabled
63
- };
64
- this.oauthService.configure(config);
65
- this.oauthService.setStorage(localStorage);
66
- this.oauthService.loadDiscoveryDocumentAndTryLogin();
67
- this.oauthService.setupAutomaticSilentRefresh();
68
- this.oauthService.events.subscribe(e => {
69
- // tslint:disable-next-line:no-console
70
- console.debug('oauth/oidc event', e);
71
- });
72
- this.oauthService.events
73
- .pipe(filter(e => e.type === 'session_terminated'))
74
- .subscribe(e => {
75
- // tslint:disable-next-line:no-console
76
- console.debug('Your session has been terminated!');
77
- });
78
- this.oauthService.events
79
- .pipe(filter(e => e.type === 'token_received'))
80
- .subscribe(e => {
81
- this.loadUser();
82
- });
83
- this.oauthService.events
84
- .pipe(filter(e => e.type === 'logout'))
85
- .subscribe(e => {
86
- this.accessToken.next(null);
87
- this.user.next(null);
88
- });
89
- if (this.oauthService.hasValidAccessToken()) {
90
- this.loadUser();
91
- }
92
- this.authority.next(this.authorizeOptions.issuer);
93
- console.debug("AuthorizeService::initialize::done");
94
- }
95
- loadUser() {
96
- const claims = this.oauthService.getIdentityClaims();
97
- if (!claims) {
98
- console.error("claims where null when loading identity claims");
99
- return;
100
- }
101
- const user = claims;
102
- const accessToken = this.oauthService.getAccessToken();
103
- this.user.next(user);
104
- this.accessToken.next(accessToken);
105
- }
106
- }
107
- AuthorizeService.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "14.2.2", ngImport: i0, type: AuthorizeService, deps: [{ token: AuthorizeOptions }, { token: i1.OAuthService }], target: i0.ɵɵFactoryTarget.Injectable });
108
- AuthorizeService.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "14.2.2", ngImport: i0, type: AuthorizeService });
109
- i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "14.2.2", ngImport: i0, type: AuthorizeService, decorators: [{
110
- type: Injectable
111
- }], ctorParameters: function () {
112
- return [{ type: AuthorizeOptions, decorators: [{
113
- type: Inject,
114
- args: [AuthorizeOptions]
115
- }] }, { type: i1.OAuthService }];
11
+ class AuthorizeOptions {
12
+ }
13
+ class AuthorizeService {
14
+ constructor(authorizeOptions, oauthService) {
15
+ this.authorizeOptions = authorizeOptions;
16
+ this.oauthService = oauthService;
17
+ this.isAuthenticated = new BehaviorSubject(false);
18
+ this.isAdmin = new BehaviorSubject(false);
19
+ this.authority = new BehaviorSubject(null);
20
+ this.accessToken = new BehaviorSubject(null);
21
+ this.user = new BehaviorSubject(null);
22
+ console.debug("AuthorizeService::created");
23
+ this.getUser().subscribe(s => {
24
+ this.isAuthenticated.next(!!s);
25
+ this.isAdmin.next(!!s && s.role === "Administrators");
26
+ });
27
+ }
28
+ getServiceUris() {
29
+ return this.authorizeOptions.wellKnownServiceUris;
30
+ }
31
+ getAuthority() {
32
+ return this.authority;
33
+ }
34
+ getIsAuthenticated() {
35
+ return this.isAuthenticated;
36
+ }
37
+ getIsAdmin() {
38
+ return this.isAdmin;
39
+ }
40
+ getAccessToken() {
41
+ return this.accessToken;
42
+ }
43
+ getUser() {
44
+ return this.user;
45
+ }
46
+ login() {
47
+ this.oauthService.initImplicitFlow();
48
+ }
49
+ logout() {
50
+ this.oauthService.logOut(false);
51
+ }
52
+ initialize() {
53
+ console.debug("AuthorizeService::initialize::started");
54
+ const config = {
55
+ responseType: 'code',
56
+ issuer: this.authorizeOptions.issuer,
57
+ redirectUri: this.authorizeOptions.redirectUri,
58
+ postLogoutRedirectUri: this.authorizeOptions.postLogoutRedirectUri,
59
+ clientId: this.authorizeOptions.clientId,
60
+ scope: this.authorizeOptions.scope,
61
+ showDebugInformation: this.authorizeOptions.showDebugInformation,
62
+ sessionChecksEnabled: this.authorizeOptions.sessionChecksEnabled
63
+ };
64
+ this.oauthService.configure(config);
65
+ this.oauthService.setStorage(localStorage);
66
+ this.oauthService.loadDiscoveryDocumentAndTryLogin();
67
+ this.oauthService.setupAutomaticSilentRefresh();
68
+ this.oauthService.events.subscribe(e => {
69
+ // tslint:disable-next-line:no-console
70
+ console.debug('oauth/oidc event', e);
71
+ });
72
+ this.oauthService.events
73
+ .pipe(filter(e => e.type === 'session_terminated'))
74
+ .subscribe(e => {
75
+ // tslint:disable-next-line:no-console
76
+ console.debug('Your session has been terminated!');
77
+ });
78
+ this.oauthService.events
79
+ .pipe(filter(e => e.type === 'token_received'))
80
+ .subscribe(e => {
81
+ this.loadUser();
82
+ });
83
+ this.oauthService.events
84
+ .pipe(filter(e => e.type === 'logout'))
85
+ .subscribe(e => {
86
+ this.accessToken.next(null);
87
+ this.user.next(null);
88
+ });
89
+ if (this.oauthService.hasValidAccessToken()) {
90
+ this.loadUser();
91
+ }
92
+ this.authority.next(this.authorizeOptions.issuer);
93
+ console.debug("AuthorizeService::initialize::done");
94
+ }
95
+ loadUser() {
96
+ const claims = this.oauthService.getIdentityClaims();
97
+ if (!claims) {
98
+ console.error("claims where null when loading identity claims");
99
+ return;
100
+ }
101
+ const user = claims;
102
+ const accessToken = this.oauthService.getAccessToken();
103
+ this.user.next(user);
104
+ this.accessToken.next(accessToken);
105
+ }
106
+ }
107
+ AuthorizeService.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "14.2.2", ngImport: i0, type: AuthorizeService, deps: [{ token: AuthorizeOptions }, { token: i1.OAuthService }], target: i0.ɵɵFactoryTarget.Injectable });
108
+ AuthorizeService.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "14.2.2", ngImport: i0, type: AuthorizeService });
109
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "14.2.2", ngImport: i0, type: AuthorizeService, decorators: [{
110
+ type: Injectable
111
+ }], ctorParameters: function () {
112
+ return [{ type: AuthorizeOptions, decorators: [{
113
+ type: Inject,
114
+ args: [AuthorizeOptions]
115
+ }] }, { type: i1.OAuthService }];
116
116
  } });
117
117
 
118
- class LoginMenuComponent {
119
- constructor(authorizeService) {
120
- this.authorizeService = authorizeService;
121
- }
122
- ngOnInit() {
123
- const isIFrame = window.self !== window.top;
124
- console.log("app-login-menu::created");
125
- this.isAuthenticated = this.authorizeService.getIsAuthenticated();
126
- this.userName = this.authorizeService.getUser().pipe(map(u => u && u.name));
127
- this.isAdmin = this.authorizeService.getIsAdmin();
128
- this.isAuthenticated.subscribe(x => {
129
- console.log(`isAuthenticated changed to ${x} (iframe ${isIFrame})`);
130
- });
131
- }
132
- login() {
133
- this.authorizeService.login();
134
- }
135
- logout() {
136
- this.authorizeService.logout();
137
- }
138
- register() {
139
- }
140
- }
141
- LoginMenuComponent.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "14.2.2", ngImport: i0, type: LoginMenuComponent, deps: [{ token: AuthorizeService }], target: i0.ɵɵFactoryTarget.Component });
142
- LoginMenuComponent.ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "14.0.0", version: "14.2.2", type: LoginMenuComponent, selector: "app-login-menu", ngImport: i0, template: "<ul *ngIf=\"isAuthenticated | async\" class=\"navbar-nav\">\n <li class=\"nav-item dropdown\">\n <a aria-expanded=\"false\" aria-haspopup=\"true\" class=\"nav-link dropdown-toggle\" data-toggle=\"dropdown\" href=\"#\"\n id=\"navbarDropdownLogin\" role=\"button\">\n {{ userName | async }} <b class=\"caret\"></b>\n </a>\n <div aria-labelledby=\"navbarDropdown\" class=\"dropdown-menu\">\n <!--<a class=\"dropdown-item\" asp-action=\"Index\" asp-area=\"Authentication\" asp-controller=\"Grants\">Client Application Access</a>-->\n <!--<a class=\"dropdown-item\" [routerLink]='[\"/authentication/profile\"]' title=\"Manage\">Manage</a>-->\n <!--<a class=\"dropdown-item\" asp-action=\"Index\" asp-area=\"Authentication\" asp-controller=\"Diagnostics\">Diagnostics</a>-->\n <div class=\"dropdown-divider\"></div>\n <a (click)='logout()' class=\"dropdown-item\" routerLink=\"\" title=\"Logout\">Logout</a>\n </div>\n </li>\n</ul>\n<ul *ngIf=\"!(isAuthenticated | async)\" class=\"navbar-nav\">\n <li class=\"nav-item\">\n <a (click)='register()' class=\"nav-link\" routerLink=\"\">Register</a>\n </li>\n <li class=\"nav-item\">\n <a (click)='login()' class=\"nav-link\" routerLink=\"\">Login</a>\n </li>\n</ul>\n", styles: [""], dependencies: [{ kind: "directive", type: i2.NgIf, selector: "[ngIf]", inputs: ["ngIf", "ngIfThen", "ngIfElse"] }, { kind: "pipe", type: i2.AsyncPipe, name: "async" }] });
143
- i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "14.2.2", ngImport: i0, type: LoginMenuComponent, decorators: [{
144
- type: Component,
145
- args: [{ selector: 'app-login-menu', template: "<ul *ngIf=\"isAuthenticated | async\" class=\"navbar-nav\">\n <li class=\"nav-item dropdown\">\n <a aria-expanded=\"false\" aria-haspopup=\"true\" class=\"nav-link dropdown-toggle\" data-toggle=\"dropdown\" href=\"#\"\n id=\"navbarDropdownLogin\" role=\"button\">\n {{ userName | async }} <b class=\"caret\"></b>\n </a>\n <div aria-labelledby=\"navbarDropdown\" class=\"dropdown-menu\">\n <!--<a class=\"dropdown-item\" asp-action=\"Index\" asp-area=\"Authentication\" asp-controller=\"Grants\">Client Application Access</a>-->\n <!--<a class=\"dropdown-item\" [routerLink]='[\"/authentication/profile\"]' title=\"Manage\">Manage</a>-->\n <!--<a class=\"dropdown-item\" asp-action=\"Index\" asp-area=\"Authentication\" asp-controller=\"Diagnostics\">Diagnostics</a>-->\n <div class=\"dropdown-divider\"></div>\n <a (click)='logout()' class=\"dropdown-item\" routerLink=\"\" title=\"Logout\">Logout</a>\n </div>\n </li>\n</ul>\n<ul *ngIf=\"!(isAuthenticated | async)\" class=\"navbar-nav\">\n <li class=\"nav-item\">\n <a (click)='register()' class=\"nav-link\" routerLink=\"\">Register</a>\n </li>\n <li class=\"nav-item\">\n <a (click)='login()' class=\"nav-link\" routerLink=\"\">Login</a>\n </li>\n</ul>\n" }]
118
+ class LoginMenuComponent {
119
+ constructor(authorizeService) {
120
+ this.authorizeService = authorizeService;
121
+ }
122
+ ngOnInit() {
123
+ const isIFrame = window.self !== window.top;
124
+ console.log("app-login-menu::created");
125
+ this.isAuthenticated = this.authorizeService.getIsAuthenticated();
126
+ this.userName = this.authorizeService.getUser().pipe(map(u => u && u.name));
127
+ this.isAdmin = this.authorizeService.getIsAdmin();
128
+ this.isAuthenticated.subscribe(x => {
129
+ console.log(`isAuthenticated changed to ${x} (iframe ${isIFrame})`);
130
+ });
131
+ }
132
+ login() {
133
+ this.authorizeService.login();
134
+ }
135
+ logout() {
136
+ this.authorizeService.logout();
137
+ }
138
+ register() {
139
+ }
140
+ }
141
+ LoginMenuComponent.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "14.2.2", ngImport: i0, type: LoginMenuComponent, deps: [{ token: AuthorizeService }], target: i0.ɵɵFactoryTarget.Component });
142
+ LoginMenuComponent.ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "14.0.0", version: "14.2.2", type: LoginMenuComponent, selector: "app-login-menu", ngImport: i0, template: "<ul *ngIf=\"isAuthenticated | async\" class=\"navbar-nav\">\r\n <li class=\"nav-item dropdown\">\r\n <a aria-expanded=\"false\" aria-haspopup=\"true\" class=\"nav-link dropdown-toggle\" data-toggle=\"dropdown\" href=\"#\"\r\n id=\"navbarDropdownLogin\" role=\"button\">\r\n {{ userName | async }} <b class=\"caret\"></b>\r\n </a>\r\n <div aria-labelledby=\"navbarDropdown\" class=\"dropdown-menu\">\r\n <!--<a class=\"dropdown-item\" asp-action=\"Index\" asp-area=\"Authentication\" asp-controller=\"Grants\">Client Application Access</a>-->\r\n <!--<a class=\"dropdown-item\" [routerLink]='[\"/authentication/profile\"]' title=\"Manage\">Manage</a>-->\r\n <!--<a class=\"dropdown-item\" asp-action=\"Index\" asp-area=\"Authentication\" asp-controller=\"Diagnostics\">Diagnostics</a>-->\r\n <div class=\"dropdown-divider\"></div>\r\n <a (click)='logout()' class=\"dropdown-item\" routerLink=\"\" title=\"Logout\">Logout</a>\r\n </div>\r\n </li>\r\n</ul>\r\n<ul *ngIf=\"!(isAuthenticated | async)\" class=\"navbar-nav\">\r\n <li class=\"nav-item\">\r\n <a (click)='register()' class=\"nav-link\" routerLink=\"\">Register</a>\r\n </li>\r\n <li class=\"nav-item\">\r\n <a (click)='login()' class=\"nav-link\" routerLink=\"\">Login</a>\r\n </li>\r\n</ul>\r\n", styles: [""], dependencies: [{ kind: "directive", type: i2.NgIf, selector: "[ngIf]", inputs: ["ngIf", "ngIfThen", "ngIfElse"] }, { kind: "pipe", type: i2.AsyncPipe, name: "async" }] });
143
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "14.2.2", ngImport: i0, type: LoginMenuComponent, decorators: [{
144
+ type: Component,
145
+ args: [{ selector: 'app-login-menu', template: "<ul *ngIf=\"isAuthenticated | async\" class=\"navbar-nav\">\r\n <li class=\"nav-item dropdown\">\r\n <a aria-expanded=\"false\" aria-haspopup=\"true\" class=\"nav-link dropdown-toggle\" data-toggle=\"dropdown\" href=\"#\"\r\n id=\"navbarDropdownLogin\" role=\"button\">\r\n {{ userName | async }} <b class=\"caret\"></b>\r\n </a>\r\n <div aria-labelledby=\"navbarDropdown\" class=\"dropdown-menu\">\r\n <!--<a class=\"dropdown-item\" asp-action=\"Index\" asp-area=\"Authentication\" asp-controller=\"Grants\">Client Application Access</a>-->\r\n <!--<a class=\"dropdown-item\" [routerLink]='[\"/authentication/profile\"]' title=\"Manage\">Manage</a>-->\r\n <!--<a class=\"dropdown-item\" asp-action=\"Index\" asp-area=\"Authentication\" asp-controller=\"Diagnostics\">Diagnostics</a>-->\r\n <div class=\"dropdown-divider\"></div>\r\n <a (click)='logout()' class=\"dropdown-item\" routerLink=\"\" title=\"Logout\">Logout</a>\r\n </div>\r\n </li>\r\n</ul>\r\n<ul *ngIf=\"!(isAuthenticated | async)\" class=\"navbar-nav\">\r\n <li class=\"nav-item\">\r\n <a (click)='register()' class=\"nav-link\" routerLink=\"\">Register</a>\r\n </li>\r\n <li class=\"nav-item\">\r\n <a (click)='login()' class=\"nav-link\" routerLink=\"\">Login</a>\r\n </li>\r\n</ul>\r\n" }]
146
146
  }], ctorParameters: function () { return [{ type: AuthorizeService }]; } });
147
147
 
148
- class AuthorizeGuard {
149
- constructor(authorize) {
150
- this.authorize = authorize;
151
- }
152
- canActivate(_next, state) {
153
- return this.authorize.getIsAuthenticated()
154
- .pipe(tap(isAuthenticated => this.handleAuthorization(isAuthenticated)));
155
- }
156
- handleAuthorization(isAuthenticated) {
157
- if (!isAuthenticated) {
158
- this.authorize.login();
159
- }
160
- }
161
- }
162
- AuthorizeGuard.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "14.2.2", ngImport: i0, type: AuthorizeGuard, deps: [{ token: AuthorizeService }], target: i0.ɵɵFactoryTarget.Injectable });
163
- AuthorizeGuard.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "14.2.2", ngImport: i0, type: AuthorizeGuard });
164
- i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "14.2.2", ngImport: i0, type: AuthorizeGuard, decorators: [{
165
- type: Injectable
148
+ class AuthorizeGuard {
149
+ constructor(authorize) {
150
+ this.authorize = authorize;
151
+ }
152
+ canActivate(_next, state) {
153
+ return this.authorize.getIsAuthenticated()
154
+ .pipe(tap(isAuthenticated => this.handleAuthorization(isAuthenticated)));
155
+ }
156
+ handleAuthorization(isAuthenticated) {
157
+ if (!isAuthenticated) {
158
+ this.authorize.login();
159
+ }
160
+ }
161
+ }
162
+ AuthorizeGuard.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "14.2.2", ngImport: i0, type: AuthorizeGuard, deps: [{ token: AuthorizeService }], target: i0.ɵɵFactoryTarget.Injectable });
163
+ AuthorizeGuard.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "14.2.2", ngImport: i0, type: AuthorizeGuard });
164
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "14.2.2", ngImport: i0, type: AuthorizeGuard, decorators: [{
165
+ type: Injectable
166
166
  }], ctorParameters: function () { return [{ type: AuthorizeService }]; } });
167
167
 
168
- class SharedAuthModule {
169
- static forRoot(authorizeOptions) {
170
- return {
171
- ngModule: SharedAuthModule,
172
- providers: [
173
- {
174
- provide: AuthorizeOptions,
175
- useValue: authorizeOptions
176
- },
177
- AuthorizeService,
178
- AuthorizeGuard
179
- ]
180
- };
181
- }
182
- }
183
- SharedAuthModule.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "14.2.2", ngImport: i0, type: SharedAuthModule, deps: [], target: i0.ɵɵFactoryTarget.NgModule });
184
- SharedAuthModule.ɵmod = i0.ɵɵngDeclareNgModule({ minVersion: "14.0.0", version: "14.2.2", ngImport: i0, type: SharedAuthModule, declarations: [LoginMenuComponent], imports: [CommonModule,
185
- HttpClientModule, i1.OAuthModule], exports: [LoginMenuComponent] });
186
- SharedAuthModule.ɵinj = i0.ɵɵngDeclareInjector({ minVersion: "12.0.0", version: "14.2.2", ngImport: i0, type: SharedAuthModule, imports: [CommonModule,
187
- HttpClientModule,
188
- OAuthModule.forRoot()] });
189
- i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "14.2.2", ngImport: i0, type: SharedAuthModule, decorators: [{
190
- type: NgModule,
191
- args: [{
192
- declarations: [LoginMenuComponent],
193
- exports: [LoginMenuComponent],
194
- providers: [],
195
- imports: [
196
- CommonModule,
197
- HttpClientModule,
198
- OAuthModule.forRoot()
199
- ]
200
- }]
168
+ class SharedAuthModule {
169
+ static forRoot(authorizeOptions) {
170
+ return {
171
+ ngModule: SharedAuthModule,
172
+ providers: [
173
+ {
174
+ provide: AuthorizeOptions,
175
+ useValue: authorizeOptions
176
+ },
177
+ AuthorizeService,
178
+ AuthorizeGuard
179
+ ]
180
+ };
181
+ }
182
+ }
183
+ SharedAuthModule.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "14.2.2", ngImport: i0, type: SharedAuthModule, deps: [], target: i0.ɵɵFactoryTarget.NgModule });
184
+ SharedAuthModule.ɵmod = i0.ɵɵngDeclareNgModule({ minVersion: "14.0.0", version: "14.2.2", ngImport: i0, type: SharedAuthModule, declarations: [LoginMenuComponent], imports: [CommonModule,
185
+ HttpClientModule, i1.OAuthModule], exports: [LoginMenuComponent] });
186
+ SharedAuthModule.ɵinj = i0.ɵɵngDeclareInjector({ minVersion: "12.0.0", version: "14.2.2", ngImport: i0, type: SharedAuthModule, imports: [CommonModule,
187
+ HttpClientModule,
188
+ OAuthModule.forRoot()] });
189
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "14.2.2", ngImport: i0, type: SharedAuthModule, decorators: [{
190
+ type: NgModule,
191
+ args: [{
192
+ declarations: [LoginMenuComponent],
193
+ exports: [LoginMenuComponent],
194
+ providers: [],
195
+ imports: [
196
+ CommonModule,
197
+ HttpClientModule,
198
+ OAuthModule.forRoot()
199
+ ]
200
+ }]
201
201
  }] });
202
202
 
203
- class AuthorizeInterceptor {
204
- constructor(authorize) {
205
- this.authorize = authorize;
206
- authorize.getAccessToken().subscribe(value => this.accessToken = value);
207
- }
208
- static isSameOriginUrl(req) {
209
- // It's an absolute url with the same origin.
210
- if (req.url.startsWith(`${window.location.origin}/`)) {
211
- return true;
212
- }
213
- // It's a protocol relative url with the same origin.
214
- // For example: //www.example.com/api/Products
215
- if (req.url.startsWith(`//${window.location.host}/`)) {
216
- return true;
217
- }
218
- // It's a relative url like /api/Products
219
- if (/^\/[^\/].*/.test(req.url)) {
220
- return true;
221
- }
222
- // It's an absolute or protocol relative url that
223
- // doesn't have the same origin.
224
- return false;
225
- }
226
- // Checks if there is an access_token available in the authorize service
227
- // and adds it to the request in case it's targeted at the same origin as the
228
- intercept(req, next) {
229
- return this.processRequestWithToken(this.accessToken, req, next);
230
- }
231
- // single page application.
232
- processRequestWithToken(token, req, next) {
233
- if (!!token && (AuthorizeInterceptor.isSameOriginUrl(req) || this.isKnownServiceUri(req))) {
234
- req = req.clone({
235
- setHeaders: {
236
- Authorization: `Bearer ${token}`
237
- }
238
- });
239
- }
240
- return next.handle(req);
241
- }
242
- isKnownServiceUri(req) {
243
- const serviceUris = this.authorize.getServiceUris();
244
- for (let i = 0; i < serviceUris.length; i++) {
245
- if (req.url.startsWith(`${serviceUris[i]}`)) {
246
- return true;
247
- }
248
- }
249
- // It's an absolute or protocol relative url that
250
- // doesn't have the same origin.
251
- return false;
252
- }
253
- }
254
- AuthorizeInterceptor.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "14.2.2", ngImport: i0, type: AuthorizeInterceptor, deps: [{ token: AuthorizeService }], target: i0.ɵɵFactoryTarget.Injectable });
255
- AuthorizeInterceptor.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "14.2.2", ngImport: i0, type: AuthorizeInterceptor });
256
- i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "14.2.2", ngImport: i0, type: AuthorizeInterceptor, decorators: [{
257
- type: Injectable
203
+ class AuthorizeInterceptor {
204
+ constructor(authorize) {
205
+ this.authorize = authorize;
206
+ authorize.getAccessToken().subscribe(value => this.accessToken = value);
207
+ }
208
+ static isSameOriginUrl(req) {
209
+ // It's an absolute url with the same origin.
210
+ if (req.url.startsWith(`${window.location.origin}/`)) {
211
+ return true;
212
+ }
213
+ // It's a protocol relative url with the same origin.
214
+ // For example: //www.example.com/api/Products
215
+ if (req.url.startsWith(`//${window.location.host}/`)) {
216
+ return true;
217
+ }
218
+ // It's a relative url like /api/Products
219
+ if (/^\/[^\/].*/.test(req.url)) {
220
+ return true;
221
+ }
222
+ // It's an absolute or protocol relative url that
223
+ // doesn't have the same origin.
224
+ return false;
225
+ }
226
+ // Checks if there is an access_token available in the authorize service
227
+ // and adds it to the request in case it's targeted at the same origin as the
228
+ intercept(req, next) {
229
+ return this.processRequestWithToken(this.accessToken, req, next);
230
+ }
231
+ // single page application.
232
+ processRequestWithToken(token, req, next) {
233
+ if (!!token && (AuthorizeInterceptor.isSameOriginUrl(req) || this.isKnownServiceUri(req))) {
234
+ req = req.clone({
235
+ setHeaders: {
236
+ Authorization: `Bearer ${token}`
237
+ }
238
+ });
239
+ }
240
+ return next.handle(req);
241
+ }
242
+ isKnownServiceUri(req) {
243
+ const serviceUris = this.authorize.getServiceUris();
244
+ for (let i = 0; i < serviceUris.length; i++) {
245
+ if (req.url.startsWith(`${serviceUris[i]}`)) {
246
+ return true;
247
+ }
248
+ }
249
+ // It's an absolute or protocol relative url that
250
+ // doesn't have the same origin.
251
+ return false;
252
+ }
253
+ }
254
+ AuthorizeInterceptor.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "14.2.2", ngImport: i0, type: AuthorizeInterceptor, deps: [{ token: AuthorizeService }], target: i0.ɵɵFactoryTarget.Injectable });
255
+ AuthorizeInterceptor.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "14.2.2", ngImport: i0, type: AuthorizeInterceptor });
256
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "14.2.2", ngImport: i0, type: AuthorizeInterceptor, decorators: [{
257
+ type: Injectable
258
258
  }], ctorParameters: function () { return [{ type: AuthorizeService }]; } });
259
259
 
260
- /*
261
- * Public API Surface of shared-auth
260
+ /*
261
+ * Public API Surface of shared-auth
262
262
  */
263
263
 
264
- /**
265
- * Generated bundle index. Do not edit.
264
+ /**
265
+ * Generated bundle index. Do not edit.
266
266
  */
267
267
 
268
268
  export { AuthorizeGuard, AuthorizeInterceptor, AuthorizeOptions, AuthorizeService, LoginMenuComponent, SharedAuthModule };
@@ -1 +1 @@
1
- {"version":3,"file":"meshmakers-shared-auth.mjs","sources":["../../../../projects/meshmakers/shared-auth/src/lib/authorize.service.ts","../../../../projects/meshmakers/shared-auth/src/lib/login-menu/login-menu.component.ts","../../../../projects/meshmakers/shared-auth/src/lib/login-menu/login-menu.component.html","../../../../projects/meshmakers/shared-auth/src/lib/authorize.guard.ts","../../../../projects/meshmakers/shared-auth/src/lib/shared-auth.module.ts","../../../../projects/meshmakers/shared-auth/src/lib/authorize.interceptor.ts","../../../../projects/meshmakers/shared-auth/src/public-api.ts","../../../../projects/meshmakers/shared-auth/src/meshmakers-shared-auth.ts"],"sourcesContent":["import {Inject, Injectable} from '@angular/core';\nimport {BehaviorSubject} from 'rxjs';\nimport {filter} from 'rxjs/operators';\nimport {AuthConfig, OAuthService} from \"angular-oauth2-oidc\";\n\nexport interface IUser {\n name: string;\n role: string;\n}\n\nexport class AuthorizeOptions {\n wellKnownServiceUris: string[];\n // Url of the Identity Provider\n issuer: string;\n // URL of the SPA to redirect the user to after login\n redirectUri: string;\n postLogoutRedirectUri: string;\n // The SPA's id. The SPA is registered with this id at the auth-server\n clientId: string;\n // set the scope for the permissions the client should request\n // The first three are defined by OIDC. The 4th is a use case-specific one\n scope: string;\n showDebugInformation: boolean;\n sessionChecksEnabled: boolean;\n}\n\n@Injectable()\nexport class AuthorizeService {\n private isAuthenticated: BehaviorSubject<boolean> = new BehaviorSubject(false);\n private isAdmin: BehaviorSubject<boolean> = new BehaviorSubject(false);\n private authority: BehaviorSubject<string> = new BehaviorSubject(null);\n private accessToken: BehaviorSubject<string> = new BehaviorSubject(null);\n private user: BehaviorSubject<IUser> = new BehaviorSubject(null);\n\n constructor(@Inject(AuthorizeOptions) private authorizeOptions: AuthorizeOptions, private oauthService: OAuthService) {\n console.debug(\"AuthorizeService::created\");\n this.getUser().subscribe(s => {\n this.isAuthenticated.next(!!s);\n this.isAdmin.next(!!s && s.role === \"Administrators\");\n });\n }\n\n public getServiceUris(): Array<string> {\n return this.authorizeOptions.wellKnownServiceUris;\n }\n\n public getAuthority(): BehaviorSubject<string> {\n return this.authority;\n }\n\n public getIsAuthenticated(): BehaviorSubject<boolean> {\n return this.isAuthenticated;\n }\n\n public getIsAdmin(): BehaviorSubject<boolean> {\n return this.isAdmin;\n }\n\n public getAccessToken(): BehaviorSubject<string> {\n return this.accessToken;\n }\n\n public getUser(): BehaviorSubject<IUser> {\n return this.user;\n }\n\n public login() {\n this.oauthService.initImplicitFlow();\n }\n\n public logout() {\n this.oauthService.logOut(false);\n }\n\n\n public initialize() {\n\n console.debug(\"AuthorizeService::initialize::started\");\n\n const config: AuthConfig = {\n responseType: 'code',\n issuer: this.authorizeOptions.issuer,\n redirectUri: this.authorizeOptions.redirectUri,\n postLogoutRedirectUri: this.authorizeOptions.postLogoutRedirectUri,\n clientId: this.authorizeOptions.clientId,\n scope: this.authorizeOptions.scope,\n showDebugInformation: this.authorizeOptions.showDebugInformation,\n sessionChecksEnabled: this.authorizeOptions.sessionChecksEnabled\n };\n\n this.oauthService.configure(config);\n this.oauthService.setStorage(localStorage);\n this.oauthService.loadDiscoveryDocumentAndTryLogin();\n\n this.oauthService.setupAutomaticSilentRefresh();\n\n this.oauthService.events.subscribe(e => {\n // tslint:disable-next-line:no-console\n console.debug('oauth/oidc event', e);\n });\n\n this.oauthService.events\n .pipe(filter(e => e.type === 'session_terminated'))\n .subscribe(e => {\n // tslint:disable-next-line:no-console\n console.debug('Your session has been terminated!');\n });\n\n this.oauthService.events\n .pipe(filter(e => e.type === 'token_received'))\n .subscribe(e => {\n this.loadUser();\n });\n\n this.oauthService.events\n .pipe(filter(e => e.type === 'logout'))\n .subscribe(e => {\n this.accessToken.next(null);\n this.user.next(null);\n });\n\n if (this.oauthService.hasValidAccessToken()) {\n this.loadUser();\n }\n\n this.authority.next(this.authorizeOptions.issuer);\n\n console.debug(\"AuthorizeService::initialize::done\");\n\n }\n\n private loadUser() {\n const claims = this.oauthService.getIdentityClaims();\n if (!claims) {\n console.error(\"claims where null when loading identity claims\");\n return;\n }\n\n const user = <IUser>claims;\n const accessToken = this.oauthService.getAccessToken();\n this.user.next(user);\n this.accessToken.next(accessToken);\n }\n}\n","import {Component, OnInit} from '@angular/core';\nimport {AuthorizeService} from '../authorize.service';\nimport {BehaviorSubject, Observable} from 'rxjs';\nimport {map} from 'rxjs/operators';\n\n@Component({\n selector: 'app-login-menu',\n templateUrl: './login-menu.component.html',\n styleUrls: ['./login-menu.component.css']\n})\nexport class LoginMenuComponent implements OnInit {\n public isAuthenticated: BehaviorSubject<boolean>;\n public userName: Observable<string>;\n public isAdmin: Observable<boolean>;\n\n constructor(private authorizeService: AuthorizeService) {\n }\n\n ngOnInit() {\n const isIFrame = window.self !== window.top;\n\n console.log(\"app-login-menu::created\");\n\n this.isAuthenticated = this.authorizeService.getIsAuthenticated();\n this.userName = this.authorizeService.getUser().pipe(map(u => u && u.name));\n this.isAdmin = this.authorizeService.getIsAdmin();\n\n this.isAuthenticated.subscribe(x => {\n\n console.log(`isAuthenticated changed to ${x} (iframe ${isIFrame})`);\n });\n }\n\n public login() {\n this.authorizeService.login();\n }\n\n public logout() {\n this.authorizeService.logout();\n }\n\n public register() {\n\n }\n}\n","<ul *ngIf=\"isAuthenticated | async\" class=\"navbar-nav\">\n <li class=\"nav-item dropdown\">\n <a aria-expanded=\"false\" aria-haspopup=\"true\" class=\"nav-link dropdown-toggle\" data-toggle=\"dropdown\" href=\"#\"\n id=\"navbarDropdownLogin\" role=\"button\">\n {{ userName | async }} <b class=\"caret\"></b>\n </a>\n <div aria-labelledby=\"navbarDropdown\" class=\"dropdown-menu\">\n <!--<a class=\"dropdown-item\" asp-action=\"Index\" asp-area=\"Authentication\" asp-controller=\"Grants\">Client Application Access</a>-->\n <!--<a class=\"dropdown-item\" [routerLink]='[\"/authentication/profile\"]' title=\"Manage\">Manage</a>-->\n <!--<a class=\"dropdown-item\" asp-action=\"Index\" asp-area=\"Authentication\" asp-controller=\"Diagnostics\">Diagnostics</a>-->\n <div class=\"dropdown-divider\"></div>\n <a (click)='logout()' class=\"dropdown-item\" routerLink=\"\" title=\"Logout\">Logout</a>\n </div>\n </li>\n</ul>\n<ul *ngIf=\"!(isAuthenticated | async)\" class=\"navbar-nav\">\n <li class=\"nav-item\">\n <a (click)='register()' class=\"nav-link\" routerLink=\"\">Register</a>\n </li>\n <li class=\"nav-item\">\n <a (click)='login()' class=\"nav-link\" routerLink=\"\">Login</a>\n </li>\n</ul>\n","import {Injectable} from '@angular/core';\nimport {ActivatedRouteSnapshot, CanActivate, RouterStateSnapshot} from '@angular/router';\nimport {AuthorizeService} from './authorize.service';\nimport {tap} from 'rxjs/operators';\n\n@Injectable()\nexport class AuthorizeGuard implements CanActivate {\n constructor(private authorize: AuthorizeService) {\n }\n\n canActivate(\n _next: ActivatedRouteSnapshot,\n state: RouterStateSnapshot): any {\n return this.authorize.getIsAuthenticated()\n .pipe(tap(isAuthenticated => this.handleAuthorization(isAuthenticated)));\n }\n\n private handleAuthorization(isAuthenticated: boolean) {\n if (!isAuthenticated) {\n this.authorize.login();\n }\n }\n}\n","import {ModuleWithProviders, NgModule} from '@angular/core';\nimport {CommonModule} from \"@angular/common\";\nimport {HttpClientModule} from \"@angular/common/http\";\nimport {LoginMenuComponent} from \"./login-menu/login-menu.component\";\nimport {AuthorizeOptions, AuthorizeService} from \"./authorize.service\";\nimport {OAuthModule} from \"angular-oauth2-oidc\";\nimport {AuthorizeGuard} from \"./authorize.guard\";\n\n@NgModule({\n declarations: [LoginMenuComponent],\n exports: [LoginMenuComponent],\n providers: [],\n imports: [\n CommonModule,\n HttpClientModule,\n OAuthModule.forRoot()\n ]\n})\nexport class SharedAuthModule {\n static forRoot(authorizeOptions: AuthorizeOptions): ModuleWithProviders<SharedAuthModule> {\n return {\n ngModule: SharedAuthModule,\n providers: [\n {\n provide: AuthorizeOptions,\n useValue: authorizeOptions\n },\n AuthorizeService,\n AuthorizeGuard\n ]\n }\n }\n}\n","import {Injectable} from '@angular/core';\nimport {HttpEvent, HttpHandler, HttpInterceptor, HttpRequest} from '@angular/common/http';\nimport {Observable} from 'rxjs';\nimport {AuthorizeService} from './authorize.service';\n\n@Injectable()\nexport class AuthorizeInterceptor implements HttpInterceptor {\n\n accessToken: string;\n\n constructor(private authorize: AuthorizeService) {\n\n authorize.getAccessToken().subscribe(value => this.accessToken = value);\n\n }\n\n private static isSameOriginUrl(req: any) {\n // It's an absolute url with the same origin.\n if (req.url.startsWith(`${window.location.origin}/`)) {\n return true;\n }\n\n // It's a protocol relative url with the same origin.\n // For example: //www.example.com/api/Products\n if (req.url.startsWith(`//${window.location.host}/`)) {\n return true;\n }\n\n // It's a relative url like /api/Products\n if (/^\\/[^\\/].*/.test(req.url)) {\n return true;\n }\n\n // It's an absolute or protocol relative url that\n // doesn't have the same origin.\n return false;\n }\n\n // Checks if there is an access_token available in the authorize service\n // and adds it to the request in case it's targeted at the same origin as the\n\n intercept(req: HttpRequest<any>, next: HttpHandler): Observable<HttpEvent<any>> {\n return this.processRequestWithToken(this.accessToken, req, next);\n }\n\n // single page application.\n private processRequestWithToken(token: string, req: HttpRequest<any>, next: HttpHandler) {\n if (!!token && (AuthorizeInterceptor.isSameOriginUrl(req) || this.isKnownServiceUri(req))) {\n req = req.clone({\n setHeaders: {\n Authorization: `Bearer ${token}`\n }\n });\n }\n\n return next.handle(req);\n }\n\n private isKnownServiceUri(req: any) {\n\n const serviceUris = this.authorize.getServiceUris();\n\n for (let i = 0; i < serviceUris.length; i++) {\n if (req.url.startsWith(`${serviceUris[i]}`)) {\n return true;\n }\n }\n\n // It's an absolute or protocol relative url that\n // doesn't have the same origin.\n return false;\n }\n}\n","/*\n * Public API Surface of shared-auth\n */\n\nexport * from './lib/authorize.service';\nexport * from './lib/login-menu/login-menu.component';\nexport * from './lib/shared-auth.module';\nexport * from './lib/authorize.interceptor';\nexport * from './lib/authorize.guard';\n","/**\n * Generated bundle index. Do not edit.\n */\n\nexport * from './public-api';\n"],"names":["i1.AuthorizeService"],"mappings":";;;;;;;;;;MAUa,gBAAgB,CAAA;AAc5B,CAAA;MAGY,gBAAgB,CAAA;IAO3B,WAA8C,CAAA,gBAAkC,EAAU,YAA0B,EAAA;AAAtE,QAAA,IAAgB,CAAA,gBAAA,GAAhB,gBAAgB,CAAkB;AAAU,QAAA,IAAY,CAAA,YAAA,GAAZ,YAAY,CAAc;QAN5G,IAAA,CAAA,eAAe,GAA6B,IAAI,eAAe,CAAC,KAAK,CAAC,CAAC;QACvE,IAAA,CAAA,OAAO,GAA6B,IA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,GAAG,GAAG,CAAC,KAAK,CAAC;AACd,gBAAA,UAAU,EAAE;oBACV,aAAa,EAAE,CAAU,OAAA,EAAA,KAAK,CAAE,CAAA;AACjC,iBAAA;AACF,aAAA,CAAC,CAAC;AACJ,SAAA;AAED,QAAA,OAAO,IAAI,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC;KACzB;AAEO,IAAA,iBAAiB,CAAC,GAAQ,EAAA;QAEhC,MAAM,WAAW,GAAG,IAAI,CAAC,SAAS,CAAC,cAAc,EAAE,CAAC;AAEpD,QAAA,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,WAAW,CAAC,MAAM,EAAE,CAAC,EAAE,EAAE;AAC3C,YAAA,IAAI,GAAG,CAAC,GAAG,CAAC,UAAU,CAAC,CAAG,EAAA,WAAW,CAAC,CAAC,CAAC,CAAA,CAAE,CAAC,EAAE;AAC3C,gBAAA,OAAO,IAAI,CAAC;AACb,aAAA;AACF,SAAA;;;AAID,QAAA,OAAO,KAAK,CAAC;KACd;;iHAjEU,oBAAoB,EAAA,IAAA,EAAA,CAAA,EAAA,KAAA,EAAAA,gBAAA,EAAA,CAAA,EAAA,MAAA,EAAA,EAAA,CAAA,eAAA,CAAA,UAAA,EAAA,CAAA,CAAA;qHAApB,oBAAoB,EAAA,CAAA,CAAA;2FAApB,oBAAoB,EAAA,UAAA,EAAA,CAAA;kBADhC,UAAU;;;ACLX;;AAEG;;ACFH;;AAEG;;;;"}
1
+ {"version":3,"file":"meshmakers-shared-auth.mjs","sources":["../../../../projects/meshmakers/shared-auth/src/lib/authorize.service.ts","../../../../projects/meshmakers/shared-auth/src/lib/login-menu/login-menu.component.ts","../../../../projects/meshmakers/shared-auth/src/lib/login-menu/login-menu.component.html","../../../../projects/meshmakers/shared-auth/src/lib/authorize.guard.ts","../../../../projects/meshmakers/shared-auth/src/lib/shared-auth.module.ts","../../../../projects/meshmakers/shared-auth/src/lib/authorize.interceptor.ts","../../../../projects/meshmakers/shared-auth/src/public-api.ts","../../../../projects/meshmakers/shared-auth/src/meshmakers-shared-auth.ts"],"sourcesContent":["import {Inject, Injectable} from '@angular/core';\r\nimport {BehaviorSubject} from 'rxjs';\r\nimport {filter} from 'rxjs/operators';\r\nimport {AuthConfig, OAuthService} from \"angular-oauth2-oidc\";\r\n\r\nexport interface IUser {\r\n name: string;\r\n role: string;\r\n}\r\n\r\nexport class AuthorizeOptions {\r\n wellKnownServiceUris: string[];\r\n // Url of the Identity Provider\r\n issuer: string;\r\n // URL of the SPA to redirect the user to after login\r\n redirectUri: string;\r\n postLogoutRedirectUri: string;\r\n // The SPA's id. The SPA is registered with this id at the auth-server\r\n clientId: string;\r\n // set the scope for the permissions the client should request\r\n // The first three are defined by OIDC. The 4th is a use case-specific one\r\n scope: string;\r\n showDebugInformation: boolean;\r\n sessionChecksEnabled: boolean;\r\n}\r\n\r\n@Injectable()\r\nexport class AuthorizeService {\r\n private isAuthenticated: BehaviorSubject<boolean> = new BehaviorSubject(false);\r\n private isAdmin: BehaviorSubject<boolean> = new BehaviorSubject(false);\r\n private authority: BehaviorSubject<string> = new BehaviorSubject(null);\r\n private accessToken: BehaviorSubject<string> = new BehaviorSubject(null);\r\n private user: BehaviorSubject<IUser> = new BehaviorSubject(null);\r\n\r\n constructor(@Inject(AuthorizeOptions) private authorizeOptions: AuthorizeOptions, private oauthService: OAuthService) {\r\n console.debug(\"AuthorizeService::created\");\r\n this.getUser().subscribe(s => {\r\n this.isAuthenticated.next(!!s);\r\n this.isAdmin.next(!!s && s.role === \"Administrators\");\r\n });\r\n }\r\n\r\n public getServiceUris(): Array<string> {\r\n return this.authorizeOptions.wellKnownServiceUris;\r\n }\r\n\r\n public getAuthority(): BehaviorSubject<string> {\r\n return this.authority;\r\n }\r\n\r\n public getIsAuthenticated(): BehaviorSubject<boolean> {\r\n return this.isAuthenticated;\r\n }\r\n\r\n public getIsAdmin(): BehaviorSubject<boolean> {\r\n return this.isAdmin;\r\n }\r\n\r\n public getAccessToken(): BehaviorSubject<string> {\r\n return this.accessToken;\r\n }\r\n\r\n public getUser(): BehaviorSubject<IUser> {\r\n return this.user;\r\n }\r\n\r\n public login() {\r\n this.oauthService.initImplicitFlow();\r\n }\r\n\r\n public logout() {\r\n this.oauthService.logOut(false);\r\n }\r\n\r\n\r\n public initialize() {\r\n\r\n console.debug(\"AuthorizeService::initialize::started\");\r\n\r\n const config: AuthConfig = {\r\n responseType: 'code',\r\n issuer: this.authorizeOptions.issuer,\r\n redirectUri: this.authorizeOptions.redirectUri,\r\n postLogoutRedirectUri: this.authorizeOptions.postLogoutRedirectUri,\r\n clientId: this.authorizeOptions.clientId,\r\n scope: this.authorizeOptions.scope,\r\n showDebugInformation: this.authorizeOptions.showDebugInformation,\r\n sessionChecksEnabled: this.authorizeOptions.sessionChecksEnabled\r\n };\r\n\r\n this.oauthService.configure(config);\r\n this.oauthService.setStorage(localStorage);\r\n this.oauthService.loadDiscoveryDocumentAndTryLogin();\r\n\r\n this.oauthService.setupAutomaticSilentRefresh();\r\n\r\n this.oauthService.events.subscribe(e => {\r\n // tslint:disable-next-line:no-console\r\n console.debug('oauth/oidc event', e);\r\n });\r\n\r\n this.oauthService.events\r\n .pipe(filter(e => e.type === 'session_terminated'))\r\n .subscribe(e => {\r\n // tslint:disable-next-line:no-console\r\n console.debug('Your session has been terminated!');\r\n });\r\n\r\n this.oauthService.events\r\n .pipe(filter(e => e.type === 'token_received'))\r\n .subscribe(e => {\r\n this.loadUser();\r\n });\r\n\r\n this.oauthService.events\r\n .pipe(filter(e => e.type === 'logout'))\r\n .subscribe(e => {\r\n this.accessToken.next(null);\r\n this.user.next(null);\r\n });\r\n\r\n if (this.oauthService.hasValidAccessToken()) {\r\n this.loadUser();\r\n }\r\n\r\n this.authority.next(this.authorizeOptions.issuer);\r\n\r\n console.debug(\"AuthorizeService::initialize::done\");\r\n\r\n }\r\n\r\n private loadUser() {\r\n const claims = this.oauthService.getIdentityClaims();\r\n if (!claims) {\r\n console.error(\"claims where null when loading identity claims\");\r\n return;\r\n }\r\n\r\n const user = <IUser>claims;\r\n const accessToken = this.oauthService.getAccessToken();\r\n this.user.next(user);\r\n this.accessToken.next(accessToken);\r\n }\r\n}\r\n","import {Component, OnInit} from '@angular/core';\r\nimport {AuthorizeService} from '../authorize.service';\r\nimport {BehaviorSubject, Observable} from 'rxjs';\r\nimport {map} from 'rxjs/operators';\r\n\r\n@Component({\r\n selector: 'app-login-menu',\r\n templateUrl: './login-menu.component.html',\r\n styleUrls: ['./login-menu.component.css']\r\n})\r\nexport class LoginMenuComponent implements OnInit {\r\n public isAuthenticated: BehaviorSubject<boolean>;\r\n public userName: Observable<string>;\r\n public isAdmin: Observable<boolean>;\r\n\r\n constructor(private authorizeService: AuthorizeService) {\r\n }\r\n\r\n ngOnInit() {\r\n const isIFrame = window.self !== window.top;\r\n\r\n console.log(\"app-login-menu::created\");\r\n\r\n this.isAuthenticated = this.authorizeService.getIsAuthenticated();\r\n this.userName = this.authorizeService.getUser().pipe(map(u => u && u.name));\r\n this.isAdmin = this.authorizeService.getIsAdmin();\r\n\r\n this.isAuthenticated.subscribe(x => {\r\n\r\n console.log(`isAuthenticated changed to ${x} (iframe ${isIFrame})`);\r\n });\r\n }\r\n\r\n public login() {\r\n this.authorizeService.login();\r\n }\r\n\r\n public logout() {\r\n this.authorizeService.logout();\r\n }\r\n\r\n public register() {\r\n\r\n }\r\n}\r\n","<ul *ngIf=\"isAuthenticated | async\" class=\"navbar-nav\">\r\n <li class=\"nav-item dropdown\">\r\n <a aria-expanded=\"false\" aria-haspopup=\"true\" class=\"nav-link dropdown-toggle\" data-toggle=\"dropdown\" href=\"#\"\r\n id=\"navbarDropdownLogin\" role=\"button\">\r\n {{ userName | async }} <b class=\"caret\"></b>\r\n </a>\r\n <div aria-labelledby=\"navbarDropdown\" class=\"dropdown-menu\">\r\n <!--<a class=\"dropdown-item\" asp-action=\"Index\" asp-area=\"Authentication\" asp-controller=\"Grants\">Client Application Access</a>-->\r\n <!--<a class=\"dropdown-item\" [routerLink]='[\"/authentication/profile\"]' title=\"Manage\">Manage</a>-->\r\n <!--<a class=\"dropdown-item\" asp-action=\"Index\" asp-area=\"Authentication\" asp-controller=\"Diagnostics\">Diagnostics</a>-->\r\n <div class=\"dropdown-divider\"></div>\r\n <a (click)='logout()' class=\"dropdown-item\" routerLink=\"\" title=\"Logout\">Logout</a>\r\n </div>\r\n </li>\r\n</ul>\r\n<ul *ngIf=\"!(isAuthenticated | async)\" class=\"navbar-nav\">\r\n <li class=\"nav-item\">\r\n <a (click)='register()' class=\"nav-link\" routerLink=\"\">Register</a>\r\n </li>\r\n <li class=\"nav-item\">\r\n <a (click)='login()' class=\"nav-link\" routerLink=\"\">Login</a>\r\n </li>\r\n</ul>\r\n","import {Injectable} from '@angular/core';\r\nimport {ActivatedRouteSnapshot, CanActivate, RouterStateSnapshot} from '@angular/router';\r\nimport {AuthorizeService} from './authorize.service';\r\nimport {tap} from 'rxjs/operators';\r\n\r\n@Injectable()\r\nexport class AuthorizeGuard implements CanActivate {\r\n constructor(private authorize: AuthorizeService) {\r\n }\r\n\r\n canActivate(\r\n _next: ActivatedRouteSnapshot,\r\n state: RouterStateSnapshot): any {\r\n return this.authorize.getIsAuthenticated()\r\n .pipe(tap(isAuthenticated => this.handleAuthorization(isAuthenticated)));\r\n }\r\n\r\n private handleAuthorization(isAuthenticated: boolean) {\r\n if (!isAuthenticated) {\r\n this.authorize.login();\r\n }\r\n }\r\n}\r\n","import {ModuleWithProviders, NgModule} from '@angular/core';\r\nimport {CommonModule} from \"@angular/common\";\r\nimport {HttpClientModule} from \"@angular/common/http\";\r\nimport {LoginMenuComponent} from \"./login-menu/login-menu.component\";\r\nimport {AuthorizeOptions, AuthorizeService} from \"./authorize.service\";\r\nimport {OAuthModule} from \"angular-oauth2-oidc\";\r\nimport {AuthorizeGuard} from \"./authorize.guard\";\r\n\r\n@NgModule({\r\n declarations: [LoginMenuComponent],\r\n exports: [LoginMenuComponent],\r\n providers: [],\r\n imports: [\r\n CommonModule,\r\n HttpClientModule,\r\n OAuthModule.forRoot()\r\n ]\r\n})\r\nexport class SharedAuthModule {\r\n static forRoot(authorizeOptions: AuthorizeOptions): ModuleWithProviders<SharedAuthModule> {\r\n return {\r\n ngModule: SharedAuthModule,\r\n providers: [\r\n {\r\n provide: AuthorizeOptions,\r\n useValue: authorizeOptions\r\n },\r\n AuthorizeService,\r\n AuthorizeGuard\r\n ]\r\n }\r\n }\r\n}\r\n","import {Injectable} from '@angular/core';\r\nimport {HttpEvent, HttpHandler, HttpInterceptor, HttpRequest} from '@angular/common/http';\r\nimport {Observable} from 'rxjs';\r\nimport {AuthorizeService} from './authorize.service';\r\n\r\n@Injectable()\r\nexport class AuthorizeInterceptor implements HttpInterceptor {\r\n\r\n accessToken: string;\r\n\r\n constructor(private authorize: AuthorizeService) {\r\n\r\n authorize.getAccessToken().subscribe(value => this.accessToken = value);\r\n\r\n }\r\n\r\n private static isSameOriginUrl(req: any) {\r\n // It's an absolute url with the same origin.\r\n if (req.url.startsWith(`${window.location.origin}/`)) {\r\n return true;\r\n }\r\n\r\n // It's a protocol relative url with the same origin.\r\n // For example: //www.example.com/api/Products\r\n if (req.url.startsWith(`//${window.location.host}/`)) {\r\n return true;\r\n }\r\n\r\n // It's a relative url like /api/Products\r\n if (/^\\/[^\\/].*/.test(req.url)) {\r\n return true;\r\n }\r\n\r\n // It's an absolute or protocol relative url that\r\n // doesn't have the same origin.\r\n return false;\r\n }\r\n\r\n // Checks if there is an access_token available in the authorize service\r\n // and adds it to the request in case it's targeted at the same origin as the\r\n\r\n intercept(req: HttpRequest<any>, next: HttpHandler): Observable<HttpEvent<any>> {\r\n return this.processRequestWithToken(this.accessToken, req, next);\r\n }\r\n\r\n // single page application.\r\n private processRequestWithToken(token: string, req: HttpRequest<any>, next: HttpHandler) {\r\n if (!!token && (AuthorizeInterceptor.isSameOriginUrl(req) || this.isKnownServiceUri(req))) {\r\n req = req.clone({\r\n setHeaders: {\r\n Authorization: `Bearer ${token}`\r\n }\r\n });\r\n }\r\n\r\n return next.handle(req);\r\n }\r\n\r\n private isKnownServiceUri(req: any) {\r\n\r\n const serviceUris = this.authorize.getServiceUris();\r\n\r\n for (let i = 0; i < serviceUris.length; i++) {\r\n if (req.url.startsWith(`${serviceUris[i]}`)) {\r\n return true;\r\n }\r\n }\r\n\r\n // It's an absolute or protocol relative url that\r\n // doesn't have the same origin.\r\n return false;\r\n }\r\n}\r\n","/*\r\n * Public API Surface of shared-auth\r\n */\r\n\r\nexport * from './lib/authorize.service';\r\nexport * from './lib/login-menu/login-menu.component';\r\nexport * from './lib/shared-auth.module';\r\nexport * from './lib/authorize.interceptor';\r\nexport * from './lib/authorize.guard';\r\n","/**\n * Generated bundle index. Do not edit.\n */\n\nexport * from './public-api';\n"],"names":["i1.AuthorizeService"],"mappings":";;;;;;;;;;MAUa,gBAAgB,CAAA;AAc5B,CAAA;MAGY,gBAAgB,CAAA;IAO3B,WAA8C,CAAA,gBAAkC,EAAU,YAA0B,EAAA;AAAtE,QAAA,IAAgB,CAAA,gBAAA,GAAhB,gBAAgB,CAAkB;AAAU,QAAA,IAAY,CAAA,YAAA,GAAZ,YAAY,CAAc;QAN5G,IAAA,CAAA,eAAe,GAA6B,IAAI,eAAe,CAAC,KAAK,CAAC,CAAC;QACvE,IAAA,CAAA,OAAO,GAA6B,IAAI,eAAe,CAAC,KAAK,CAAC,CAAC;QAC/D,IAAA,CAAA,SAAS,GAA4B,IAAI,eAAe,CAAC,IAAI,CAAC,CAAC;QAC/D,IAAA,CAAA,WAAW,GAA4B,IAAI,eAAe,CAAC,IAAI,CAAC,CAAC;QACjE,IAAA,CAAA,IAAI,GAA2B,IAAI,eAAe,CAAC,IAAI,CAAC,CAAC;AAG/D,QAAA,OAAO,CAAC,KAAK,CAAC,2BAA2B,CAAC,CAAC;QAC3C,IAAI,CAAC,OAAO,EAAE,CAAC,SAAS,CAAC,CAAC,IAAG;YAC3B,IAAI,CAAC,eAAe,CAAC,IAAI,CAAC,CA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