Prevent login requests to be sent multiple times from the oauth2 dialog

This commit is contained in:
George Kalampokis 2020-10-27 12:31:45 +02:00
parent 22cc8bb3a3
commit eeca52d3ff
3 changed files with 47 additions and 8 deletions

View File

@ -40,6 +40,7 @@ export class LoginComponent extends BaseComponent implements OnInit, AfterViewIn
private orcidUser: OrcidUser;
private zenodoToken: ZenodoToken;
private accessToken: string;
private oauthLock: boolean;
//public cofigurableProviders: ConfigurableProvider[];
constructor(
@ -77,7 +78,12 @@ export class LoginComponent extends BaseComponent implements OnInit, AfterViewIn
this.oauth2DialogService.login(this.getLinkedInUrl()).pipe(takeUntil(this._destroyed))
.subscribe(result => {
if (result !== undefined) {
this.linkedInLoginUser(result.oauthCode, result.oauthState);
if (!this.oauthLock) {
this.linkedInLoginUser(result.oauthCode, result.oauthState);
this.oauthLock = true;
}
} else {
this.oauthLock = false;
}
});
}
@ -89,7 +95,12 @@ export class LoginComponent extends BaseComponent implements OnInit, AfterViewIn
this.oauth2DialogService.login(url).pipe(takeUntil(this._destroyed))
.subscribe(result => {
if (result !== undefined) {
this.twitterLoginUser(result.oauthToken, result.oauthVerifier);
if (!this.oauthLock) {
this.twitterLoginUser(result.oauthToken, result.oauthVerifier);
this.oauthLock = true;
}
} else {
this.oauthLock = false;
}
});
}
@ -102,7 +113,12 @@ export class LoginComponent extends BaseComponent implements OnInit, AfterViewIn
this.oauth2DialogService.login(this.getB2AccessUrl()).pipe(takeUntil(this._destroyed))
.subscribe(result => {
if (result !== undefined) {
this.b2AccessLoginUser(result.oauthCode);
if (!this.oauthLock) {
this.b2AccessLoginUser(result.oauthCode);
this.oauthLock = true;
}
} else {
this.oauthLock = false;
}
});
}
@ -112,7 +128,12 @@ export class LoginComponent extends BaseComponent implements OnInit, AfterViewIn
this.oauth2DialogService.login(this.getORCIDUrl()).pipe(takeUntil(this._destroyed))
.subscribe(result => {
if (result !== undefined) {
this.orcidLoginUser(result.oauthCode);
if (!this.oauthLock) {
this.orcidLoginUser(result.oauthCode);
this.oauthLock = true;
}
} else {
this.oauthLock = false;
}
});
}
@ -122,7 +143,12 @@ export class LoginComponent extends BaseComponent implements OnInit, AfterViewIn
this.oauth2DialogService.login(this.getOpenAireUrl()).pipe(takeUntil(this._destroyed))
.subscribe(result => {
if (result !== undefined) {
this.openaireLoginUser(result.oauthCode, result.oauthState);
if (!this.oauthLock) {
this.openaireLoginUser(result.oauthCode, result.oauthState);
this.oauthLock = true;
}
} else {
this.oauthLock = false;
}
});
}
@ -136,7 +162,12 @@ export class LoginComponent extends BaseComponent implements OnInit, AfterViewIn
this.oauth2DialogService.login(this.getZenodoUrl()).pipe(takeUntil(this._destroyed))
.subscribe(result => {
if (result !== undefined) {
this.zenodoLoginUser(result.oauthCode);
if (!this.oauthLock) {
this.zenodoLoginUser(result.oauthCode);
this.oauthLock = true;
}
} else {
this.oauthLock = false;
}
});
}

View File

@ -68,6 +68,7 @@ export class DmpOverviewComponent extends BaseComponent implements OnInit {
textMessage: any;
versions: VersionListingModel[];
version: VersionListingModel;
private oauthLock: boolean;
@ViewChild('doi', { static: false })
doi: ElementRef;
@ -528,14 +529,17 @@ export class DmpOverviewComponent extends BaseComponent implements OnInit {
.pipe(takeUntil(this._destroyed))
.subscribe(result => {
if (result !== undefined) {
if (result.oauthCode !== undefined && result.oauthCode !== null) {
if (result.oauthCode !== undefined && result.oauthCode !== null && !this.oauthLock) {
this.userService.registerDOIToken(result.oauthCode, this.configurationService.app + 'oauth2')
.pipe(takeUntil(this._destroyed))
.subscribe(() => {
this.hasDOIToken = true;
this.showConfirmationDOIDialog(dmp);
});
this.oauthLock = true;
}
} else {
this.oauthLock = false;
}
});
}

View File

@ -49,6 +49,7 @@ export class UserProfileComponent extends BaseComponent implements OnInit, OnDes
zenodoEmail: String;
roleOrganizationEnum = RoleOrganizationType;
authProviderEnum = AuthProvider;
private oauthLock: boolean;
organisationsAutoCompleteConfiguration: MultipleAutoCompleteConfiguration = {
filterFn: this.filterOrganisations.bind(this),
@ -238,11 +239,14 @@ export class UserProfileComponent extends BaseComponent implements OnInit, OnDes
.pipe(takeUntil(this._destroyed))
.subscribe(result => {
if (result !== undefined) {
if (result.oauthCode !== undefined && result.oauthCode !== null) {
if (result.oauthCode !== undefined && result.oauthCode !== null && !this.oauthLock) {
this.userService.registerDOIToken(result.oauthCode, this.configurationService.app + 'oauth2')
.pipe(takeUntil(this._destroyed))
.subscribe(() => this.router.navigate(['/reload']).then(() => this.router.navigate(['/profile'])));
this.oauthLock = true;
}
} else {
this.oauthLock = false;
}
});
}