Skip to content
This repository was archived by the owner on Aug 1, 2021. It is now read-only.

Commit eaea079

Browse files
committed
- Bug fixes
- angular-oauth2-oidc Session Improvements for Angular Apps. Incluind Admin UI - Some Action attributes was HttpPost instead HttpPut (fixed) - New unity tests
1 parent f744b14 commit eaea079

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

46 files changed

+790
-481
lines changed

README.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,13 @@ We'll love it! Please [Read the docs](https://jp-project.readthedocs.io/en/lates
111111
If you need help building or running your Jp Project platform
112112
There are several ways we can help you out.
113113

114+
## v1.3
115+
116+
- Bug fixes
117+
- angular-oauth2-oidc Session Improvements for Angular Apps. Incluind Admin UI
118+
- Some Action attributes was HttpPost instead HttpPut (fixed)
119+
- New unity tests
120+
114121
## v1.2
115122

116123
- Docker support

src/Backend/Jp.UserManagement/Controllers/ApiResourceController.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ public async Task<ActionResult<DefaultResponse<bool>>> Save([FromBody] ApiResour
5353
return Response(true);
5454
}
5555

56-
[HttpPost, Route("update"), Authorize(Policy = "Admin")]
56+
[HttpPut, Route("update"), Authorize(Policy = "Admin")]
5757
public async Task<ActionResult<DefaultResponse<bool>>> Update([FromBody] ApiResource model)
5858
{
5959
if (!ModelState.IsValid)
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
{
2+
// Use IntelliSense to learn about possible attributes.
3+
// Hover to view descriptions of existing attributes.
4+
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
5+
"version": "0.2.0",
6+
"configurations": [
7+
{
8+
"type": "chrome",
9+
"request": "launch",
10+
"name": "Launch Chrome against localhost",
11+
"url": "http://localhost:4300",
12+
"webRoot": "${workspaceFolder}"
13+
}
14+
]
15+
}

src/Frontend/Jp.AdminUI/src/app/app.component.ts

Lines changed: 19 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,12 @@ import { Component, HostBinding, OnInit } from "@angular/core";
22
declare var $: any;
33

44
import { SettingsService } from "./core/settings/settings.service";
5-
import { OAuthService, JwksValidationHandler } from "angular-oauth2-oidc";
6-
import { Router } from "@angular/router";
7-
import { authConfig } from "./core/auth/auth.config";
8-
import { environment } from "../environments/environment";
9-
import { tap } from "rxjs/operators";
5+
// import { authConfig } from "./core/auth/auth.config";
6+
import { AuthService } from "@core/auth/auth.service";
7+
import { Observable } from "rxjs";
8+
9+
10+
1011

1112
@Component({
1213
selector: "app-root",
@@ -26,31 +27,22 @@ export class AppComponent implements OnInit {
2627
@HostBinding("class.aside-toggled") get asideToggled() { return this.settings.layout.asideToggled; }
2728
@HostBinding("class.aside-collapsed-text") get isCollapsedText() { return this.settings.layout.isCollapsedText; }
2829

29-
constructor(private router: Router,
30-
private oauthService: OAuthService,
31-
public settings: SettingsService) {
32-
this.configureWithNewConfigApi();
33-
}
30+
isAuthenticated: Observable<boolean>;
31+
isDoneLoading: Observable<boolean>;
32+
canActivateProtectedRoutes: Observable<boolean>;
33+
34+
constructor(
35+
private authService: AuthService,
36+
public settings: SettingsService
37+
) {
38+
this.isAuthenticated = this.authService.isAuthenticated$;
39+
this.isDoneLoading = this.authService.isDoneLoading$;
40+
this.canActivateProtectedRoutes = this.authService.canActivateProtectedRoutes$;
3441

35-
private async configureWithNewConfigApi() {
36-
this.oauthService.configure(authConfig);
37-
this.oauthService.setStorage(localStorage);
38-
this.oauthService.tokenValidationHandler = new JwksValidationHandler();
39-
40-
41-
this.settings.loadDiscoveryDocumentAndTryLogin().pipe(tap(doc => {
42-
if (!environment.production)
43-
console.log(doc);
44-
})).subscribe(a => {
45-
this.oauthService.setupAutomaticSilentRefresh();
46-
});
47-
// this.oauthService.loadDiscoveryDocument().then(doc => {
48-
// if (!environment.production)
49-
// console.log(doc);
50-
// this.oauthService.tryLogin();
51-
// });
42+
this.authService.runInitialLoginSequence();
5243
}
5344

45+
5446
ngOnInit() {
5547
$(document).on("click", "[href=\"#\"]", e => e.preventDefault());
5648
}

src/Frontend/Jp.AdminUI/src/app/app.module.ts

Lines changed: 2 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ import { CoreModule } from "./core/core.module";
1111
import { LayoutModule } from "./shared/layout/layout.module";
1212
import { SharedModule } from "./shared/shared.module";
1313
import { RoutesModule } from "./app.routing.module";
14-
import { AuthInterceptor } from "./core/interceptors/auth.interceptor";
1514
import { OAuthModule } from "angular-oauth2-oidc";
1615
import { environment } from "../environments/environment";
1716

@@ -20,25 +19,7 @@ export function createTranslateLoader(http: HttpClient) {
2019
return new TranslateHttpLoader(http, "./assets/i18n/", ".json");
2120
}
2221

23-
// import dev only modules
24-
let dev = [
25-
{
26-
provide: HTTP_INTERCEPTORS,
27-
useClass: AuthInterceptor,
28-
multi: true
29-
}
30-
];
31-
let INTERCEPTORS = [
32-
{
33-
provide: HTTP_INTERCEPTORS,
34-
useClass: AuthInterceptor,
35-
multi: true
36-
}
37-
];
38-
// if production clear dev imports and set to prod mode
39-
if (process.env.NODE_ENV === "production") {
40-
dev = [];
41-
}
22+
4223

4324
@NgModule({
4425
declarations: [
@@ -47,13 +28,7 @@ if (process.env.NODE_ENV === "production") {
4728
imports: [
4829
HttpClientModule,
4930
BrowserAnimationsModule, // required for ng2-tag-input
50-
OAuthModule.forRoot({
51-
resourceServer: {
52-
allowedUrls: [ environment.ResourceServer],
53-
sendAccessToken: true
54-
}
55-
}),
56-
CoreModule,
31+
CoreModule.forRoot(),
5732
LayoutModule,
5833
SharedModule.forRoot(),
5934
RoutesModule,
@@ -66,8 +41,6 @@ if (process.env.NODE_ENV === "production") {
6641
})
6742
],
6843
providers: [
69-
...dev,
70-
...INTERCEPTORS
7144
],
7245
bootstrap: [AppComponent]
7346
})
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
import { AuthConfig } from 'angular-oauth2-oidc';
2+
import { environment } from '@env/environment';
3+
4+
export const authConfig: AuthConfig = {
5+
issuer: environment.IssuerUri,
6+
clientId: 'IS4-Admin',
7+
redirectUri: environment.Uri + "/login-callback",
8+
silentRefreshRedirectUri: environment.Uri + '/silent-refresh.html',
9+
scope: "openid profile email jp_api.is4",
10+
silentRefreshTimeout: 5000, // For faster testing
11+
timeoutFactor: 0.25, // For faster testing
12+
sessionChecksEnabled: true,
13+
showDebugInformation: true, // Also requires enabling "Verbose" level in devtools
14+
clearHashAfterLogin: false, // https://github.com/manfredsteyer/angular-oauth2-oidc/issues/457#issuecomment-431807040
15+
};
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
import { Injectable } from '@angular/core';
2+
import { ActivatedRouteSnapshot, CanActivate, RouterStateSnapshot } from '@angular/router';
3+
import { Observable } from 'rxjs';
4+
import { filter, map, tap } from 'rxjs/operators';
5+
6+
import { AuthService } from './auth.service';
7+
8+
@Injectable()
9+
export class AuthGuardWithForcedLogin implements CanActivate {
10+
private isAuthenticated: boolean;
11+
12+
constructor(
13+
private authService: AuthService,
14+
) {
15+
this.authService.isAuthenticated$.subscribe(i => this.isAuthenticated = i);
16+
}
17+
18+
canActivate(
19+
route: ActivatedRouteSnapshot,
20+
state: RouterStateSnapshot,
21+
): Observable<boolean> {
22+
return this.authService.isDoneLoading$
23+
.pipe(filter(isDone => isDone))
24+
.pipe(tap(_ => this.isAuthenticated || this.authService.login(state.url)))
25+
.pipe(map(_ => this.isAuthenticated));
26+
}
27+
}
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
import { Injectable } from '@angular/core';
2+
import { ActivatedRouteSnapshot, CanActivate, RouterStateSnapshot } from '@angular/router';
3+
import { Observable } from 'rxjs';
4+
import { tap } from 'rxjs/operators';
5+
6+
import { AuthService } from './auth.service';
7+
8+
@Injectable()
9+
export class AuthGuard implements CanActivate {
10+
constructor(
11+
private authService: AuthService,
12+
) { }
13+
14+
canActivate(
15+
route: ActivatedRouteSnapshot,
16+
state: RouterStateSnapshot,
17+
): Observable<boolean> {
18+
return this.authService.canActivateProtectedRoutes$
19+
.pipe(tap(x => console.log('You tried to go to ' + state.url + ' and this guard said ' + x)));
20+
}
21+
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
import { OAuthModuleConfig } from 'angular-oauth2-oidc';
2+
import { environment } from '@env/environment';
3+
4+
export const authModuleConfig: OAuthModuleConfig = {
5+
resourceServer: {
6+
allowedUrls: [environment.ResourceServer],
7+
sendAccessToken: true
8+
}
9+
};
Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
1-
import { AuthConfig } from "angular-oauth2-oidc";
2-
import { environment } from "@env/environment";
3-
export const authConfig: AuthConfig = {
4-
issuer: environment.IssuerUri,
5-
requireHttps: environment.RequireHttps,
6-
clientId: "IS4-Admin",
7-
postLogoutRedirectUri: environment.Uri,
8-
redirectUri: environment.Uri + "/login-callback",
9-
silentRefreshRedirectUri: environment.Uri + '/silent-refresh.html',
10-
scope: "openid profile email jp_api.is4",
11-
oidc: true,
12-
};
1+
// import { AuthConfig } from "angular-oauth2-oidc";
2+
// import { environment } from "@env/environment";
3+
// export const authConfig: AuthConfig = {
4+
// issuer: environment.IssuerUri,
5+
// requireHttps: environment.RequireHttps,
6+
// clientId: "IS4-Admin",
7+
// postLogoutRedirectUri: environment.Uri,
8+
// redirectUri: environment.Uri + "/login-callback",
9+
// silentRefreshRedirectUri: environment.Uri + '/silent-refresh.html',
10+
// scope: "openid profile email jp_api.is4",
11+
// oidc: true,
12+
// };

0 commit comments

Comments
 (0)