[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[reclaim-ui] 228/459: redirect to edit-attestation after linking account
From: |
gnunet |
Subject: |
[reclaim-ui] 228/459: redirect to edit-attestation after linking account |
Date: |
Fri, 11 Jun 2021 23:25:20 +0200 |
This is an automated email from the git hooks/post-receive script.
martin-schanzenbach pushed a commit to branch master
in repository reclaim-ui.
commit 6d41e8f34756b6f470d36ae3f71198242bb43e7b
Author: anna wimbauer <anna.wibauer@gmx.de>
AuthorDate: Wed Jul 1 12:59:10 2020 +0200
redirect to edit-attestation after linking account
---
src/app/attestation.service.ts | 14 +-
.../edit-attestations.component.html | 22 +--
.../edit-attestations.component.ts | 153 ++++++++++++++-------
src/app/edit-identity/edit-identity.component.html | 13 --
src/app/edit-identity/edit-identity.component.ts | 50 -------
src/app/identity-list/identity-list.component.ts | 2 +-
6 files changed, 125 insertions(+), 129 deletions(-)
diff --git a/src/app/attestation.service.ts b/src/app/attestation.service.ts
index 317adda..cc7e564 100644
--- a/src/app/attestation.service.ts
+++ b/src/app/attestation.service.ts
@@ -4,6 +4,7 @@ import { Observable} from 'rxjs';
import { ConfigService } from './config.service'
import { AuthConfig } from 'angular-oauth2-oidc';
import { IdProvider } from './idProvider';
+import { Identity } from './identity';
@Injectable()
export class AttestationService {
@@ -16,12 +17,13 @@ export class AttestationService {
}
getOauthConfig(idProvider: IdProvider){
- let redirectUri;
- try {
- redirectUri = browser.runtime.getURL('index.html');
- } catch (error) {
- console.log(error);
- redirectUri = window.location.href;
+ var redirectUri;
+ if (window.location.href.includes('localhost')){
+ const user = localStorage.getItem('userForAttestation');
+ redirectUri = 'http://localhost:4200/edit-attestations/' + user;
+ }
+ else {
+ redirectUri = "https://ui.reclaim";
}
const authCodeFlowConfig: AuthConfig = {
diff --git a/src/app/edit-attestations/edit-attestations.component.html
b/src/app/edit-attestations/edit-attestations.component.html
index d96ec35..c9a91ad 100644
--- a/src/app/edit-attestations/edit-attestations.component.html
+++ b/src/app/edit-attestations/edit-attestations.component.html
@@ -41,28 +41,28 @@
<div *ngIf= "!isAttestationValid(attestation)"> <span
style="color:#f00"> Expired </span> <span class="fa fa-times"></span> </div>
</td>
</tr>
- <tr [class.alert-danger]="isAttestInConflict(newAttestation)">
+ <tr [class.alert-danger]="isAttestInConflict(newAttestation)"
*ngIf="newAccessGranted()">
<td>
<input [class.text-danger]="!attestationNameValid(newAttestation)"
placeholder="Attestation" [(ngModel)]="newAttestation.name">
</td>
+ <td><div style="min-width: 15em">JWT</div></td>
<td>
- <input placeholder="Type [JWT]"
[class.text-danger]="!attestationTypeValid(newAttestation)"
[(ngModel)]="newAttestation.type">
+ {{getNewAttestationExpiration()}}
</td>
+ <td><div style="min-width: 15em">{{newIdProvider.url}}</div></td>
<td>
- <input placeholder="Attestation Value"
[class.text-danger]="!attestationValueValid(newAttestation)"
[(ngModel)]="newAttestation.value">
- </td>
- <td>
- </td>
- <td>
- <button [disabled]="!canAddAttestation(newAttestation)" class="btn
btn-primary" (click)="addAttestation()">
+ <button [disabled]="!canAddAttestation(newAttestation)" class="btn
btn-primary" (click)="saveIdProvider()">
<span class="fa fa-plus"></span>
</button>
+ <button class="btn btn-primary ml-2" (click)="cancleAdding()">
+ <span class="fa fa-trash"></span>
+ </button>
</td>
</tr>
</tbody>
</table>
<!-- Attestation creation warning -->
- <div *ngIf="!attestationNameValid(newAttestation) ||
!attestationTypeValid(newAttestation) ||
!attestationValueValid(newAttestation)" class="alert alert-primary
alert-dismissible fade show" role="alert">
+ <div *ngIf="newAccessGranted() && !attestationNameValid(newAttestation) ||
!attestationTypeValid(newAttestation) ||
!attestationValueValid(newAttestation)" class="alert alert-primary
alert-dismissible fade show" role="alert">
<span class="fa fa-warning"></span> Note:
<ul>
<li>Only use alphanumeric attestation names.</li>
@@ -73,8 +73,8 @@
<hr/>
<!-- Edit card buttons -->
<div>
- <button class="btn btn-primary" (click)="saveAttestation()"
[disabled]="!canSaveAttestation()">
- <span class="fa fa-save"></span> Save and Back
+ <button class="btn btn-primary" (click)="goBack()"
[disabled]="!canGoBack()">
+ <span class="fa fa-save"></span> Back
</button>
</div>
</div>
diff --git a/src/app/edit-attestations/edit-attestations.component.ts
b/src/app/edit-attestations/edit-attestations.component.ts
index 62a6236..4e9f39a 100644
--- a/src/app/edit-attestations/edit-attestations.component.ts
+++ b/src/app/edit-attestations/edit-attestations.component.ts
@@ -6,6 +6,10 @@ import { Attestation } from '../attestation';
import { IdentityService } from '../identity.service';
import { from, forkJoin, EMPTY } from 'rxjs';
import { finalize } from 'rxjs/operators';
+import { AttestationService } from '../attestation.service';
+import { OAuthService } from 'angular-oauth2-oidc';
+import { IdProvider } from '../idProvider';
+import { ConstantPool } from '@angular/compiler';
@Component({
selector: 'app-edit-attestations',
@@ -17,16 +21,25 @@ export class EditAttestationsComponent implements OnInit {
identity: Identity;
attestations: Attestation[];
newAttestation: Attestation;
+ newIdProvider: IdProvider;
constructor(private reclaimService: ReclaimService,
private identityService: IdentityService,
private activatedRoute: ActivatedRoute,
- private router: Router) { }
+ private router: Router,
+ private attestationService: AttestationService,
+ private oauthService: OAuthService) { }
ngOnInit() {
- this.newAttestation = new Attestation('', '', '', '', '', 0, []);
+ this.newAttestation = new Attestation('', '', '', 'JWT', '', 0, []);
this.identity = new Identity('','');
+ this.newIdProvider = new IdProvider ('', '', '');
+ this.loadIdProviderFromLocalStorage();
this.attestations = [];
+ if (this.newIdProvider.url !== ''){
+
this.oauthService.configure(this.attestationService.getOauthConfig(this.newIdProvider));
+ this.oauthService.loadDiscoveryDocumentAndTryLogin().then(res =>
console.log("logged in")).catch(err => console.log(err));
+ }
this.activatedRoute.params.subscribe(p => {
if (p['id'] === undefined) {
return;
@@ -36,14 +49,14 @@ export class EditAttestationsComponent implements OnInit {
for (let i = 0; i < ids.length; i++) {
if (ids[i].name == p['id']) {
this.identity = ids[i];
- this.updateAttestation();
+ this.updateAttestations();
}
}
});
});
}
- private updateAttestation() {
+ private updateAttestations() {
this.reclaimService.getAttestations(this.identity).subscribe(attestation
=> {
this.attestations = attestation;
},
@@ -53,23 +66,35 @@ export class EditAttestationsComponent implements OnInit {
});
}
+ saveIdProvider(){
+ this.saveIdProviderinLocalStorage();
+ this.addAttestation();
+ }
+
addAttestation() {
- this.storeAttestation()
- .pipe(
- finalize(() => {
- this.newAttestation.name = '';
- this.newAttestation.type = '';
- this.newAttestation.value = '';
- this.updateAttestation();
- }))
- .subscribe(res => {
- console.log(res);
- },
- err => {
- console.log(err);
- //this.errorInfos.push("Failed to update identity ``" +
this.identityInEdit.name + "''");
- EMPTY
- });
+ this.newAttestation.value = this.oauthService.getAccessToken();
+ this.reclaimService.addAttestation(this.identity,
this.newAttestation).subscribe(res => {
+ console.log("Saved Attestation");
+ console.log(res);
+ this.resetNewIdProvider();
+ this.updateAttestations();
+ this.newAttestation.name = '';
+ this.newAttestation.value = '';
+ this.logOutFromOauthService();
+ },
+ err => {
+ console.log("Failed saving attestation");
+ console.log(err);
+ //this.errorInfos.push("Failed to update identity ``" +
this.identityInEdit.name + "''");
+ EMPTY
+ this.newAttestation.name = '';
+ this.newAttestation.value = '';
+ this.logOutFromOauthService();
+ });
+ }
+
+ saveIdProviderinLocalStorage(){
+ localStorage.setItem('Authorization: ' + this.newAttestation.name,
'idProvider: ' + this.newIdProvider.url + ';redirectUri: ' +
this.oauthService.redirectUri + ';clientId: ' + this.oauthService.clientId +
';accessToken: ' + this.oauthService.getAccessToken() + ';idToken: ' +
this.oauthService.getIdToken() + ';logoutURL: ' + this.newIdProvider.logoutURL);
}
private storeAttestation() {
@@ -80,14 +105,15 @@ export class EditAttestationsComponent implements OnInit {
return forkJoin(promises);
}
- canSaveAttestation() {
- if (this.canAddAttestation(this.newAttestation)) {
+ canGoBack() {
+ if (this.newIdProvider.url === ''){
return true;
}
- return ((this.newAttestation.name === '') &&
- (this.newAttestation.value === '') &&
- (this.newAttestation.type === '')) &&
- !this.isAttestInConflict(this.newAttestation);
+ return false;
+ }
+
+ goBack() {
+ this.router.navigate(['/edit-identity', this.identity.name]);
}
isAttestInConflict(attestation: Attestation) {
@@ -102,31 +128,11 @@ export class EditAttestationsComponent implements OnInit {
return false;
}
- saveAttestation() {
- this.storeAttestation()
- .pipe(
- finalize(() => {
- this.newAttestation.name = '';
- this.newAttestation.value = '';
- this.newAttestation.type = '';
- this.router.navigate(['/edit-identity', this.identity.name]);
- }))
- .subscribe(res => {
- //FIXME success dialog/banner
- this.updateAttestation();
- },
- err => {
- console.log(err);
- //this.errorInfos.push("Failed to update identity ``" +
this.identityInEdit.name + "''");
- });
- }
-
-
deleteAttestation(attestation: Attestation) {
this.reclaimService.deleteAttestation(this.identity, attestation)
.subscribe(res => {
//FIXME info dialog
- this.updateAttestation();
+ this.updateAttestations();
},
err => {
//this.errorInfos.push("Failed to delete attestation ``" +
attestation.name + "''");
@@ -135,7 +141,11 @@ export class EditAttestationsComponent implements OnInit {
}
canAddAttestation(attestation: Attestation) {
- if ((attestation.name === '') || (attestation.value === '') ||
(attestation.type === '')) {
+ if(!this.oauthService.hasValidAccessToken()){
+ console.log("not logged in");
+ return false;
+ }
+ if ((attestation.name === '')) {
return false;
}
if (attestation.name.indexOf(' ') >= 0) {
@@ -178,4 +188,51 @@ export class EditAttestationsComponent implements OnInit {
isAttestationValid(attestation: Attestation) {
return true;
}
+
+ loadIdProviderFromLocalStorage(){
+ this.newIdProvider.url = localStorage.getItem("newIdProviderURL") || '';
+ this.newIdProvider.name =
this.getNewIdProviderName(this.newIdProvider.url);
+ this.newIdProvider.logoutURL =
localStorage.getItem("newIdProviderLogoutURL") || '';
+ }
+
+ getNewIdProviderName(url: string){
+ return url.split('//')[1];
+ }
+
+ newAccessGranted(){
+ if (this.newIdProvider.url !== ''){
+ return true;
+ }
+ return false;
+ }
+
+ getNewAttestationExpiration(){
+ var exp = new Date();
+ exp.setMilliseconds(this.oauthService.getIdTokenExpiration() / 1000);
+ return exp.toLocaleString();
+ }
+
+ resetNewIdProvider(){
+ this.newIdProvider.url = '';
+ this.newIdProvider.logoutURL = '';
+ this.newIdProvider.name = '';
+ localStorage.removeItem('newIdProviderURL');
+ localStorage.removeItem('newIdProviderLogoutURL')
+ }
+
+ logOutFromOauthService(){
+ if (!this.oauthService.hasValidAccessToken()){
+ return;
+ }
+ this.oauthService.logOut(false);
+ }
+
+ cancleAdding(){
+ this.logOutFromOauthService();
+ this.resetNewIdProvider();
+ this.newAttestation.value = '';
+ this.newAttestation.name = '';
+ }
+
+
}
diff --git a/src/app/edit-identity/edit-identity.component.html
b/src/app/edit-identity/edit-identity.component.html
index bd72498..0fe4c10 100644
--- a/src/app/edit-identity/edit-identity.component.html
+++ b/src/app/edit-identity/edit-identity.component.html
@@ -167,19 +167,6 @@
<button *ngIf="isExperimental() && newIdProviderDiscovered() &&
!grantedAccessToIdProvider()" class="btn btn-primary mb-4 fhg-link"
(click)="loginFhgAccount()">
<span class="fa fa-user"></span> Grant Access to {{newIdProvider.name}}
</button>
- <!--Save account-->
- <div *ngIf="isExperimental() && newIdProviderDiscovered() &&
grantedAccessToIdProvider()" class="input-group my-2 col-lg-4">
- <div class="input-group-prepend">
- <span class="input-group-text">Attestation Name</span>
- </div>
- <input placeholder="Attestation Name" class="form-control"
[(ngModel)]="newAttestation.name">
- </div>
- <div *ngIf="newIdProviderDiscovered() && grantedAccessToIdProvider() &&
attestationNameDuplicate()" class="alert alert-danger alert-dismissible fade
show my-2" role="alert">
- <span class="fa fa-warning"></span> You already have an attestation with
this name.
- </div>
- <button *ngIf="isExperimental() && newIdProviderDiscovered() &&
grantedAccessToIdProvider()" [disabled]="attestationNameDuplicate() ||
newAttestation.name==''" class="btn btn-primary mb-4 fhg-link"
(click)="saveIdProvider()">
- <span class="fa fa-user"></span> Save {{newIdProvider.name}} Account
- </button>
<button *ngIf="isExperimental() && newIdProviderDiscovered()" class="btn
btn-primary mb-4 fhg-link" (click)="cancleLinking()">
Cancle Linking
</button>
diff --git a/src/app/edit-identity/edit-identity.component.ts
b/src/app/edit-identity/edit-identity.component.ts
index d257236..a57dd90 100644
--- a/src/app/edit-identity/edit-identity.component.ts
+++ b/src/app/edit-identity/edit-identity.component.ts
@@ -695,43 +695,6 @@ export class EditIdentityComponent implements OnInit {
this.getId();
}
- saveIdProviderinLocalStorage(){
- const newAuthorization: Authorization = {
- idProvider: this.newIdProvider.url,
- attestationName: this.newAttestation.name,
- redirectUri: this.oauthService.redirectUri,
- clientId: this.oauthService.clientId,
- accessToken: this.getAccessToken(),
- idToken: this.oauthService.getIdToken(),
- logoutURL: this.newIdProvider.logoutURL
- }
- this.authorizations.push(newAuthorization);
- localStorage.setItem('Authorization: ' + this.newAttestation.name,
'idProvider: ' + this.newIdProvider.url + ';redirectUri: ' +
this.oauthService.redirectUri + ';clientId: ' + this.oauthService.clientId +
';accessToken: ' + this.getAccessToken() + ';idToken: ' +
this.oauthService.getIdToken() + ';logoutURL: ' + this.newIdProvider.logoutURL);
- }
-
- addAttestation() {
- this.newAttestation.value = this.getAccessToken();
- this.reclaimService.addAttestation(this.identity,
this.newAttestation).subscribe(res => {
- console.log("Saved Attestation");
- console.log(res);
- this.resetNewIdProvider();
- this.updateAttestations();
- this.newAttestation.name = '';
- this.newAttestation.value = '';
- this.logOutFromOauthService();
- },
- err => {
- console.log("Failed saving attestation");
- console.log(err);
- //this.errorInfos.push("Failed to update identity ``" +
this.identityInEdit.name + "''");
- EMPTY
- this.newAttestation.name = '';
- this.newAttestation.value = '';
- this.logOutFromOauthService();
- });
-
- }
-
attestationNameDuplicate(){
let i;
for (i = 0; i < this.attestations.length; i++) {
@@ -742,23 +705,10 @@ export class EditIdentityComponent implements OnInit {
return false;
}
- saveIdProvider(){
- if (this.attestationNameDuplicate()){
- console.log("name duplicate");
- return;
- }
- this.saveIdProviderinLocalStorage();
- this.addAttestation();
- }
-
getId (): any{
return this.oauthService.getIdentityClaims();
}
- getAccessToken () {
- return this.oauthService.getAccessToken();
- }
-
grantedAccessToIdProvider(){
if (this.oauthService.hasValidAccessToken()){
return true;
diff --git a/src/app/identity-list/identity-list.component.ts
b/src/app/identity-list/identity-list.component.ts
index b3cd33d..b5b233e 100644
--- a/src/app/identity-list/identity-list.component.ts
+++ b/src/app/identity-list/identity-list.component.ts
@@ -264,7 +264,7 @@ export class IdentityListComponent implements OnInit {
this.updateAttributes(identity);
this.updateAttestations(identity);
});
- if (!this.modalOpened) {
+ if (this.modalOpened) {
this.closeModal('GnunetInfo');
}
this.connected = true;
--
To stop receiving notification emails like this one, please contact
gnunet@gnunet.org.
- [reclaim-ui] 223/459: button label changed, (continued)
- [reclaim-ui] 223/459: button label changed, gnunet, 2021/06/11
- [reclaim-ui] 229/459: fix, gnunet, 2021/06/11
- [reclaim-ui] 238/459: improved error massage, gnunet, 2021/06/11
- [reclaim-ui] 225/459: added logout url to webfinger, gnunet, 2021/06/11
- [reclaim-ui] 212/459: Add typescript dependency to make modules happy., gnunet, 2021/06/11
- [reclaim-ui] 239/459: -fix expiration date display, gnunet, 2021/06/11
- [reclaim-ui] 231/459: maing, gnunet, 2021/06/11
- [reclaim-ui] 245/459: improved scope display, gnunet, 2021/06/11
- [reclaim-ui] 236/459: redirect after logout from idProvider, gnunet, 2021/06/11
- [reclaim-ui] 255/459: remove env, gnunet, 2021/06/11
- [reclaim-ui] 228/459: redirect to edit-attestation after linking account,
gnunet <=
- [reclaim-ui] 237/459: moved IdProvider-Linking to edit-attestations, gnunet, 2021/06/11
- [reclaim-ui] 242/459: more style, gnunet, 2021/06/11
- [reclaim-ui] 217/459: fixed attestation-save (already existing attestations were always added again), gnunet, 2021/06/11
- [reclaim-ui] 222/459: omejdn:api scope deleted, gnunet, 2021/06/11
- [reclaim-ui] 227/459: redirect now to edit-attestations/clientname should be edit-identity/clientname #20, gnunet, 2021/06/11
- [reclaim-ui] 203/459: yarn.lock, gnunet, 2021/06/11
- [reclaim-ui] 234/459: adding attestation works, gnunet, 2021/06/11
- [reclaim-ui] 214/459: package.json, gnunet, 2021/06/11
- [reclaim-ui] 240/459: scopes after idProviderDiscovery, gnunet, 2021/06/11
- [reclaim-ui] 244/459: fix, gnunet, 2021/06/11