diff --git a/src/app/app.module.ts b/src/app/app.module.ts index 8eebba86f1..a85eb8345d 100644 --- a/src/app/app.module.ts +++ b/src/app/app.module.ts @@ -11,6 +11,8 @@ import { LayoutModule } from './layout/layout.module' import { BidiModule } from '@angular/cdk/bidi' import { PseudoModule } from 'src/locale/i18n.pseudo.component' import { TitleService } from './core/title-service/title.service' +import { HttpContentTypeHeaderInterceptor } from './core/http-content-type-header-interceptor/http-content-type-header-interceptor' +import { HTTP_INTERCEPTORS } from '@angular/common/http' @NgModule({ declarations: [AppComponent], @@ -25,7 +27,7 @@ import { TitleService } from './core/title-service/title.service' // Environmental dependent modules environment.SHOW_TEST_WARNING_BANNER ? EnvironmentBannerModule : [], ], - providers: [TitleService], + providers: [TitleService, {provide:HTTP_INTERCEPTORS, useClass:HttpContentTypeHeaderInterceptor, multi:true}], bootstrap: [AppComponent], }) export class AppModule { diff --git a/src/app/core/account-actions-deactivate/account-actions-deactivate.service.ts b/src/app/core/account-actions-deactivate/account-actions-deactivate.service.ts index 0fc8581059..4612a8659a 100644 --- a/src/app/core/account-actions-deactivate/account-actions-deactivate.service.ts +++ b/src/app/core/account-actions-deactivate/account-actions-deactivate.service.ts @@ -12,7 +12,6 @@ import { ErrorHandlerService } from '../error-handler/error-handler.service' export class AccountActionsDeactivateService { headers = new HttpHeaders({ 'Access-Control-Allow-Origin': '*', - 'Content-Type': 'text/plain charset=utf-8', }) options: { headers: any; responseType: 'text' } diff --git a/src/app/core/account-actions-download/account-actions-download.service.ts b/src/app/core/account-actions-download/account-actions-download.service.ts index d135021836..32d0b805dd 100644 --- a/src/app/core/account-actions-download/account-actions-download.service.ts +++ b/src/app/core/account-actions-download/account-actions-download.service.ts @@ -1,4 +1,4 @@ -import { HttpClient, HttpHeaders } from '@angular/common/http' +import { HttpClient } from '@angular/common/http' import { Inject, Injectable } from '@angular/core' import { catchError, retry, tap } from 'rxjs/operators' import { WINDOW } from 'src/app/cdk/window' @@ -9,10 +9,7 @@ import { ErrorHandlerService } from '../error-handler/error-handler.service' providedIn: 'root', }) export class AccountActionsDownloadService { - headers = new HttpHeaders({ - 'Access-Control-Allow-Origin': '*', - 'Content-Type': 'application/json', - }) + constructor( private _errorHandler: ErrorHandlerService, private _http: HttpClient, diff --git a/src/app/core/account-actions-duplicated/account-actions-duplicated.service.ts b/src/app/core/account-actions-duplicated/account-actions-duplicated.service.ts index 61b225068a..4dab746f23 100644 --- a/src/app/core/account-actions-duplicated/account-actions-duplicated.service.ts +++ b/src/app/core/account-actions-duplicated/account-actions-duplicated.service.ts @@ -13,8 +13,7 @@ import { ErrorHandlerService } from '../error-handler/error-handler.service' }) export class AccountActionsDuplicatedService { headers = new HttpHeaders({ - 'Access-Control-Allow-Origin': '*', - 'Content-Type': 'application/json', + 'Access-Control-Allow-Origin': '*', }) constructor( private _errorHandler: ErrorHandlerService, diff --git a/src/app/core/account-default-email-frequencies/account-default-email-frequencies.service.ts b/src/app/core/account-default-email-frequencies/account-default-email-frequencies.service.ts index 6262e0f97f..1089931de6 100644 --- a/src/app/core/account-default-email-frequencies/account-default-email-frequencies.service.ts +++ b/src/app/core/account-default-email-frequencies/account-default-email-frequencies.service.ts @@ -12,8 +12,7 @@ import { ErrorHandlerService } from '../error-handler/error-handler.service' }) export class AccountDefaultEmailFrequenciesService { headers = new HttpHeaders({ - 'Access-Control-Allow-Origin': '*', - 'Content-Type': 'application/json', + 'Access-Control-Allow-Origin': '*', }) constructor( private _errorHandler: ErrorHandlerService, diff --git a/src/app/core/account-default-visibility/account-default-visibility.service.ts b/src/app/core/account-default-visibility/account-default-visibility.service.ts index 0619b41a00..185b9f6f5b 100644 --- a/src/app/core/account-default-visibility/account-default-visibility.service.ts +++ b/src/app/core/account-default-visibility/account-default-visibility.service.ts @@ -11,8 +11,7 @@ import { ErrorHandlerService } from '../error-handler/error-handler.service' }) export class AccountDefaultVisibilityService { headers = new HttpHeaders({ - 'Access-Control-Allow-Origin': '*', - 'Content-Type': 'application/json', + 'Access-Control-Allow-Origin': '*', }) constructor( diff --git a/src/app/core/account-security-alternate-sign-in/account-security-alternate-sign-in.service.ts b/src/app/core/account-security-alternate-sign-in/account-security-alternate-sign-in.service.ts index 3a6500858d..99f43d8909 100644 --- a/src/app/core/account-security-alternate-sign-in/account-security-alternate-sign-in.service.ts +++ b/src/app/core/account-security-alternate-sign-in/account-security-alternate-sign-in.service.ts @@ -19,8 +19,7 @@ import { ErrorHandlerService } from '../error-handler/error-handler.service' }) export class AccountSecurityAlternateSignInService { headers = new HttpHeaders({ - 'Access-Control-Allow-Origin': '*', - 'Content-Type': 'application/json', + 'Access-Control-Allow-Origin': '*', }) constructor( private _errorHandler: ErrorHandlerService, diff --git a/src/app/core/account-security-password/account-security-password.service.ts b/src/app/core/account-security-password/account-security-password.service.ts index 54d436a513..fe82310a29 100644 --- a/src/app/core/account-security-password/account-security-password.service.ts +++ b/src/app/core/account-security-password/account-security-password.service.ts @@ -13,7 +13,6 @@ import { ErrorHandlerService } from '../error-handler/error-handler.service' export class AccountSecurityPasswordService { headers = new HttpHeaders({ 'Access-Control-Allow-Origin': '*', - 'Content-Type': 'application/json', }) constructor( diff --git a/src/app/core/account-trusted-individuals/account-trusted-individuals.service.ts b/src/app/core/account-trusted-individuals/account-trusted-individuals.service.ts index 60edb6db5e..94a6a3c4e3 100644 --- a/src/app/core/account-trusted-individuals/account-trusted-individuals.service.ts +++ b/src/app/core/account-trusted-individuals/account-trusted-individuals.service.ts @@ -22,7 +22,6 @@ export class AccountTrustedIndividualsService { headers = new HttpHeaders({ 'Access-Control-Allow-Origin': '*', - 'Content-Type': 'application/json', }) constructor( private _errorHandler: ErrorHandlerService, diff --git a/src/app/core/account-trusted-organizations/account-trusted-organizations.service.ts b/src/app/core/account-trusted-organizations/account-trusted-organizations.service.ts index 751fdfcc1e..2f15fd2b92 100644 --- a/src/app/core/account-trusted-organizations/account-trusted-organizations.service.ts +++ b/src/app/core/account-trusted-organizations/account-trusted-organizations.service.ts @@ -13,7 +13,6 @@ import { ErrorHandlerService } from '../error-handler/error-handler.service' export class AccountTrustedOrganizationsService { headers = new HttpHeaders({ 'Access-Control-Allow-Origin': '*', - 'Content-Type': 'application/json', }) constructor( private _errorHandler: ErrorHandlerService, diff --git a/src/app/core/http-content-type-header-interceptor/http-content-type-header-interceptor.ts b/src/app/core/http-content-type-header-interceptor/http-content-type-header-interceptor.ts new file mode 100644 index 0000000000..c5ec0abedc --- /dev/null +++ b/src/app/core/http-content-type-header-interceptor/http-content-type-header-interceptor.ts @@ -0,0 +1,34 @@ +import { HttpHandler, HttpInterceptor, HttpRequest } from "@angular/common/http"; +import { Injectable } from "@angular/core"; + +@Injectable() +export class HttpContentTypeHeaderInterceptor implements HttpInterceptor { + + private formUrlEcondedUrls = ["/sendReactivation.json", "/social/signin/auth.json", "/shibboleth/signin/auth.json", "/signin/auth.json"]; + + construct () { + + } + + intercept(req:HttpRequest, next: HttpHandler) { + var method = req.method + var urlWithParams = req.urlWithParams + // If the request contains a content type, be sure to set the encoding to utf-8 + if(['POST', 'PUT'].includes(method)) { + var clonedRequest; + if(this.formUrlEcondedUrls.includes(urlWithParams)) { + clonedRequest = req.clone({ + headers: req.headers.set('Content-Type', 'application/x-www-form-urlencoded;charset=utf-8') + }); + } else { + clonedRequest = req.clone({ + headers: req.headers.set('Content-Type', 'application/json;charset=utf-8') + }); + } + + return next.handle(clonedRequest); + } + // Nothing changed, continue using the same request object + return next.handle(req); + } +} \ No newline at end of file diff --git a/src/app/core/inbox/inbox.service.ts b/src/app/core/inbox/inbox.service.ts index 7dec0a0144..c2bd0d9e4b 100644 --- a/src/app/core/inbox/inbox.service.ts +++ b/src/app/core/inbox/inbox.service.ts @@ -45,7 +45,6 @@ export class InboxService { ) { this.headers = new HttpHeaders({ 'Access-Control-Allow-Origin': '*', - 'Content-Type': 'application/json', }) } diff --git a/src/app/core/oauth/oauth.service.ts b/src/app/core/oauth/oauth.service.ts index a28340c8aa..0d01ef65ad 100644 --- a/src/app/core/oauth/oauth.service.ts +++ b/src/app/core/oauth/oauth.service.ts @@ -47,7 +47,6 @@ export class OauthService { ) { this.headers = new HttpHeaders({ 'Access-Control-Allow-Origin': '*', - 'Content-Type': 'application/json', }) } diff --git a/src/app/core/password-recovery/password-recovery.service.ts b/src/app/core/password-recovery/password-recovery.service.ts index a7ac5dc27b..ceecff6914 100644 --- a/src/app/core/password-recovery/password-recovery.service.ts +++ b/src/app/core/password-recovery/password-recovery.service.ts @@ -20,7 +20,6 @@ export class PasswordRecoveryService { ) {} headers = new HttpHeaders({ 'Access-Control-Allow-Origin': '*', - 'Content-Type': 'application/json', }) resetPassword(data) { diff --git a/src/app/core/record-affiliations/record-affiliations.service.ts b/src/app/core/record-affiliations/record-affiliations.service.ts index 0afcb677a9..a5f11b82fd 100644 --- a/src/app/core/record-affiliations/record-affiliations.service.ts +++ b/src/app/core/record-affiliations/record-affiliations.service.ts @@ -27,7 +27,6 @@ export class RecordAffiliationService { lastEmittedValue: AffiliationUIGroup[] headers = new HttpHeaders({ 'Access-Control-Allow-Origin': '*', - 'Content-Type': 'application/json', }) $affiliations: ReplaySubject diff --git a/src/app/core/record-biography/record-biography.service.ts b/src/app/core/record-biography/record-biography.service.ts index 3517bda324..752c51a1db 100644 --- a/src/app/core/record-biography/record-biography.service.ts +++ b/src/app/core/record-biography/record-biography.service.ts @@ -15,7 +15,6 @@ export class RecordBiographyService { $biography: ReplaySubject headers = new HttpHeaders({ 'Access-Control-Allow-Origin': '*', - 'Content-Type': 'application/json', }) constructor( diff --git a/src/app/core/record-countries/record-countries.service.ts b/src/app/core/record-countries/record-countries.service.ts index 96bc5161fc..34df04e2ef 100644 --- a/src/app/core/record-countries/record-countries.service.ts +++ b/src/app/core/record-countries/record-countries.service.ts @@ -18,7 +18,6 @@ export class RecordCountriesService { $addresses: ReplaySubject headers = new HttpHeaders({ 'Access-Control-Allow-Origin': '*', - 'Content-Type': 'application/json', }) constructor( diff --git a/src/app/core/record-emails/record-emails.service.ts b/src/app/core/record-emails/record-emails.service.ts index 567c34493a..a1ffbdabad 100644 --- a/src/app/core/record-emails/record-emails.service.ts +++ b/src/app/core/record-emails/record-emails.service.ts @@ -25,7 +25,6 @@ import { RecordPublicSideBarService } from '../record-public-side-bar/record-pub export class RecordEmailsService { headers = new HttpHeaders({ 'Access-Control-Allow-Origin': '*', - 'Content-Type': 'application/json', }) private $emailsSubject diff --git a/src/app/core/record-fundings/record-fundings.service.ts b/src/app/core/record-fundings/record-fundings.service.ts index 6b1cfb5c4f..541c51e148 100644 --- a/src/app/core/record-fundings/record-fundings.service.ts +++ b/src/app/core/record-fundings/record-fundings.service.ts @@ -16,8 +16,7 @@ import { RecordImportWizard } from '../../types/record-peer-review-import.endpoi export class RecordFundingsService { lastEmittedValue: FundingGroup[] headers = new HttpHeaders({ - 'Access-Control-Allow-Origin': '*', - 'Content-Type': 'application/json', + 'Access-Control-Allow-Origin': '*', }) $fundings: ReplaySubject = new ReplaySubject() diff --git a/src/app/core/record-keyword/record-keyword.service.ts b/src/app/core/record-keyword/record-keyword.service.ts index db5fc6e895..888fe0e011 100644 --- a/src/app/core/record-keyword/record-keyword.service.ts +++ b/src/app/core/record-keyword/record-keyword.service.ts @@ -15,7 +15,6 @@ export class RecordKeywordService { $keywords: ReplaySubject headers = new HttpHeaders({ 'Access-Control-Allow-Origin': '*', - 'Content-Type': 'application/json', }) constructor( diff --git a/src/app/core/record-names/record-names.service.ts b/src/app/core/record-names/record-names.service.ts index f507cf91cb..43cc5e14ca 100644 --- a/src/app/core/record-names/record-names.service.ts +++ b/src/app/core/record-names/record-names.service.ts @@ -15,7 +15,6 @@ export class RecordNamesService { $names: ReplaySubject headers = new HttpHeaders({ 'Access-Control-Allow-Origin': '*', - 'Content-Type': 'application/json', }) constructor( diff --git a/src/app/core/record-other-names/record-other-names.service.ts b/src/app/core/record-other-names/record-other-names.service.ts index adedf85f8d..256c27be8a 100644 --- a/src/app/core/record-other-names/record-other-names.service.ts +++ b/src/app/core/record-other-names/record-other-names.service.ts @@ -16,7 +16,6 @@ export class RecordOtherNamesService { $otherNames: ReplaySubject headers = new HttpHeaders({ 'Access-Control-Allow-Origin': '*', - 'Content-Type': 'application/json', }) constructor( diff --git a/src/app/core/record-peer-review/record-peer-review.service.ts b/src/app/core/record-peer-review/record-peer-review.service.ts index b16ff33c36..8b88d1d68e 100644 --- a/src/app/core/record-peer-review/record-peer-review.service.ts +++ b/src/app/core/record-peer-review/record-peer-review.service.ts @@ -17,7 +17,6 @@ export class RecordPeerReviewService { $peer: ReplaySubject = new ReplaySubject() headers = new HttpHeaders({ 'Access-Control-Allow-Origin': '*', - 'Content-Type': 'application/json', }) lastEmittedValue: PeerReview[] diff --git a/src/app/core/record-personal-identifiers/record-person-identifier.service.ts b/src/app/core/record-personal-identifiers/record-person-identifier.service.ts index 6d82f3be31..dd3c7c1f4a 100644 --- a/src/app/core/record-personal-identifiers/record-person-identifier.service.ts +++ b/src/app/core/record-personal-identifiers/record-person-identifier.service.ts @@ -18,7 +18,6 @@ export class RecordPersonIdentifierService { $privatePersonIdentifier: ReplaySubject headers = new HttpHeaders({ 'Access-Control-Allow-Origin': '*', - 'Content-Type': 'application/json', }) constructor( diff --git a/src/app/core/record-public-side-bar/record-public-side-bar.service.ts b/src/app/core/record-public-side-bar/record-public-side-bar.service.ts index a973b09c3f..5bf405ef33 100644 --- a/src/app/core/record-public-side-bar/record-public-side-bar.service.ts +++ b/src/app/core/record-public-side-bar/record-public-side-bar.service.ts @@ -24,7 +24,6 @@ export class RecordPublicSideBarService { headers = new HttpHeaders({ 'Access-Control-Allow-Origin': '*', - 'Content-Type': 'application/json', }) getPublicRecordSideBar( diff --git a/src/app/core/record-research-resource/record-research-resource.service.ts b/src/app/core/record-research-resource/record-research-resource.service.ts index be6f1c40bf..887a3d5d56 100644 --- a/src/app/core/record-research-resource/record-research-resource.service.ts +++ b/src/app/core/record-research-resource/record-research-resource.service.ts @@ -22,7 +22,6 @@ export class RecordResearchResourceService { headers = new HttpHeaders({ 'Access-Control-Allow-Origin': '*', - 'Content-Type': 'application/json', }) constructor( diff --git a/src/app/core/record-websites/record-websites.service.ts b/src/app/core/record-websites/record-websites.service.ts index ddfa28cda4..d6db5a7a70 100644 --- a/src/app/core/record-websites/record-websites.service.ts +++ b/src/app/core/record-websites/record-websites.service.ts @@ -15,7 +15,6 @@ export class RecordWebsitesService { $websites: ReplaySubject headers = new HttpHeaders({ 'Access-Control-Allow-Origin': '*', - 'Content-Type': 'application/json', }) constructor( diff --git a/src/app/core/record-works/record-works.service.ts b/src/app/core/record-works/record-works.service.ts index 747125cb14..c4abb9ae16 100644 --- a/src/app/core/record-works/record-works.service.ts +++ b/src/app/core/record-works/record-works.service.ts @@ -430,8 +430,7 @@ export class RecordWorksService { JSON.stringify(obj), { headers: { - 'Access-Control-Allow-Origin': '*', - 'Content-Type': 'application/json', + 'Access-Control-Allow-Origin': '*', }, } ) @@ -448,7 +447,6 @@ export class RecordWorksService { { headers: { 'Access-Control-Allow-Origin': '*', - 'Content-Type': 'application/json', }, } ) diff --git a/src/app/core/record/record.service.ts b/src/app/core/record/record.service.ts index 1081d746be..2086c5ba69 100644 --- a/src/app/core/record/record.service.ts +++ b/src/app/core/record/record.service.ts @@ -79,7 +79,6 @@ export class RecordService { headers = new HttpHeaders({ 'Access-Control-Allow-Origin': '*', - 'Content-Type': 'application/json', }) subscriptionSourceCountDebugger = 0 diff --git a/src/app/core/sign-in/sign-in.service.ts b/src/app/core/sign-in/sign-in.service.ts index a51d1f76ec..5fc29e753f 100644 --- a/src/app/core/sign-in/sign-in.service.ts +++ b/src/app/core/sign-in/sign-in.service.ts @@ -1,4 +1,4 @@ -import { HttpClient, HttpHeaders, HttpParams } from '@angular/common/http' +import { HttpClient, HttpParams } from '@angular/common/http' import { Injectable } from '@angular/core' import { catchError, map, retry, switchMap, first } from 'rxjs/operators' @@ -16,8 +16,7 @@ import { Title } from '@angular/platform-browser' @Injectable({ providedIn: 'root', }) -export class SignInService { - private headers: HttpHeaders +export class SignInService { constructor( private _http: HttpClient, @@ -25,10 +24,7 @@ export class SignInService { private _errorHandler: ErrorHandlerService, private _userService: UserService ) { - this.headers = new HttpHeaders().set( - 'Content-Type', - 'application/x-www-form-urlencoded;charset=utf-8' - ) + } /** * @param SignInLocal sign in information @@ -61,8 +57,7 @@ export class SignInService { } body = body.set('oauthRequest', signInLocal.isOauth ? 'true' : 'false') return this._http - .post(environment.API_WEB + loginUrl, body, { - headers: this.headers, + .post(environment.API_WEB + loginUrl, body, { withCredentials: true, }) .pipe( @@ -84,8 +79,7 @@ export class SignInService { let body = new HttpParams({ encoder: new CustomEncoder() }) body = body.set('email', email) return this._http - .post(environment.API_WEB + `sendReactivation.json`, body, { - headers: this.headers, + .post(environment.API_WEB + `sendReactivation.json`, body, { withCredentials: true, }) .pipe( @@ -102,8 +96,7 @@ export class SignInService { singOut() { this._titleService.setTitle('ORCID') return this._http - .get(environment.API_WEB + 'userStatus.json?logUserOut=true', { - headers: this.headers, + .get(environment.API_WEB + 'userStatus.json?logUserOut=true', { withCredentials: true, }) .pipe( diff --git a/src/app/core/trusted-summary/trusted-summary.service.ts b/src/app/core/trusted-summary/trusted-summary.service.ts index ad717969dc..b30169e3a6 100644 --- a/src/app/core/trusted-summary/trusted-summary.service.ts +++ b/src/app/core/trusted-summary/trusted-summary.service.ts @@ -13,7 +13,6 @@ import { ERROR_REPORT } from 'src/app/errors' export class TrustedSummaryService { headers = new HttpHeaders({ 'Access-Control-Allow-Origin': '*', - 'Content-Type': 'application/json', }) constructor( diff --git a/src/app/core/two-factor-authentication/two-factor-authentication.service.ts b/src/app/core/two-factor-authentication/two-factor-authentication.service.ts index c2bf4548da..d8dad0fcdb 100644 --- a/src/app/core/two-factor-authentication/two-factor-authentication.service.ts +++ b/src/app/core/two-factor-authentication/two-factor-authentication.service.ts @@ -18,7 +18,6 @@ import { ErrorHandlerService } from '../error-handler/error-handler.service' export class TwoFactorAuthenticationService { headers = new HttpHeaders({ 'Access-Control-Allow-Origin': '*', - 'Content-Type': 'application/json', }) constructor( diff --git a/src/app/core/user/user.service.ts b/src/app/core/user/user.service.ts index aa6682e98c..265d1f69de 100644 --- a/src/app/core/user/user.service.ts +++ b/src/app/core/user/user.service.ts @@ -54,7 +54,6 @@ import { UserInfoService } from '../user-info/user-info.service' export class UserService { headers = new HttpHeaders({ 'Access-Control-Allow-Origin': '*', - 'Content-Type': 'application/json', }) constructor(