Skip to content

Commit

Permalink
redirect browser login to webapp /login_success page
Browse files Browse the repository at this point in the history
  • Loading branch information
jcschaff committed Apr 27, 2024
1 parent b67c799 commit afe9114
Show file tree
Hide file tree
Showing 6 changed files with 58 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand All @@ -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);
Expand Down Expand Up @@ -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<String> authorizationCodeURIQueue = new LinkedBlockingQueue<>(1);

Expand All @@ -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);
Expand Down
6 changes: 6 additions & 0 deletions webapp-ng/src/app/app-routing.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 = [
{
Expand All @@ -26,6 +27,11 @@ const routes: Routes = [
component: HomeComponent,
pathMatch: 'full',
},
{
path: 'login_success',
component: LoginSuccessComponent,
canActivate: [AuthGuard],
},
];

@NgModule({
Expand Down
Empty file.
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
<div class="container">
<h1>Login Successful!</h1>
<p>You have successfully logged in. Welcome!</p>
</div>
Original file line number Diff line number Diff line change
@@ -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<LoginSuccessComponent>;

beforeEach(async () => {
await TestBed.configureTestingModule({
imports: [LoginSuccessComponent]
})
.compileComponents();

fixture = TestBed.createComponent(LoginSuccessComponent);
component = fixture.componentInstance;
fixture.detectChanges();
});

it('should create', () => {
expect(component).toBeTruthy();
});
});
13 changes: 13 additions & 0 deletions webapp-ng/src/app/pages/login-success/login-success.component.ts
Original file line number Diff line number Diff line change
@@ -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 {

}

0 comments on commit afe9114

Please sign in to comment.