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">
<label class="title"> {{customAppTitle? customAppTitle:(appTitle | translate)}}
</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">
<span>{{'BUTTON.LOG_IN_OIDC' | translate }}</span>
</button>

View File

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

View File

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

View File

@ -14,7 +14,8 @@
import { Component, Output, EventEmitter, OnInit } from '@angular/core';
import { Router, NavigationExtras } from '@angular/router';
import { TranslateService } from '@ngx-translate/core';
// import { map } from 'rxjs/operators';
import { PlatformLocation } from '@angular/common';
import { ModalEvent } from '../modal-event';
import { modalEvents } from '../modal-events.const';
@ -25,7 +26,7 @@ import { supportedLangs, enLang, languageNames, CommonRoutes } from '../../share
import { AppConfigService } from '../../app-config.service';
import { SearchTriggerService } from '../global-search/search-trigger.service';
import { MessageHandlerService } from '../../shared/message-handler/message-handler.service';
import {SkinableConfig} from "../../skinable-config.service";
import { SkinableConfig } from "../../skinable-config.service";
@Component({
selector: 'navigator',
@ -40,12 +41,13 @@ export class NavigatorComponent implements OnInit {
selectedLang: string = enLang;
appTitle: string = 'APP_TITLE.HARBOR';
customStyle: {[key: string]: any};
customProjectName: {[key: string]: any};
customStyle: { [key: string]: any };
customProjectName: { [key: string]: any };
constructor(
private session: SessionService,
private router: Router,
private location: PlatformLocation,
private translate: TranslateService,
private cookie: CookieService,
private appConfigService: AppConfigService,
@ -65,10 +67,10 @@ export class NavigatorComponent implements OnInit {
}
this.selectedLang = this.translate.currentLang;
this.translate.onLangChange.subscribe((langChange: {lang: string}) => {
this.translate.onLangChange.subscribe((langChange: { lang: string }) => {
this.selectedLang = langChange.lang;
// 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);
});
if (this.appConfigService.isIntegrationMode()) {
@ -112,7 +114,7 @@ export class NavigatorComponent implements OnInit {
let config = this.appConfigService.getConfig();
return user && ((config && !(config.auth_mode === "ldap_auth" || config.auth_mode === "uaa_auth")) ||
(user.user_id === 1 && user.username === "admin"));
(user.user_id === 1 && user.username === "admin"));
}
matchLang(lang: string): boolean {
@ -147,8 +149,10 @@ export class NavigatorComponent implements OnInit {
logOut(): void {
// Naviagte to the sign in route
// Appending 'signout' means destroy session cache
let signout = true;
let redirect_url = this.location.pathname;
let navigatorExtra: NavigationExtras = {
queryParams: { "signout": true }
queryParams: {signout, redirect_url}
};
this.router.navigate([CommonRoutes.EMBEDDED_SIGN_IN], navigatorExtra);
// Confirm search result panel is close

View File

@ -28,7 +28,9 @@ export class OidcOnboardComponent implements OnInit {
});
}
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 => {
this.errorMessage = errorHandler(error);
this.errorOpen = true;