Skip to content
Merged

PD-5529 #2831

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions src/app/core/sign-in/sign-in.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down Expand Up @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
)
})
})
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Loading