Merge pull request #7317 from jwangyangls/oidcRedirectToHarbor

Add OIDC onboard page redirect to Harbor url when we login from OIDC
This commit is contained in:
jwangyangls 2019-04-09 10:04:35 +08:00 committed by GitHub
commit a8ff6aa934
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 21 additions and 14 deletions

View File

@ -3,7 +3,7 @@
<form #signInForm="ngForm" class="login"> <form #signInForm="ngForm" class="login">
<label class="title"> {{customAppTitle? customAppTitle:(appTitle | translate)}} <label class="title"> {{customAppTitle? customAppTitle:(appTitle | translate)}}
</label> </label>
<a href="/c/oidc/login" class="login-oidc"> <a href="/c/oidc/login" class="login-oidc" *ngIf="isOidcLoginMode">
<button type="button" id="log_oidc" class="btn btn-primary btn-block"> <button type="button" id="log_oidc" class="btn btn-primary btn-block">
<span>{{'BUTTON.LOG_IN_OIDC' | translate }}</span> <span>{{'BUTTON.LOG_IN_OIDC' | translate }}</span>
</button> </button>

View File

@ -60,6 +60,6 @@
background:transparent; background:transparent;
} }
} }
.title{ .login-oidc{
margin-bottom: 50px; margin-top: 50px;
} }

View File

@ -141,11 +141,12 @@ export class SignInComponent implements AfterViewChecked, OnInit {
return this.appConfig.auth_mode === 'db_auth' return this.appConfig.auth_mode === 'db_auth'
&& this.appConfig.self_registration; && this.appConfig.self_registration;
} }
public get isOidcLoginMode(): boolean {
return this.appConfig.auth_mode === 'oidc_auth';
}
public get showForgetPwd(): boolean { public get showForgetPwd(): boolean {
return this.appConfig.auth_mode !== 'ldap_auth' && this.appConfig.auth_mode !== 'uaa_auth'; return this.appConfig.auth_mode !== 'ldap_auth' && this.appConfig.auth_mode !== 'uaa_auth';
} }
clickRememberMe($event: any): void { clickRememberMe($event: any): void {
if ($event && $event.target) { if ($event && $event.target) {
this.rememberMe = $event.target.checked; this.rememberMe = $event.target.checked;

View File

@ -14,7 +14,8 @@
import { Component, Output, EventEmitter, OnInit } from '@angular/core'; import { Component, Output, EventEmitter, OnInit } from '@angular/core';
import { Router, NavigationExtras } from '@angular/router'; import { Router, NavigationExtras } from '@angular/router';
import { TranslateService } from '@ngx-translate/core'; import { TranslateService } from '@ngx-translate/core';
// import { map } from 'rxjs/operators';
import { PlatformLocation } from '@angular/common';
import { ModalEvent } from '../modal-event'; import { ModalEvent } from '../modal-event';
import { modalEvents } from '../modal-events.const'; import { modalEvents } from '../modal-events.const';
@ -25,7 +26,7 @@ import { supportedLangs, enLang, languageNames, CommonRoutes } from '../../share
import { AppConfigService } from '../../app-config.service'; import { AppConfigService } from '../../app-config.service';
import { SearchTriggerService } from '../global-search/search-trigger.service'; import { SearchTriggerService } from '../global-search/search-trigger.service';
import { MessageHandlerService } from '../../shared/message-handler/message-handler.service'; import { MessageHandlerService } from '../../shared/message-handler/message-handler.service';
import {SkinableConfig} from "../../skinable-config.service"; import { SkinableConfig } from "../../skinable-config.service";
@Component({ @Component({
selector: 'navigator', selector: 'navigator',
@ -40,12 +41,13 @@ export class NavigatorComponent implements OnInit {
selectedLang: string = enLang; selectedLang: string = enLang;
appTitle: string = 'APP_TITLE.HARBOR'; appTitle: string = 'APP_TITLE.HARBOR';
customStyle: {[key: string]: any}; customStyle: { [key: string]: any };
customProjectName: {[key: string]: any}; customProjectName: { [key: string]: any };
constructor( constructor(
private session: SessionService, private session: SessionService,
private router: Router, private router: Router,
private location: PlatformLocation,
private translate: TranslateService, private translate: TranslateService,
private cookie: CookieService, private cookie: CookieService,
private appConfigService: AppConfigService, private appConfigService: AppConfigService,
@ -65,10 +67,10 @@ export class NavigatorComponent implements OnInit {
} }
this.selectedLang = this.translate.currentLang; this.selectedLang = this.translate.currentLang;
this.translate.onLangChange.subscribe((langChange: {lang: string}) => { this.translate.onLangChange.subscribe((langChange: { lang: string }) => {
this.selectedLang = langChange.lang; this.selectedLang = langChange.lang;
// Keep in cookie for next use // Keep in cookie for next use
let opt: CookieOptions = {path: '/', expires: new Date(Date.now() + 3600 * 1000 * 24 * 31)}; let opt: CookieOptions = { path: '/', expires: new Date(Date.now() + 3600 * 1000 * 24 * 31) };
this.cookie.put("harbor-lang", langChange.lang, opt); this.cookie.put("harbor-lang", langChange.lang, opt);
}); });
if (this.appConfigService.isIntegrationMode()) { if (this.appConfigService.isIntegrationMode()) {
@ -147,8 +149,10 @@ export class NavigatorComponent implements OnInit {
logOut(): void { logOut(): void {
// Naviagte to the sign in route // Naviagte to the sign in route
// Appending 'signout' means destroy session cache // Appending 'signout' means destroy session cache
let signout = true;
let redirect_url = this.location.pathname;
let navigatorExtra: NavigationExtras = { let navigatorExtra: NavigationExtras = {
queryParams: { "signout": true } queryParams: {signout, redirect_url}
}; };
this.router.navigate([CommonRoutes.EMBEDDED_SIGN_IN], navigatorExtra); this.router.navigate([CommonRoutes.EMBEDDED_SIGN_IN], navigatorExtra);
// Confirm search result panel is close // Confirm search result panel is close

View File

@ -28,7 +28,9 @@ export class OidcOnboardComponent implements OnInit {
}); });
} }
clickSaveBtn(): void { clickSaveBtn(): void {
this.oidcOnboardService.oidcSave({ username: this.oidcUsername.value }).subscribe(res => { } this.oidcOnboardService.oidcSave({ username: this.oidcUsername.value }).subscribe(res => {
this.router.navigate([CommonRoutes.HARBOR_DEFAULT]);
}
, error => { , error => {
this.errorMessage = errorHandler(error); this.errorMessage = errorHandler(error);
this.errorOpen = true; this.errorOpen = true;