diff --git a/src/app/core/sign-in/sign-in.service.ts b/src/app/core/sign-in/sign-in.service.ts index 072d081e8..90941884c 100644 --- a/src/app/core/sign-in/sign-in.service.ts +++ b/src/app/core/sign-in/sign-in.service.ts @@ -5,6 +5,7 @@ import { HttpParams, } from '@angular/common/http' import { Injectable } from '@angular/core' +import { of } from 'rxjs' import { catchError, map, switchMap, first, take } from 'rxjs/operators' import { getOrcidNumber, isValidOrcidFormat } from '../../constants' @@ -113,6 +114,9 @@ export class SignInService { return this._errorHandler.handleError(error) }), switchMap((response) => { + if (!updateUserSession) { + return of(response) + } // call refreshUserSession with force session update to handle register actions from sessions with a logged in user return this._userService .refreshUserSession(forceSessionUpdate, true) diff --git a/src/app/sign-in/components/form-sign-in/form-sign-in.component.spec.ts b/src/app/sign-in/components/form-sign-in/form-sign-in.component.spec.ts index d8e3db620..391ed4fbc 100644 --- a/src/app/sign-in/components/form-sign-in/form-sign-in.component.spec.ts +++ b/src/app/sign-in/components/form-sign-in/form-sign-in.component.spec.ts @@ -17,6 +17,7 @@ import { OauthService } from '../../../core/oauth/oauth.service' import { CUSTOM_ELEMENTS_SCHEMA } from '@angular/core' import { ReactiveFormsModule } from '@angular/forms' import { Router } from '@angular/router' +import { of } from 'rxjs' describe('FormSignInComponent', () => { let component: FormSignInComponent @@ -71,4 +72,32 @@ describe('FormSignInComponent', () => { expect(routerNavigateSpy).toHaveBeenCalledTimes(1) }) + + it('skips post-login session refresh in oauth2 signin flow', () => { + component.isOauthAuthorizationTogglzEnable = true + component.signInLocal = { isOauth: true, type: 'regular' as any } as any + component.authorizationForm.patchValue({ + username: 'test@example.org', + password: 'secret', + }) + spyOn(component as any, 'handleOauthLogin').and.stub() + + const signInSpy = spyOn( + (component as any)._signIn, + 'signIn' + ).and.returnValue( + of({ + success: true, + url: 'https://qa.orcid.org/oauth/authorize', + } as any) + ) + + component.onSubmit() + + expect(signInSpy).toHaveBeenCalledWith( + jasmine.anything(), + false, + true + ) + }) }) diff --git a/src/app/sign-in/components/form-sign-in/form-sign-in.component.ts b/src/app/sign-in/components/form-sign-in/form-sign-in.component.ts index d2d2f1c2e..ef1b54755 100644 --- a/src/app/sign-in/components/form-sign-in/form-sign-in.component.ts +++ b/src/app/sign-in/components/form-sign-in/form-sign-in.component.ts @@ -205,10 +205,12 @@ export class FormSignInComponent implements OnInit, OnDestroy { this.loading.next(true) const isOauth = this.signInLocal.isOauth - const willNotNavigateOutOrcidAngular = isOauth + const shouldUpdateUserSessionAfterSignIn = !( + isOauth && this.isOauthAuthorizationTogglzEnable + ) const $signIn = this._signIn.signIn( this.signInLocal, - willNotNavigateOutOrcidAngular, + shouldUpdateUserSessionAfterSignIn, true ) this.authorizationFormSubmitted = true