Skip to content

Commit e12531a

Browse files
authored
Merge pull request #2831 from ORCID/lmendoza/PD-5529-v2
PD-5529
2 parents f89886a + a40ba42 commit e12531a

3 files changed

Lines changed: 37 additions & 2 deletions

File tree

src/app/core/sign-in/sign-in.service.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import {
55
HttpParams,
66
} from '@angular/common/http'
77
import { Injectable } from '@angular/core'
8+
import { of } from 'rxjs'
89
import { catchError, map, switchMap, first, take } from 'rxjs/operators'
910

1011
import { getOrcidNumber, isValidOrcidFormat } from '../../constants'
@@ -113,6 +114,9 @@ export class SignInService {
113114
return this._errorHandler.handleError(error)
114115
}),
115116
switchMap((response) => {
117+
if (!updateUserSession) {
118+
return of(response)
119+
}
116120
// call refreshUserSession with force session update to handle register actions from sessions with a logged in user
117121
return this._userService
118122
.refreshUserSession(forceSessionUpdate, true)

src/app/sign-in/components/form-sign-in/form-sign-in.component.spec.ts

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ import { OauthService } from '../../../core/oauth/oauth.service'
1717
import { CUSTOM_ELEMENTS_SCHEMA } from '@angular/core'
1818
import { ReactiveFormsModule } from '@angular/forms'
1919
import { Router } from '@angular/router'
20+
import { of } from 'rxjs'
2021

2122
describe('FormSignInComponent', () => {
2223
let component: FormSignInComponent
@@ -71,4 +72,32 @@ describe('FormSignInComponent', () => {
7172

7273
expect(routerNavigateSpy).toHaveBeenCalledTimes(1)
7374
})
75+
76+
it('skips post-login session refresh in oauth2 signin flow', () => {
77+
component.isOauthAuthorizationTogglzEnable = true
78+
component.signInLocal = { isOauth: true, type: 'regular' as any } as any
79+
component.authorizationForm.patchValue({
80+
username: 'test@example.org',
81+
password: 'secret',
82+
})
83+
spyOn(component as any, 'handleOauthLogin').and.stub()
84+
85+
const signInSpy = spyOn(
86+
(component as any)._signIn,
87+
'signIn'
88+
).and.returnValue(
89+
of({
90+
success: true,
91+
url: 'https://qa.orcid.org/oauth/authorize',
92+
} as any)
93+
)
94+
95+
component.onSubmit()
96+
97+
expect(signInSpy).toHaveBeenCalledWith(
98+
jasmine.anything(),
99+
false,
100+
true
101+
)
102+
})
74103
})

src/app/sign-in/components/form-sign-in/form-sign-in.component.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -205,10 +205,12 @@ export class FormSignInComponent implements OnInit, OnDestroy {
205205
this.loading.next(true)
206206

207207
const isOauth = this.signInLocal.isOauth
208-
const willNotNavigateOutOrcidAngular = isOauth
208+
const shouldUpdateUserSessionAfterSignIn = !(
209+
isOauth && this.isOauthAuthorizationTogglzEnable
210+
)
209211
const $signIn = this._signIn.signIn(
210212
this.signInLocal,
211-
willNotNavigateOutOrcidAngular,
213+
shouldUpdateUserSessionAfterSignIn,
212214
true
213215
)
214216
this.authorizationFormSubmitted = true

0 commit comments

Comments
 (0)