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

Commit 381e43f

Browse files
committed
Minor bugs fix
- Fixed oidc flow
1 parent eaea079 commit 381e43f

File tree

20 files changed

+137
-80
lines changed

20 files changed

+137
-80
lines changed
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
import { AuthConfig } from 'angular-oauth2-oidc';
2+
import { environment } from '@env/environment';
3+
4+
export const authProdConfig: 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+
sessionChecksEnabled: true,
11+
clearHashAfterLogin: false, // https://github.com/manfredsteyer/angular-oauth2-oidc/issues/457#issuecomment-431807040
12+
};

src/Frontend/Jp.AdminUI/src/app/core/auth/auth.service.ts

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import { Router } from '@angular/router';
33
import { OAuthErrorEvent, OAuthService } from 'angular-oauth2-oidc';
44
import { BehaviorSubject, combineLatest, Observable, ReplaySubject } from 'rxjs';
55
import { filter, map } from 'rxjs/operators';
6+
import { environment } from '@env/environment.prod';
67

78
@Injectable({ providedIn: 'root' })
89
export class AuthService {
@@ -38,13 +39,14 @@ export class AuthService {
3839
private router: Router,
3940
) {
4041
// Useful for debugging:
41-
this.oauthService.events.subscribe(event => {
42-
if (event instanceof OAuthErrorEvent) {
43-
console.error(event);
44-
} else {
45-
console.warn(event);
46-
}
47-
});
42+
if (!environment.production)
43+
this.oauthService.events.subscribe(event => {
44+
if (event instanceof OAuthErrorEvent) {
45+
console.error(event);
46+
} else {
47+
console.warn(event);
48+
}
49+
});
4850

4951
// This is tricky, as it might cause race conditions (where access_token is set in another
5052
// tab before everything is said and done there.
@@ -80,7 +82,6 @@ export class AuthService {
8082
}
8183

8284
public runInitialLoginSequence(): Promise<void> {
83-
this.oauthService.setStorage(localStorage);
8485

8586
if (location.hash) {
8687
console.log('Encountered hash fragment, plotting as table...');

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

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,14 @@ import { HttpClientModule } from "@angular/common/http";
1212
import { authModuleConfig } from "./auth/auth-module-config";
1313
import { AuthGuard } from "./auth/auth-guard.service";
1414
import { authConfig } from "./auth/auth-config";
15+
import { authProdConfig } from "./auth/auth-config.prod";
16+
import { environment } from "@env/environment";
1517

1618
export function storageFactory(): OAuthStorage {
1719
return localStorage;
1820
}
1921

22+
2023
@NgModule({
2124
imports: [
2225
HttpClientModule,
@@ -41,7 +44,7 @@ export class CoreModule {
4144
return {
4245
ngModule: CoreModule,
4346
providers: [
44-
{ provide: AuthConfig, useValue: authConfig },
47+
{ provide: AuthConfig, useValue: authProdConfig },
4548
{ provide: OAuthModuleConfig, useValue: authModuleConfig },
4649
{ provide: ValidationHandler, useClass: JwksValidationHandler },
4750
{ provide: OAuthStorage, useFactory: storageFactory },

src/Frontend/Jp.AdminUI/src/app/core/settings/settings.service.ts

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -68,10 +68,6 @@ export class SettingsService {
6868

6969
}
7070

71-
public logout() {
72-
this.oauthService.logOut();
73-
}
74-
7571
public getUserProfile(): Observable<object> {
7672
if (this.user == null) {
7773
return this.userProfileObservable;
Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,33 @@
1-
import { Component, OnInit } from "@angular/core";
1+
import { Component, OnInit, OnDestroy } from "@angular/core";
22
import { Router } from "@angular/router";
33
import { SettingsService } from "../../core/settings/settings.service";
44
import { AuthService } from "@core/auth/auth.service";
5-
import { tap } from "rxjs/operators";
5+
import { Subscription } from "rxjs";
66

77
@Component({
88
selector: "app-login-callback",
99
templateUrl: "login-callback.component.html",
1010
styleUrls: ["./login-callback.component.scss"],
1111
})
12-
export class LoginCallbackComponent implements OnInit {
12+
export class LoginCallbackComponent implements OnInit, OnDestroy {
13+
stream: Subscription;
1314

1415
constructor(
1516
private authService: AuthService,
1617
private router: Router,
1718
public settingsService: SettingsService) { }
1819

19-
ngOnInit() {
20-
this.authService.canActivateProtectedRoutes$
21-
.subscribe(yes => {
22-
if (yes)
23-
return this.router.navigate(['/home']);
24-
});
20+
21+
public ngOnInit() {
22+
this.stream = this.authService.canActivateProtectedRoutes$.subscribe(yes => {
23+
if (yes)
24+
return this.router.navigate(['/home']);
25+
else
26+
return this.router.navigate(['/login']);
27+
});
28+
}
29+
30+
public ngOnDestroy() {
31+
this.stream.unsubscribe();
2532
}
2633
}
Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,36 @@
1-
import { Component, OnInit } from "@angular/core";
1+
import { Component, OnInit, OnDestroy } from "@angular/core";
22
import { SettingsService } from "../../core/settings/settings.service";
33
import { Router } from "@angular/router";
44
import { AuthService } from "@core/auth/auth.service";
5-
5+
import { Subscription } from "rxjs";
66

77

88
@Component({
99
selector: "app-login",
1010
templateUrl: "./login.component.html",
1111
styleUrls: ["./login.component.scss"],
1212
})
13-
export class LoginComponent implements OnInit {
13+
export class LoginComponent implements OnInit, OnDestroy {
14+
private stream: Subscription;
15+
1416
constructor(public settingsService: SettingsService,
1517
private authService: AuthService,
1618
private router: Router) {
1719

1820
}
1921

2022
public ngOnInit() {
21-
this.authService.isAuthenticated$.subscribe(yes => {
22-
if (!yes)
23-
this.login();
23+
this.stream = this.authService.canActivateProtectedRoutes$.subscribe(yes => {
24+
if (yes)
25+
this.router.navigate(['/home']);
26+
else
27+
this.authService.login('/login-callback');
2428
});
2529
}
2630

27-
public login() {
28-
this.authService.login('/login-callback');
31+
public ngOnDestroy() {
32+
this.stream.unsubscribe();
2933
}
3034

35+
public login() { this.authService.login('/login-callback'); }
3136
}

src/Frontend/Jp.AdminUI/src/app/shared/layout/header/header.component.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import { SettingsService } from "@core/settings/settings.service";
88
import { MenuService } from "@core/menu/menu.service";
99
import { Router } from "@angular/router";
1010
import { environment } from "@env/environment";
11+
import { AuthService } from "@core/auth/auth.service";
1112

1213
@Component({
1314
selector: "app-header",
@@ -28,6 +29,7 @@ export class HeaderComponent implements OnInit {
2829
public menu: MenuService,
2930
public userblockService: UserblockService,
3031
public settings: SettingsService,
32+
public authService: AuthService,
3133
private router: Router) {
3234
// show only a few items on demo
3335
this.menuItems = menu.getMenu().slice(0, 4); // for horizontal layout
@@ -43,7 +45,7 @@ export class HeaderComponent implements OnInit {
4345
}
4446

4547
public async logout() {
46-
await this.settings.logout();
48+
await this.authService.logout();
4749
}
4850

4951
toggleUserBlock(event) {
Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
export const environment = {
22
production: true,
3-
ResourceServer: "https://jpproject.azurewebsites.net/api/",
4-
IssuerUri: "https://jpproject.azurewebsites.net/sso",
3+
ResourceServer: "https://accounts.allto.com.br/api/",
4+
IssuerUri: "https://accounts.allto.com.br/sso",
55
RequireHttps: true,
6-
Uri: "https://jpproject.azurewebsites.net/admin-ui"
6+
Uri: "https://accounts.allto.com.br/admin-ui"
77
};

src/Frontend/Jp.UI.SSO/Util/Clients.cs

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
using IdentityServer4;
1+
using System;
2+
using IdentityServer4;
23
using IdentityServer4.Models;
34
using Microsoft.Extensions.Configuration;
45
using System.Collections.Generic;
@@ -25,7 +26,10 @@ public static IEnumerable<Client> GetAdminClient(IConfiguration configuration)
2526
ClientUri = configuration.GetValue<string>("ApplicationSettings:IS4AdminUi"),
2627
AllowedGrantTypes = GrantTypes.Implicit,
2728
AllowAccessTokensViaBrowser = true,
28-
RedirectUris = { $"{configuration.GetValue<string>("ApplicationSettings:IS4AdminUi")}/login-callback"},
29+
RedirectUris = new[] {
30+
$"{configuration.GetValue<string>("ApplicationSettings:IS4AdminUi")}/login-callback",
31+
$"{configuration.GetValue<string>("ApplicationSettings:IS4AdminUi")}/silent-refresh.html"
32+
},
2933
AllowedCorsOrigins = { configuration.GetValue<string>("ApplicationSettings:IS4AdminUi")},
3034
IdentityTokenLifetime = 3600,
3135
AuthorizationCodeLifetime = 3600,
@@ -48,7 +52,10 @@ public static IEnumerable<Client> GetAdminClient(IConfiguration configuration)
4852
AllowedGrantTypes = GrantTypes.Implicit,
4953
AllowAccessTokensViaBrowser = true,
5054
RequireConsent = true,
51-
RedirectUris = { $"{configuration.GetValue<string>("ApplicationSettings:UserManagementURL")}/login-callback" },
55+
RedirectUris =new[] {
56+
$"{configuration.GetValue<string>("ApplicationSettings:UserManagementURL")}/login-callback",
57+
$"{configuration.GetValue<string>("ApplicationSettings:UserManagementURL")}/silent-refresh.html"
58+
},
5259
PostLogoutRedirectUris = { $"{configuration.GetValue<string>("ApplicationSettings:UserManagementURL")}" },
5360
AllowedCorsOrigins = { $"{configuration.GetValue<string>("ApplicationSettings:UserManagementURL")}" },
5461
LogoUri = "~/images/clientLogo/1.jpg",
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
import { AuthConfig } from 'angular-oauth2-oidc';
2+
import { environment } from '@env/environment';
3+
4+
export const authProdConfig: AuthConfig = {
5+
issuer: environment.AuthorityUri,
6+
clientId: "UserManagementUI",
7+
redirectUri: environment.Uri + "/login-callback",
8+
silentRefreshRedirectUri: environment.Uri + '/silent-refresh.html',
9+
scope: "openid profile email jp_api.user",
10+
sessionChecksEnabled: true,
11+
clearHashAfterLogin: false, // https://github.com/manfredsteyer/angular-oauth2-oidc/issues/457#issuecomment-431807040
12+
};

0 commit comments

Comments
 (0)