diff --git a/backend/core/src/main/java/org/opencdmp/model/persist/deposit/DepositAuthenticateRequest.java b/backend/core/src/main/java/org/opencdmp/model/persist/deposit/DepositAuthenticateRequest.java index 3f17f8959..da3a66212 100644 --- a/backend/core/src/main/java/org/opencdmp/model/persist/deposit/DepositAuthenticateRequest.java +++ b/backend/core/src/main/java/org/opencdmp/model/persist/deposit/DepositAuthenticateRequest.java @@ -1,12 +1,9 @@ package org.opencdmp.model.persist.deposit; -import org.opencdmp.commons.validation.BaseValidator; import gr.cite.tools.validation.specification.Specification; +import org.opencdmp.commons.validation.BaseValidator; import org.opencdmp.convention.ConventionService; import org.opencdmp.errorcode.ErrorThesaurusProperties; -import org.opencdmp.model.persist.ReferencePersist; -import jakarta.validation.constraints.NotEmpty; -import jakarta.validation.constraints.NotNull; import org.springframework.beans.factory.config.ConfigurableBeanFactory; import org.springframework.context.MessageSource; import org.springframework.context.annotation.Scope; @@ -27,14 +24,14 @@ public class DepositAuthenticateRequest { public static final String _code = "code"; public String getRepositoryId() { - return repositoryId; + return this.repositoryId; } public void setRepositoryId(String repositoryId) { this.repositoryId = repositoryId; } public String getCode() { - return code; + return this.code; } public void setCode(String code) { this.code = code; @@ -63,10 +60,10 @@ public class DepositAuthenticateRequest { return Arrays.asList( this.spec() .must(() -> !this.isEmpty(item.getRepositoryId())) - .failOn(DepositAuthenticateRequest._repositoryId).failWith(messageSource.getMessage("Validation_Required", new Object[]{DepositAuthenticateRequest._repositoryId}, LocaleContextHolder.getLocale())), + .failOn(DepositAuthenticateRequest._repositoryId).failWith(this.messageSource.getMessage("Validation_Required", new Object[]{DepositAuthenticateRequest._repositoryId}, LocaleContextHolder.getLocale())), this.spec() .must(() -> !this.isEmpty(item.getCode())) - .failOn(DepositAuthenticateRequest._code).failWith(messageSource.getMessage("Validation_Required", new Object[]{DepositAuthenticateRequest._code}, LocaleContextHolder.getLocale())) + .failOn(DepositAuthenticateRequest._code).failWith(this.messageSource.getMessage("Validation_Required", new Object[]{DepositAuthenticateRequest._code}, LocaleContextHolder.getLocale())) ); } } diff --git a/backend/core/src/main/java/org/opencdmp/model/persist/deposit/DepositRequest.java b/backend/core/src/main/java/org/opencdmp/model/persist/deposit/DepositRequest.java index af25da4b2..1bac49f6a 100644 --- a/backend/core/src/main/java/org/opencdmp/model/persist/deposit/DepositRequest.java +++ b/backend/core/src/main/java/org/opencdmp/model/persist/deposit/DepositRequest.java @@ -25,7 +25,7 @@ public class DepositRequest { public static final String _dmpId = "dmpId"; - private String accessToken; + private String authorizationCode; private BaseFieldSet project; @@ -45,12 +45,12 @@ public class DepositRequest { this.dmpId = dmpId; } - public String getAccessToken() { - return this.accessToken; + public String getAuthorizationCode() { + return this.authorizationCode; } - public void setAccessToken(String accessToken) { - this.accessToken = accessToken; + public void setAuthorizationCode(String authorizationCode) { + this.authorizationCode = authorizationCode; } public BaseFieldSet getProject() { diff --git a/backend/core/src/main/java/org/opencdmp/service/deposit/DepositClientImpl.java b/backend/core/src/main/java/org/opencdmp/service/deposit/DepositClientImpl.java index 369e31a70..33b345917 100644 --- a/backend/core/src/main/java/org/opencdmp/service/deposit/DepositClientImpl.java +++ b/backend/core/src/main/java/org/opencdmp/service/deposit/DepositClientImpl.java @@ -29,7 +29,7 @@ public class DepositClientImpl implements DepositClient { @Override public String authenticate(String code) { logger.debug(new MapLogEntry("code")); - return this.depositClient.get().uri("/authenticate/", uriBuilder -> uriBuilder.queryParam("authToken", code).build()).exchangeToMono(mono -> mono.statusCode().isError() ? mono.createException().flatMap(Mono::error) : mono.bodyToMono(String.class)).block(); + return this.depositClient.get().uri("/authenticate", uriBuilder -> uriBuilder.queryParam("authToken", code).build()).exchangeToMono(mono -> mono.statusCode().isError() ? mono.createException().flatMap(Mono::error) : mono.bodyToMono(String.class)).block(); } @Override diff --git a/backend/core/src/main/java/org/opencdmp/service/deposit/DepositService.java b/backend/core/src/main/java/org/opencdmp/service/deposit/DepositService.java index 6a3872e23..4fc1f6739 100644 --- a/backend/core/src/main/java/org/opencdmp/service/deposit/DepositService.java +++ b/backend/core/src/main/java/org/opencdmp/service/deposit/DepositService.java @@ -1,10 +1,8 @@ package org.opencdmp.service.deposit; -import org.opencdmp.model.EntityDoi; -import org.opencdmp.model.persist.deposit.DepositAuthenticateRequest; -import org.opencdmp.model.persist.deposit.DepositRequest; -import org.opencdmp.model.deposit.DepositConfiguration; import gr.cite.tools.fieldset.FieldSet; +import org.opencdmp.model.EntityDoi; +import org.opencdmp.model.persist.deposit.DepositRequest; import javax.crypto.BadPaddingException; import javax.crypto.IllegalBlockSizeException; @@ -21,6 +19,4 @@ public interface DepositService { EntityDoi deposit(DepositRequest dmpDepositModel) throws Exception; String getLogo(String repositoryId) throws InvalidApplicationException, InvalidAlgorithmParameterException, NoSuchPaddingException, IllegalBlockSizeException, NoSuchAlgorithmException, BadPaddingException, InvalidKeyException; - - String authenticate(DepositAuthenticateRequest model) throws InvalidApplicationException, InvalidAlgorithmParameterException, NoSuchPaddingException, IllegalBlockSizeException, NoSuchAlgorithmException, BadPaddingException, InvalidKeyException; } diff --git a/backend/core/src/main/java/org/opencdmp/service/deposit/DepositServiceImpl.java b/backend/core/src/main/java/org/opencdmp/service/deposit/DepositServiceImpl.java index 6a34f06a9..2ae5f7d62 100644 --- a/backend/core/src/main/java/org/opencdmp/service/deposit/DepositServiceImpl.java +++ b/backend/core/src/main/java/org/opencdmp/service/deposit/DepositServiceImpl.java @@ -282,12 +282,20 @@ public class DepositServiceImpl implements DepositService { DepositSourceEntity source = this.getDepositSources().stream().filter(depositSource -> depositSource.getRepositoryId().equals(dmpDepositModel.getRepositoryId())).findFirst().orElse(null); if (source == null) throw new MyNotFoundException(this.messageSource.getMessage("General_ItemNotFound", new Object[]{dmpDepositModel.getRepositoryId(), DepositSourceEntity.class.getSimpleName()}, LocaleContextHolder.getLocale())); + String accessToken = null; + if (!this.conventionService.isNullOrEmpty(dmpDepositModel.getAuthorizationCode())) { + DepositAuthenticateRequest authenticateRequest = new DepositAuthenticateRequest(); + authenticateRequest.setRepositoryId(dmpDepositModel.getRepositoryId()); + authenticateRequest.setCode(dmpDepositModel.getAuthorizationCode()); + accessToken = this.authenticate(authenticateRequest); + } + org.opencdmp.model.file.FileEnvelope pdfFile = this.fileTransformerService.exportDmp(dmpEntity.getId(), source.getPdfTransformerId(),"pdf"); org.opencdmp.model.file.FileEnvelope rda = this.fileTransformerService.exportDmp(dmpEntity.getId(), source.getRdaTransformerId(),"json"); FileEnvelopeModel pdfEnvelope = new FileEnvelopeModel(); FileEnvelopeModel jsonEnvelope = new FileEnvelopeModel(); - + pdfEnvelope.setFilename(pdfFile.getFilename()); jsonEnvelope.setMimeType("application/pdf"); jsonEnvelope.setFilename(rda.getFilename()); @@ -299,14 +307,14 @@ public class DepositServiceImpl implements DepositService { pdfEnvelope.setFileRef(this.addFileToSharedStorage(pdfFile)); jsonEnvelope.setFileRef(this.addFileToSharedStorage(rda)); } - + //GK: Fifth Transform them to the DepositModel DmpModel depositModel = this.builderFactory.builder(DmpCommonModelBuilder.class).useSharedStorage(depositClient.getConfiguration().isUseSharedStorage()).authorize(AuthorizationFlags.OwnerOrDmpAssociatedOrPermission) .setRepositoryId(dmpDepositModel.getRepositoryId()).setPdfFile(pdfEnvelope).setRdaJsonFile(jsonEnvelope).build(dmpEntity); //GK: Sixth Perform the deposit - String doi = depositClient.deposit(depositModel, dmpDepositModel.getAccessToken()); + String doi = depositClient.deposit(depositModel, accessToken); //GK: Something has gone wrong return null if (doi.isEmpty()) return null; //GK: doi is fine store it in database @@ -378,8 +386,7 @@ public class DepositServiceImpl implements DepositService { return depositClient.getLogo(); } - @Override - public String authenticate(DepositAuthenticateRequest model) throws InvalidApplicationException, InvalidAlgorithmParameterException, NoSuchPaddingException, IllegalBlockSizeException, NoSuchAlgorithmException, BadPaddingException, InvalidKeyException { + private String authenticate(DepositAuthenticateRequest model) throws InvalidApplicationException, InvalidAlgorithmParameterException, NoSuchPaddingException, IllegalBlockSizeException, NoSuchAlgorithmException, BadPaddingException, InvalidKeyException { this.authorizationService.authorizeForce(Permission.BrowseDeposit, Permission.DeferredAffiliation); DepositClient depositClient = this.getDepositClient(model.getRepositoryId()); diff --git a/backend/web/src/main/java/org/opencdmp/controllers/DepositController.java b/backend/web/src/main/java/org/opencdmp/controllers/DepositController.java index 93c1c1394..2e2d20859 100644 --- a/backend/web/src/main/java/org/opencdmp/controllers/DepositController.java +++ b/backend/web/src/main/java/org/opencdmp/controllers/DepositController.java @@ -12,7 +12,6 @@ import org.opencdmp.model.EntityDoi; import org.opencdmp.model.censorship.EntityDoiCensor; import org.opencdmp.model.censorship.deposit.DepositConfigurationCensor; import org.opencdmp.model.deposit.DepositConfiguration; -import org.opencdmp.model.persist.deposit.DepositAuthenticateRequest; import org.opencdmp.model.persist.deposit.DepositRequest; import org.opencdmp.service.deposit.DepositService; import org.slf4j.LoggerFactory; @@ -71,19 +70,6 @@ public class DepositController { return model; } - @PostMapping("/get-access-token") - @ValidationFilterAnnotation(validator = DepositAuthenticateRequest.DepositAuthenticateRequestValidator.ValidatorName, argumentName = "model") - public String getAccessToken(@RequestBody DepositAuthenticateRequest model) throws InvalidApplicationException, InvalidAlgorithmParameterException, NoSuchPaddingException, IllegalBlockSizeException, NoSuchAlgorithmException, BadPaddingException, InvalidKeyException { - logger.debug(new MapLogEntry("get access token" + DepositAuthenticateRequest.class.getSimpleName()).And("model", model)); - - String accessToken = this.depositService.authenticate(model); - this.auditService.track(AuditableAction.Deposit_GetAccessToken, Map.ofEntries( - new AbstractMap.SimpleEntry("model", model) - )); - - return accessToken; - } - @PostMapping("/deposit") @Transactional @ValidationFilterAnnotation(validator = DepositRequest.DepositRequestValidator.ValidatorName, argumentName = "model") diff --git a/dmp-frontend/src/app/app-routing.module.ts b/dmp-frontend/src/app/app-routing.module.ts index f83680b2e..9ae5246d0 100644 --- a/dmp-frontend/src/app/app-routing.module.ts +++ b/dmp-frontend/src/app/app-routing.module.ts @@ -366,9 +366,13 @@ const appRoutes: Routes = [ }, { path: 'logout', loadChildren: () => import('./ui/auth/logout/logout.module').then(m => m.LogoutModule) }, { path: 'reload', component: ReloadHelperComponent }, - { path: 'oauth2', component: DepositOauth2DialogComponent }, - { path: 'login/external/zenodo', component: DepositOauth2DialogComponent }, - { path: 'deposit/oauth2', loadChildren: () => import('./ui/misc/deposit-oauth2-dialog/deposit-oauth2-dialog.module').then(m => m.DepositOauth2DialogModule) } + { + path: 'deposit/oauth2', + loadChildren: () => import('./ui/misc/deposit-oauth2-dialog/deposit-oauth2-dialog.module').then(m => m.DepositOauth2DialogModule), + data: { + showOnlyRouterOutlet: true + } + } ]; @NgModule({ diff --git a/dmp-frontend/src/app/app.component.html b/dmp-frontend/src/app/app.component.html index 87b6099ed..3cc8deb9d 100644 --- a/dmp-frontend/src/app/app.component.html +++ b/dmp-frontend/src/app/app.component.html @@ -1,4 +1,4 @@ -
+
@@ -22,10 +22,10 @@
--> - - + + - diff --git a/dmp-frontend/src/app/app.component.ts b/dmp-frontend/src/app/app.component.ts index 24b6aa882..e857cabb8 100644 --- a/dmp-frontend/src/app/app.component.ts +++ b/dmp-frontend/src/app/app.component.ts @@ -42,6 +42,7 @@ export class AppComponent implements OnInit, AfterViewInit { helpContentEnabled: boolean; private statusChangeSubscription: Subscription; onlySplash = true; + showOnlyRouterOutlet = false; @ViewChild('sidenav') sidenav:MatSidenav; @@ -147,6 +148,22 @@ export class AppComponent implements OnInit, AfterViewInit { while (child.firstChild) { child = child.firstChild; } + if (child.snapshot.data && child.snapshot.data.showOnlyRouterOutlet) { + this.showOnlyRouterOutlet = true; + this.ccService.getConfig().enabled = false; + this.ccService.destroy(); + this.ccService.init(this.ccService.getConfig()); + } else { + this.showOnlyRouterOutlet = false; + if (this.cookieService.get("cookiesConsent") == "true") { + this.ccService.getConfig().enabled = false; + } else { + this.ccService.getConfig().enabled = true; + } + this.ccService.destroy(); + this.ccService.init(this.ccService.getConfig()); + } + const usePrefix = child.snapshot.data['usePrefix'] ?? true; if (child.snapshot.data['getFromTitleService']) { return { title: this.titleService.getTitle(), usePrefix: usePrefix }; diff --git a/dmp-frontend/src/app/core/model/deposit/deposit-request.ts b/dmp-frontend/src/app/core/model/deposit/deposit-request.ts index d1f377bb6..f60d68a0a 100644 --- a/dmp-frontend/src/app/core/model/deposit/deposit-request.ts +++ b/dmp-frontend/src/app/core/model/deposit/deposit-request.ts @@ -3,7 +3,7 @@ import { Guid } from "@common/types/guid"; export class DepositRequest { repositoryId: string; dmpId: Guid; - accessToken: String; + authorizationCode: String; project: DepositRequestFields; } @@ -14,4 +14,4 @@ export interface DepositRequestFields { export class DepositAuthenticateRequest { repositoryId: string; code: string; -} \ No newline at end of file +} diff --git a/dmp-frontend/src/app/ui/dmp/editor/dmp-deposit-dropdown/dmp-deposit-dropdown.component.ts b/dmp-frontend/src/app/ui/dmp/editor/dmp-deposit-dropdown/dmp-deposit-dropdown.component.ts index 53192679a..ff1b824db 100644 --- a/dmp-frontend/src/app/ui/dmp/editor/dmp-deposit-dropdown/dmp-deposit-dropdown.component.ts +++ b/dmp-frontend/src/app/ui/dmp/editor/dmp-deposit-dropdown/dmp-deposit-dropdown.component.ts @@ -75,13 +75,13 @@ export class DmpDepositDropdown extends BaseComponent implements OnInit { dialogRef.afterClosed().pipe(takeUntil(this._destroyed)).subscribe(result => { switch (result) { case 0: - this.showOauth2Dialog(this.depositOauth2DialogService.getLoginUrl(repo, this.dmp?.id), repo, this.dmp); + this.showOauth2Dialog(this.depositOauth2DialogService.getLoginUrl(repo), repo, this.dmp); break; case 1: const depositRequest: DepositRequest = { repositoryId: repo.repositoryId, dmpId: this.dmp.id, - accessToken: null, + authorizationCode: null, project: this.EntityDoiFields() }; this.depositRepositoriesService.deposit(depositRequest) @@ -99,7 +99,7 @@ export class DmpDepositDropdown extends BaseComponent implements OnInit { const depositRequest: DepositRequest = { repositoryId: repo.repositoryId, dmpId: this.dmp.id, - accessToken: null, + authorizationCode: null, project: this.EntityDoiFields() }; this.depositRepositoriesService.deposit(depositRequest) @@ -123,22 +123,21 @@ export class DmpDepositDropdown extends BaseComponent implements OnInit { showOauth2Dialog(url: string, repo: DepositConfiguration, dmp: Dmp) { this.depositOauth2DialogService.login(url) .pipe(takeUntil(this._destroyed)) - .subscribe(token => { - if (token !== undefined) { - console.log(token); - // const depositRequest: DepositRequest = { - // repositoryId: repo.repositoryId, - // dmpId: dmp.id, - // accessToken: token, - // project: this.EntityDoiFields() - // }; - // this.depositRepositoriesService.deposit(depositRequest) - // .pipe(takeUntil(this._destroyed)) - // .subscribe(doi => { - // this.onDOICallbackSuccess(); - // this.outputRepos.push(doi); - // this.outputReposEmitter.emit(this.outputRepos); - // }, error => this.onDOICallbackError(error)); + .subscribe(code => { + if (code !== undefined) { + const depositRequest: DepositRequest = { + repositoryId: repo.repositoryId, + dmpId: dmp.id, + authorizationCode: code, + project: this.EntityDoiFields() + }; + this.depositRepositoriesService.deposit(depositRequest) + .pipe(takeUntil(this._destroyed)) + .subscribe(doi => { + this.onDOICallbackSuccess(); + this.outputRepos.push(doi); + this.outputReposEmitter.emit(this.outputRepos); + }, error => this.onDOICallbackError(error)); this.oauthLock = true; } else { this.oauthLock = false; diff --git a/dmp-frontend/src/app/ui/misc/deposit-oauth2-dialog/deposit-oauth2-dialog-routing.module.ts b/dmp-frontend/src/app/ui/misc/deposit-oauth2-dialog/deposit-oauth2-dialog-routing.module.ts index 8c5350e64..19ca94df0 100644 --- a/dmp-frontend/src/app/ui/misc/deposit-oauth2-dialog/deposit-oauth2-dialog-routing.module.ts +++ b/dmp-frontend/src/app/ui/misc/deposit-oauth2-dialog/deposit-oauth2-dialog-routing.module.ts @@ -4,18 +4,18 @@ import { DepositOauth2DialogComponent } from './deposit-oauth2-dialog.component' const routes: Routes = [ { - path: ':id/:entityId', + path: '', component: DepositOauth2DialogComponent, data: { - breadcrumb: true - }, + showOnlyRouterOutlet: true + } }, { path: 'code-callaback', component: DepositOauth2DialogComponent, data: { - breadcrumb: true - }, + showOnlyRouterOutlet: true + } }, ]; diff --git a/dmp-frontend/src/app/ui/misc/deposit-oauth2-dialog/deposit-oauth2-dialog.component.html b/dmp-frontend/src/app/ui/misc/deposit-oauth2-dialog/deposit-oauth2-dialog.component.html index a9478084f..a43030185 100644 --- a/dmp-frontend/src/app/ui/misc/deposit-oauth2-dialog/deposit-oauth2-dialog.component.html +++ b/dmp-frontend/src/app/ui/misc/deposit-oauth2-dialog/deposit-oauth2-dialog.component.html @@ -1 +1 @@ -

oauth2-dialog works!

+

{{error}}

diff --git a/dmp-frontend/src/app/ui/misc/deposit-oauth2-dialog/deposit-oauth2-dialog.component.ts b/dmp-frontend/src/app/ui/misc/deposit-oauth2-dialog/deposit-oauth2-dialog.component.ts index 60ba4f18e..cae709a85 100644 --- a/dmp-frontend/src/app/ui/misc/deposit-oauth2-dialog/deposit-oauth2-dialog.component.ts +++ b/dmp-frontend/src/app/ui/misc/deposit-oauth2-dialog/deposit-oauth2-dialog.component.ts @@ -1,16 +1,7 @@ -import { Component, OnInit, Inject } from '@angular/core'; -import { ActivatedRoute, ParamMap, Params } from '@angular/router'; +import { Component, OnInit } from '@angular/core'; +import { ActivatedRoute, Params } from '@angular/router'; import { BaseComponent } from '@common/base/base.component'; import { takeUntil } from 'rxjs/operators'; -import { DepositOauth2DialogService } from './service/deposit-oauth2-dialog.service'; -import { DepositService } from '@app/core/services/deposit/deposit.service'; -import { DepositConfiguration } from '@app/core/model/deposit/deposit-configuration'; -import { nameof } from 'ts-simple-nameof'; -import { HttpErrorResponse } from '@angular/common/http'; -import { HttpError, HttpErrorHandlingService } from '@common/modules/errors/error-handling/http-error-handling.service'; -import { SnackBarNotificationLevel, UiNotificationService } from '@app/core/services/notification/ui-notification-service'; -import { DepositAuthenticateRequest, DepositRequest, DepositRequestFields } from '@app/core/model/deposit/deposit-request'; -import { EntityDoi } from '@app/core/model/entity-doi/entity-doi'; @Component({ selector: 'app-deposit-oauth2-dialog', @@ -20,11 +11,7 @@ import { EntityDoi } from '@app/core/model/entity-doi/entity-doi'; export class DepositOauth2DialogComponent extends BaseComponent implements OnInit{ constructor( - private route: ActivatedRoute, - private depositRepositoriesService: DepositService, - private uiNotificationService: UiNotificationService, - private httpErrorHandlingService: HttpErrorHandlingService, - private depositOauth2DialogService: DepositOauth2DialogService + private route: ActivatedRoute ) { super(); } @@ -32,42 +19,14 @@ export class DepositOauth2DialogComponent extends BaseComponent implements OnIni error: string = null; ngOnInit(): void { - this.route.paramMap.pipe(takeUntil(this._destroyed)).subscribe((paramMap: ParamMap) => { - let itemId = paramMap.get('id'); - let entityId = paramMap.get('entityId'); - - if (itemId && entityId) { - this.depositRepositoriesService.getRepository(itemId, [ - nameof(x => x.depositType), - nameof(x => x.repositoryId), - nameof(x => x.repositoryAuthorizationUrl), - nameof(x => x.repositoryRecordUrl), - nameof(x => x.repositoryClientId), - nameof(x => x.hasLogo), - nameof(x => x.redirectUri) - ]) - .pipe(takeUntil(this._destroyed)) - .subscribe( - repo => { - this.loadUrl(this.depositOauth2DialogService.getLoginUrl(repo, entityId)); - }, - error => this.onCallbackError(error)); - } else { - this.error = 'Repository id required' - } - }); + this.error = null; this.route.queryParams.pipe(takeUntil(this._destroyed)) .subscribe((params: Params) => { - console.log(params) if (params['url']) { this.loadUrl(params['url']) } else if (params['code']) { - if (!params['state']) { - this.error = 'State required' - - } else { - this.getAccessToken(params['code'], params['state']); - } + localStorage.setItem('repositoryOauthCode', params['code']); + window.close(); } else { this.error = 'Repository id required' } @@ -77,27 +36,4 @@ export class DepositOauth2DialogComponent extends BaseComponent implements OnIni private loadUrl(url: string ) { window.location.href = url; } - - private getAccessToken(code: string, state: string) { - const decoded = decodeURIComponent(state); - const stateParsed = JSON.parse(atob(decoded)); - if (!stateParsed) this.error = 'State required'; - if (!stateParsed.repositoryId) this.error = 'State repository id required'; - if (!stateParsed.entity) this.error = 'State entity required'; - - const depositAuthenticateRequest: DepositAuthenticateRequest = { - repositoryId: stateParsed.repositoryId, - code: code - }; - this.depositRepositoriesService.getAccessToken(depositAuthenticateRequest) - .pipe(takeUntil(this._destroyed)) - .subscribe(token => { - localStorage.setItem('repositoryOauthToken', token); - }, error => this.onCallbackError(error)); - } - - onCallbackError(errorResponse: HttpErrorResponse) { - const error: HttpError = this.httpErrorHandlingService.getError(errorResponse); - this.uiNotificationService.snackBarNotification(error.getMessagesString(), SnackBarNotificationLevel.Warning); - } } diff --git a/dmp-frontend/src/app/ui/misc/deposit-oauth2-dialog/service/deposit-oauth2-dialog.service.ts b/dmp-frontend/src/app/ui/misc/deposit-oauth2-dialog/service/deposit-oauth2-dialog.service.ts index 980498f76..26a02a8b0 100644 --- a/dmp-frontend/src/app/ui/misc/deposit-oauth2-dialog/service/deposit-oauth2-dialog.service.ts +++ b/dmp-frontend/src/app/ui/misc/deposit-oauth2-dialog/service/deposit-oauth2-dialog.service.ts @@ -2,7 +2,6 @@ import { Injectable, Inject } from '@angular/core'; import { BaseService } from '@common/base/base.service'; import { BehaviorSubject, Observable, interval } from 'rxjs'; import { ConfigurationService } from '@app/core/services/configuration/configuration.service'; -import { isNullOrUndefined } from '@app/utilities/enhancers/utils'; import { takeUntil } from 'rxjs/operators'; import { DepositConfiguration } from '@app/core/model/deposit/deposit-configuration'; @@ -15,21 +14,20 @@ export class DepositOauth2DialogService extends BaseService{ super(); } - public getLoginUrl(repo: DepositConfiguration, entityId) { + public getLoginUrl(repo: DepositConfiguration) { return repo.repositoryAuthorizationUrl + '?client_id=' + repo.repositoryClientId - + '&state=' + encodeURIComponent(btoa(JSON.stringify({ repositoryId: repo.repositoryId, entity: entityId }))) + '&response_type=code&scope=deposit:write+deposit:actions+user:email&redirect_uri=' + repo.redirectUri } public login(url: string): Observable { - const windows = window.open(this.configurationService.app + 'oauth2?url=' + encodeURIComponent(url) ,'', `height=500px,width=500px,top=${(window.screen.height / 2) - 200}px,left=${(window.screen.width / 2) - 200}px`); + const windows = window.open(this.configurationService.app + 'deposit/oauth2?url=' + encodeURIComponent(url) ,'', `height=500px,width=500px,top=${(window.screen.height / 2) - 200}px,left=${(window.screen.width / 2) - 200}px`); const sub = interval(300).pipe(takeUntil(this._destroyed)).subscribe(() => { if (windows.closed) { let oauthCode; - if (localStorage.getItem('repositoryOauthToken')) { - oauthCode = localStorage.getItem('repositoryOauthToken'); - localStorage.removeItem('repositoryOauthToken'); + if (localStorage.getItem('repositoryOauthCode')) { + oauthCode = localStorage.getItem('repositoryOauthCode'); + localStorage.removeItem('repositoryOauthCode'); } this.code.next(oauthCode); this.code.next(undefined);