Skip to content

Commit

Permalink
GUI: Add a renew token button
Browse files Browse the repository at this point in the history
Fixes #152
  • Loading branch information
qligier committed Jun 21, 2024
1 parent f058223 commit 00b6a66
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 20 deletions.
5 changes: 3 additions & 2 deletions angular/src/app/fhirConfig.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,15 +70,16 @@ export class FhirConfigService {
}

getAuthCodeFlowConfig(provider: string): AuthConfig {
const idpAlias = provider ? ("/alias/" + provider) : "";
return {
// Url of the Identity Provider

loginUrl: this.getMobileAccessGatewayLoginUrl()+(provider ? ("/alias/"+provider) : ""),
loginUrl: this.getMobileAccessGatewayLoginUrl() + idpAlias,
// URL of the SPA to redirect the user to after login
// redirectUri: window.location.origin + '/index.html',
redirectUri: this.getRedirectUri(),

tokenEndpoint: this.getMobileAccessGatewayTokenEndpoint(),
tokenEndpoint: this.getMobileAccessGatewayTokenEndpoint() + idpAlias,

// The SPA's id. The SPA is registerd with this id at the auth-server
// clientId: 'server.code',
Expand Down
13 changes: 10 additions & 3 deletions angular/src/app/mag/mag.component.html
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@
<select matNativeControl [formControl]="provider">
<option *ngFor="let idp of idps" [value]="idp.id">
{{ idp.name }}
</option>
</option>
</select>
</mat-form-field>
</div>
Expand All @@ -142,6 +142,13 @@
>
Authenticate
</button>
<button
mat-raised-button
color="primary"
type="submit"
(click)="onRenewToken()">
Renew the token
</button>
</mat-card-actions>
</mat-card-content>
</mat-card>
Expand All @@ -161,7 +168,7 @@
</div>
</mat-cell>
</ng-container>

<ng-container matColumnDef="name">
<mat-header-cell *matHeaderCellDef class="name"
>Description</mat-header-cell
Expand All @@ -170,7 +177,7 @@
{{ entry.description }}
</mat-cell>
</ng-container>

<ng-container matColumnDef="contentType">
<mat-header-cell *matHeaderCellDef class="contentType"
>Content-Type</mat-header-cell
Expand Down
41 changes: 26 additions & 15 deletions angular/src/app/mag/mag.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ export function toLocaleDateTime(date: Date) {

interface IDP {
id: string;
name: string;
name: string;
}

class UUIReplace {
Expand All @@ -44,6 +44,8 @@ class UUIReplace {
styleUrls: ['./mag.component.scss'],
})
export class MagComponent implements OnInit {
private readonly LS_OAUTH_CONF_KEY = "magOAuthConf";

mag: FhirClient;
json: string;
doc: string;
Expand Down Expand Up @@ -231,12 +233,12 @@ export class MagComponent implements OnInit {

this.searchGiven = new UntypedFormControl();
this.searchFamily = new UntypedFormControl();

this.documentTitle = new UntypedFormControl();
this.documentTitle.setValue(
this.getLocalStorageItemOrDefault('mag.documentTitle', 'Titel')
);

this.documentDescription = new UntypedFormControl();
this.documentDescription.setValue(
this.getLocalStorageItemOrDefault('mag.documentDescription', 'Description')
Expand All @@ -253,12 +255,16 @@ export class MagComponent implements OnInit {

this.fhirConfigService = data;

oauthService.configure(this.fhirConfigService.getAuthCodeFlowConfig(this.provider.value));
oauthService.tryLoginCodeFlow().then((_) => {
this.scopes = this.oauthService.getGrantedScopes();
});
// If we have a OAuth configuration in local storage, we use it to configure the service
if (localStorage.getItem(this.LS_OAUTH_CONF_KEY) !== null) {
const conf = JSON.parse(localStorage.getItem(this.LS_OAUTH_CONF_KEY));
this.oauthService.configure(conf);
this.oauthService.tryLoginCodeFlow().then((_) => {
this.scopes = this.oauthService.getGrantedScopes();
});
}

oauthService.events.subscribe((event) => {
this.oauthService.events.subscribe((event) => {
if (event instanceof OAuthErrorEvent) {
console.error(event);
} else {
Expand All @@ -276,7 +282,7 @@ export class MagComponent implements OnInit {
this.idps = body;
this.provider.setValue(
this.getLocalStorageItemOrDefault('mag.provider', '')
);
);
},
error: (err: Error) => {
this.idps = [ { id : "", name : "Default" } ];
Expand Down Expand Up @@ -564,21 +570,26 @@ export class MagComponent implements OnInit {
onAuthenticate() {
this.cache();
this.scopes = null;
const authCodeFlowConfig = this.fhirConfigService.getAuthCodeFlowConfig(this.provider.value);
if (this.authenticate.value === 'HCP') {
let authCodeFlowConfig = this.fhirConfigService.getAuthCodeFlowConfig(this.provider.value);
authCodeFlowConfig.scope = `person_id=${this.targetIdentifier2Value}^^^&2.16.756.5.30.1.127.3.10.3&ISO purpose_of_use=urn:oid:2.16.756.5.30.1.127.3.10.5|NORM subject_role=urn:oid:2.16.756.5.30.1.127.3.10.6|HCP`;
localStorage.setItem(this.LS_OAUTH_CONF_KEY, JSON.stringify(authCodeFlowConfig));
this.oauthService.configure(authCodeFlowConfig);
this.oauthService.initCodeFlow();
}
}
if (this.authenticate.value === 'Patient') {
let authCodeFlowConfig = this.fhirConfigService.getAuthCodeFlowConfig(this.provider.value);
authCodeFlowConfig.scope = `person_id=${this.targetIdentifier2Value}^^^&2.16.756.5.30.1.127.3.10.3&ISO purpose_of_use=urn:oid:2.16.756.5.30.1.127.3.10.5|NORM subject_role=urn:oid:2.16.756.5.30.1.127.3.10.6|PAT`;
localStorage.setItem(this.LS_OAUTH_CONF_KEY, JSON.stringify(authCodeFlowConfig));
this.oauthService.configure(authCodeFlowConfig);
this.oauthService.initCodeFlow();
}
this.oauthService.initCodeFlow();
}
if (this.authenticate.value === 'TCU') {
this.getSamlToken().then((value) => (this.json = value));
}
}
}

onRenewToken(): void {
this.oauthService.refreshToken().then(r => console.log(r));
}

getAppcDocument(eprspid: string, uniqueId: string): string {
Expand Down

0 comments on commit 00b6a66

Please sign in to comment.