Skip to content

Commit def519a

Browse files
committed
replace eserviceid with formsg's if not supplied
1 parent 5ce0652 commit def519a

File tree

4 files changed

+22
-21
lines changed

4 files changed

+22
-21
lines changed

src/app/modules/form/public-form/public-form.controller.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ import { MyInfoService } from '../../myinfo/myinfo.service'
3131
import {
3232
createMyInfoLoginCookie,
3333
extractAuthCode,
34-
validateMyInfoForm,
34+
getMyInfoEserviceIdInForm,
3535
} from '../../myinfo/myinfo.util'
3636
import { SGIDMyInfoData } from '../../sgid/sgid.adapter'
3737
import {
@@ -647,9 +647,9 @@ export const _handleFormAuthRedirect: ControllerHandler<
647647
formAuthType = form.authType
648648
switch (form.authType) {
649649
case FormAuthType.MyInfo:
650-
return validateMyInfoForm(form).andThen((form) =>
650+
return getMyInfoEserviceIdInForm(form).andThen(([form, eserviceId]) =>
651651
MyInfoService.createRedirectURL({
652-
formEsrvcId: form.esrvcId,
652+
formEsrvcId: eserviceId,
653653
formId,
654654
requestedAttributes: form.getUniqueMyInfoAttrs(),
655655
encodedQuery,

src/app/modules/myinfo/myinfo.controller.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ import {
1818
MyInfoAuthCodeCookieState,
1919
MyInfoAuthCodeSuccessPayload,
2020
} from './myinfo.types'
21-
import { mapRedirectURLError, validateMyInfoForm } from './myinfo.util'
21+
import { getMyInfoEserviceIdInForm, mapRedirectURLError } from './myinfo.util'
2222

2323
const logger = createLoggerWithLabel(module)
2424

@@ -48,10 +48,10 @@ export const respondWithRedirectURL: ControllerHandler<
4848
> = async (req, res) => {
4949
const { formId, encodedQuery } = req.query
5050
return FormService.retrieveFormById(formId)
51-
.andThen((form) => validateMyInfoForm(form))
52-
.andThen((form) =>
51+
.andThen((form) => getMyInfoEserviceIdInForm(form))
52+
.andThen(([form, eserviceId]) =>
5353
MyInfoService.createRedirectURL({
54-
formEsrvcId: form.esrvcId,
54+
formEsrvcId: eserviceId,
5555
formId,
5656
requestedAttributes: form.getUniqueMyInfoAttrs(),
5757
encodedQuery,

src/app/modules/myinfo/myinfo.service.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -61,12 +61,12 @@ import {
6161
createRelayState,
6262
getMyInfoAttr,
6363
getMyInfoAttributeConstantsList,
64+
getMyInfoEserviceIdInForm,
6465
hashFieldValues,
6566
isMyInfoChildrenBirthRecords,
6667
isMyInfoLoginCookie,
6768
isMyInfoRelayState,
6869
logIfFieldValueNotInMyinfoList,
69-
validateMyInfoForm,
7070
} from './myinfo.util'
7171
import getMyInfoHashModel from './myinfo_hash.model'
7272

@@ -500,13 +500,13 @@ export class MyInfoServiceClass {
500500
| MyInfoFetchError
501501
> {
502502
const requestedAttributes = form.getUniqueMyInfoAttrs()
503-
return validateMyInfoForm(form).asyncAndThen((form) =>
503+
return getMyInfoEserviceIdInForm(form).asyncAndThen(([, eserviceId]) =>
504504
ResultAsync.fromPromise(
505505
this.#myInfoPersonBreaker
506506
.fire(
507507
accessToken,
508508
internalAttrListToScopes(requestedAttributes),
509-
form.esrvcId,
509+
eserviceId,
510510
)
511511
.then((response) => new MyInfoData(response)),
512512
(error) => {

src/app/modules/myinfo/myinfo.util.ts

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -314,26 +314,27 @@ export const createRelayState = (
314314
})
315315

316316
/**
317-
* Validates that a form is a MyInfo form with an e-service ID
317+
* returns form with an e-service ID if form is a MyInfo form
318318
* @param form Form to validate
319319
*/
320-
export const validateMyInfoForm = <T extends IFormSchema>(
320+
export const getMyInfoEserviceIdInForm = <T extends IFormSchema>(
321321
form: T,
322-
): Result<MyInfoForm<T>, FormAuthNoEsrvcIdError | AuthTypeMismatchError> => {
323-
if (!form.esrvcId) {
324-
return err(new FormAuthNoEsrvcIdError(form._id))
325-
}
326-
if (isMyInfoFormWithEsrvcId(form)) {
327-
return ok(form)
322+
): Result<
323+
[MyInfoForm<T>, string],
324+
FormAuthNoEsrvcIdError | AuthTypeMismatchError
325+
> => {
326+
if (isMyInfoForm(form)) {
327+
const esrvcId = form.esrvcId || spcpMyInfoConfig.spEsrvcId
328+
return ok([form, esrvcId])
328329
}
329330
return err(new AuthTypeMismatchError(FormAuthType.MyInfo, form.authType))
330331
}
331332

332-
// Typeguard to ensure that form has eserviceId and MyInfo authType
333-
const isMyInfoFormWithEsrvcId = <F extends IFormSchema>(
333+
// Typeguard to ensure that form is MyInfo authType
334+
const isMyInfoForm = <F extends IFormSchema>(
334335
form: F,
335336
): form is MyInfoForm<F> => {
336-
return form.authType === FormAuthType.MyInfo && !!form.esrvcId
337+
return form.authType === FormAuthType.MyInfo
337338
}
338339

339340
/**

0 commit comments

Comments
 (0)