Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion src/app/app.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,14 @@ import { provideHttpClient, withInterceptorsFromDi } from '@angular/common/http'
import { MainComponent } from './main/main.component';
import {AMA_ENDPOINT, BACKEND_URL, FRONTEND_URL} from "./tokens";
import {environment} from "../environments/environment";
import { FormsModule } from '@angular/forms';

@NgModule({ declarations: [
AppComponent,
MainComponent
],
bootstrap: [AppComponent], imports: [BrowserModule,
AppRoutingModule], providers: [
AppRoutingModule, FormsModule], providers: [
{ provide: FRONTEND_URL, useValue: new URL(environment.frontendUrl) },
{ provide: BACKEND_URL, useValue: new URL(environment.backendUrl) },
{ provide: AMA_ENDPOINT, useValue: new URL(environment.amaUrl + environment.amaConsentPath) },
Expand Down
1 change: 1 addition & 0 deletions src/app/helper/url-helper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -88,4 +88,5 @@ export class UrlHelper {
endpoint.searchParams.set('redirectUrl', this.getFrontendEndpoint().href)
return endpoint;
}

}
4 changes: 4 additions & 0 deletions src/app/main/main.component.html
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,14 @@
<button [disabled]="!sessionInformation?.isLoggedIn" (click)="writeDataset()">Write data to Pod</button>
<button [disabled]="!sessionInformation?.isLoggedIn" (click)="readDataset()">Read data from Pod</button>
<button [disabled]="!sessionInformation?.isLoggedIn" (click)="retrieveAccessGrants()">Retrieve access grants</button>
<button [disabled]="!sessionInformation?.isLoggedIn" (click)="redirect()">Redirect to other application</button>
<button [disabled]="!sessionInformation?.isLoggedIn" (click)="logout()">Log out</button>
<!-- <button [disabled]="!sessionInformation?.isLoggedIn" (click)="deletePod()">Delete pod</button>-->
<!-- <button [disabled]="!sessionInformation?.isLoggedIn" (click)="emptyPod()">Empty pod</button>-->
</div>
<div>
<input type="text" [(ngModel)]="redirectUrl">
</div>

<div id="session-information">
<div *ngIf="sessionInformation?.isLoggedIn">
Expand Down
76 changes: 67 additions & 9 deletions src/app/main/main.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@
* Main component of the application, providing user interactions and managing sessions.
*/

import { Component, OnInit } from '@angular/core';
import { PodService } from 'src/app/services/pod.service';
import { ActivatedRoute } from '@angular/router';
import { filter, firstValueFrom } from 'rxjs';
import {Component, Inject, OnInit} from '@angular/core';
import {PodService} from 'src/app/services/pod.service';
import {ActivatedRoute} from '@angular/router';
import {filter, firstValueFrom} from 'rxjs';
import {
addStringNoLocale,
addUrl,
Expand All @@ -14,11 +14,13 @@ import {
setThing,
solidDatasetAsTurtle
} from "@inrupt/solid-client";
import { SessionService } from "../services/session.service";
import { SessionInformation } from "../interface/session-information";
import { UrlHelper } from "../helper/url-helper";
import { VcService } from "../services/vc.service";
import {SessionService} from "../services/session.service";
import {SessionInformation} from "../interface/session-information";
import {UrlHelper} from "../helper/url-helper";
import {VcService} from "../services/vc.service";
import {AccessGrant} from "@inrupt/solid-client-access-grants";
import {BACKEND_URL} from "../tokens";
import {HttpClient} from "@angular/common/http";

@Component({
selector: 'app-main',
Expand All @@ -28,6 +30,8 @@ import {AccessGrant} from "@inrupt/solid-client-access-grants";
})
export class MainComponent implements OnInit {

redirectUrl = "http://localhost:4201/redirect";

/** Session information about the current user */
sessionInformation?: SessionInformation;

Expand All @@ -39,7 +43,14 @@ export class MainComponent implements OnInit {

accessGrants?: AccessGrant[];

constructor(private sessionService: SessionService, private podService: PodService, private vcService: VcService, private urlHelper: UrlHelper, private route: ActivatedRoute) { }
constructor(private sessionService: SessionService,
private podService: PodService,
private vcService: VcService,
private urlHelper: UrlHelper,
private route: ActivatedRoute,
private http: HttpClient,
@Inject(BACKEND_URL) private backendUrl: URL) {
}

/**
* load the sessionInformation and if the user is directed back to this page with an access-grant-id,
Expand Down Expand Up @@ -143,5 +154,52 @@ export class MainComponent implements OnInit {
this.accessGrants = await this.vcService.getAccessGrants();
}

async redirect() {
if(this.sessionInformation && this.sessionInformation.webId) {
const webId = this.sessionInformation?.webId;
let backendHtiUrl = this.backendUrl + 'hti-launch?webId=' + encodeURIComponent(webId) + '&redirectUrl=' + encodeURIComponent(this.redirectUrl);
const data = await firstValueFrom(this.http.get(backendHtiUrl, {
withCredentials: true,
responseType: 'json'
})) as any
this.postForm(
this.redirectUrl,
{
'launch_token': data.launch_token
})

} else {
console.log("User is not logged in.")
}
}

/**
* Submits a form with the given parameters to the specified path using the POST method.
*
* @param {string} path - The URL or path where the form should be submitted.
* @param {{ [x: string]: string }} params - A dictionary of key-value pairs to include as hidden form fields.
* @return {void} This method does not return a value.
*/
postForm(path: string, params: { [x: string]: string; }) {
const method = "post";
const form = document.createElement("form");
form.setAttribute("method", method);
form.setAttribute("action", path);

for (const key in params) {

if (Object.prototype.hasOwnProperty.call(params, key)) {
const hiddenField = document.createElement("input");
hiddenField.setAttribute("type", "hidden");
hiddenField.setAttribute("name", key);
hiddenField.setAttribute("value", params[key]);

form.appendChild(hiddenField);
}
}
document.body.appendChild(form);
form.submit();
}

protected readonly JSON = JSON;
}