From afe91148602ca37351add295938569940141b0dd Mon Sep 17 00:00:00 2001 From: Jim Schaff Date: Sat, 27 Apr 2024 19:18:31 -0400 Subject: [PATCH] redirect browser login to webapp /login_success page --- .../restclient/auth/InteractiveLogin.java | 16 +++++++++---- webapp-ng/src/app/app-routing.module.ts | 6 +++++ .../login-success/login-success.component.css | 0 .../login-success.component.html | 4 ++++ .../login-success.component.spec.ts | 23 +++++++++++++++++++ .../login-success/login-success.component.ts | 13 +++++++++++ 6 files changed, 58 insertions(+), 4 deletions(-) create mode 100644 webapp-ng/src/app/pages/login-success/login-success.component.css create mode 100644 webapp-ng/src/app/pages/login-success/login-success.component.html create mode 100644 webapp-ng/src/app/pages/login-success/login-success.component.spec.ts create mode 100644 webapp-ng/src/app/pages/login-success/login-success.component.ts diff --git a/vcell-restclient/src/main/java/org/vcell/restclient/auth/InteractiveLogin.java b/vcell-restclient/src/main/java/org/vcell/restclient/auth/InteractiveLogin.java index 2e013a6495..1c48abde25 100644 --- a/vcell-restclient/src/main/java/org/vcell/restclient/auth/InteractiveLogin.java +++ b/vcell-restclient/src/main/java/org/vcell/restclient/auth/InteractiveLogin.java @@ -27,9 +27,12 @@ public class InteractiveLogin { private InteractiveLogin() { } - - public static AuthApiClient login(String clientID, URI authServerUri, URI apiBaseUri) throws URISyntaxException, IOException, ParseException { + URI successRedirectURI = new URI(apiBaseUri+"/login_success"); + return login(clientID, authServerUri, apiBaseUri, successRedirectURI); + } + + public static AuthApiClient login(String clientID, URI authServerUri, URI apiBaseUri, URI successRedirectURI) throws URISyntaxException, IOException, ParseException { // Retrieve OpenID Provider Metadata URI metadata_endpoint = new URI(authServerUri + "/.well-known/openid-configuration"); @@ -53,7 +56,7 @@ public static AuthApiClient login(String clientID, URI authServerUri, URI apiBas if (Desktop.isDesktopSupported() && Desktop.getDesktop().isSupported(Desktop.Action.BROWSE)) { // set up web server to receive redirect and send URL to system browser - will be redirected back to http://localhost:9999/oidc_test_callback System.out.println("launched browser with login window, will intercept the authentication response sent to local web server"); - authorizationResponse = getAuthorizationResponseAutomated(localHttpServerPort, callback_endpoint_path, authRequestURI); + authorizationResponse = getAuthorizationResponseAutomated(localHttpServerPort, callback_endpoint_path, authRequestURI, successRedirectURI); } else { // manual copy/paste of redirect URL into browser, and copy/paste of redirect URL back into console authorizationResponse = getAuthorizationResponseManual(authRequestURI); @@ -82,7 +85,7 @@ private static AuthorizationResponse getAuthorizationResponseManual(URI authRequ return authorizationResponse; } - private static AuthorizationResponse getAuthorizationResponseAutomated(int localHttpServerPort, String callback_endpoint_path, URI authRequestURI) throws IOException, ParseException { + private static AuthorizationResponse getAuthorizationResponseAutomated(int localHttpServerPort, String callback_endpoint_path, URI authRequestURI, URI successRedirectURI) throws IOException, ParseException { AuthorizationResponse authorizationResponse; final BlockingQueue authorizationCodeURIQueue = new LinkedBlockingQueue<>(1); @@ -100,6 +103,11 @@ private static AuthorizationResponse getAuthorizationResponseAutomated(int local System.out.println("received redirect URI with authorization code from web server"); authorizationCodeURIQueue.add(exchange.getRequestURI().toString()); System.out.println("added redirect URI to queue"); + // redirect the user to https://vcellapi-test.cam.uchc.edu with a 303 status + exchange.getResponseHeaders().add("Location", String.valueOf(successRedirectURI)); + //exchange.getResponseHeaders().add("Location", "https://vcellapi-test.cam.uchc.edu/login_success"); + exchange.sendResponseHeaders(303, -1); + exchange.close(); }); httpServer.setExecutor(null); diff --git a/webapp-ng/src/app/app-routing.module.ts b/webapp-ng/src/app/app-routing.module.ts index cc88af6c86..fc8a1b5f14 100644 --- a/webapp-ng/src/app/app-routing.module.ts +++ b/webapp-ng/src/app/app-routing.module.ts @@ -5,6 +5,7 @@ import { ProfileComponent } from './pages/profile/profile.component'; import { ErrorComponent } from './pages/error/error.component'; import { AuthGuard } from '@auth0/auth0-angular'; import { PublicationListComponent } from './components/publication-list/publication-list.component'; +import {LoginSuccessComponent} from "./pages/login-success/login-success.component"; const routes: Routes = [ { @@ -26,6 +27,11 @@ const routes: Routes = [ component: HomeComponent, pathMatch: 'full', }, + { + path: 'login_success', + component: LoginSuccessComponent, + canActivate: [AuthGuard], + }, ]; @NgModule({ diff --git a/webapp-ng/src/app/pages/login-success/login-success.component.css b/webapp-ng/src/app/pages/login-success/login-success.component.css new file mode 100644 index 0000000000..e69de29bb2 diff --git a/webapp-ng/src/app/pages/login-success/login-success.component.html b/webapp-ng/src/app/pages/login-success/login-success.component.html new file mode 100644 index 0000000000..184a3e41cb --- /dev/null +++ b/webapp-ng/src/app/pages/login-success/login-success.component.html @@ -0,0 +1,4 @@ +
+

Login Successful!

+

You have successfully logged in. Welcome!

+
diff --git a/webapp-ng/src/app/pages/login-success/login-success.component.spec.ts b/webapp-ng/src/app/pages/login-success/login-success.component.spec.ts new file mode 100644 index 0000000000..ae6bb68b7f --- /dev/null +++ b/webapp-ng/src/app/pages/login-success/login-success.component.spec.ts @@ -0,0 +1,23 @@ +import { ComponentFixture, TestBed } from '@angular/core/testing'; + +import { LoginSuccessComponent } from './login-success.component'; + +describe('LoginSuccessComponent', () => { + let component: LoginSuccessComponent; + let fixture: ComponentFixture; + + beforeEach(async () => { + await TestBed.configureTestingModule({ + imports: [LoginSuccessComponent] + }) + .compileComponents(); + + fixture = TestBed.createComponent(LoginSuccessComponent); + component = fixture.componentInstance; + fixture.detectChanges(); + }); + + it('should create', () => { + expect(component).toBeTruthy(); + }); +}); diff --git a/webapp-ng/src/app/pages/login-success/login-success.component.ts b/webapp-ng/src/app/pages/login-success/login-success.component.ts new file mode 100644 index 0000000000..41c737cca3 --- /dev/null +++ b/webapp-ng/src/app/pages/login-success/login-success.component.ts @@ -0,0 +1,13 @@ +import { Component } from '@angular/core'; +import { CommonModule } from '@angular/common'; + +@Component({ + selector: 'app-login-success', + standalone: true, + imports: [CommonModule], + templateUrl: './login-success.component.html', + styleUrl: './login-success.component.css' +}) +export class LoginSuccessComponent { + +}