import _ = require ( 'lodash' ) ; import { EidasAttributes , EidasLevelOfAssurances , EidasResponseAttributes , } from '@fc/eidas' ; import { AcrValues , IOidcIdentity } from '@fc/oidc' ; export const LevelOfAssurancesToAcrValueMap = { [ EidasLevelOfAssurances . LOW ] : AcrValues . EIDAS1 , [ EidasLevelOfAssurances . SUBSTANTIAL ] : AcrValues . EIDAS2 , [ EidasLevelOfAssurances . HIGH ] : AcrValues . EIDAS3 , } ; export const RequestedAttributesToScopesMap = { [ EidasAttributes . PERSON_IDENTIFIER ] : [ 'openid' ] , [ EidasAttributes . CURRENT_GIVEN_NAME ] : [ 'given_name' ] , [ EidasAttributes . CURRENT_FAMILY_NAME ] : [ 'preferred_username' , 'family_name' ] , [ EidasAttributes . BIRTH_NAME ] : [ 'family_name' ] , [ EidasAttributes . DATE_OF_BIRTH ] : [ 'birthdate' ] , [ EidasAttributes . PLACE_OF_BIRTH ] : [ 'birthplace' , 'birthcountry' ] , [ EidasAttributes . GENDER ] : [ 'gender' ] , } ; function getSub ( attributes ) { const [ sub ] = attributes . personIdentifier || [ ] ; return { sub } ; } function getGender ( attributes ) { const [ eidasGender ] = attributes . gender || [ ] ; let gender ; if ( eidasGender ) { gender = _ . lowerFirst ( eidasGender ) ; } return { gender } ; } function getBirthdate ( attributes ) { const [ birthdate ] = attributes . dateOfBirth || [ ] ; return { birthdate } ; } function getBirthplace ( attributes ) { const [ birthplace ] = attributes . placeOfBirth || [ ] ; return { birthplace } ; } function getGivenNames ( attributes ) { const given_name = attributes . currentGivenName ?. join ( ' ' ) ; return { given_name } ; } function getFamilyName ( attributes ) { const [ family_name ] = attributes . currentFamilyName || [ ] ; return { family_name } ; } export const AttributesToClaimsMap = { [ EidasAttributes . PERSON_IDENTIFIER ] : getSub , [ EidasAttributes . GENDER ] : getGender , [ EidasAttributes . DATE_OF_BIRTH ] : getBirthdate , [ EidasAttributes . PLACE_OF_BIRTH ] : getBirthplace , [ EidasAttributes . CURRENT_GIVEN_NAME ] : getGivenNames , [ EidasAttributes . CURRENT_FAMILY_NAME ] : getFamilyName , } ;