Skip to content

Commit

Permalink
Merge pull request #399 from pagopa/feat/fe-get-client-data
Browse files Browse the repository at this point in the history
FE get client data
  • Loading branch information
sebbalex authored Oct 1, 2024
2 parents e3d3935 + e159407 commit ee082a4
Show file tree
Hide file tree
Showing 3 changed files with 55 additions and 6 deletions.
8 changes: 7 additions & 1 deletion src/oneid/docker_mock/batchDynamo.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
]
},
"logoUri": {
"S": "http://test.com/logo.png"
"S": "https://io.italia.it/assets/img/io-it-logo-blue.svg"
},
"friendlyName": {
"S": "test_16_09"
Expand All @@ -43,6 +43,12 @@
},
"clientId": {
"S": "fM2Ki8PDGjazPFubNtv03FpJZ21CYimrS6-Hnboag1E"
},
"policyUri": {
"S": "https://io.italia.it/privacy-policy/"
},
"tosUri": {
"S": "https://io.italia.it/note-legali/"
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,14 @@ public class ClientFE {
public String clientID;
public String friendlyName;
public String logoUri;
public String ppUri;
public String policyUri;
public String tosUri;

public ClientFE(@NotNull Client client) {
this.clientID = client.getClientId();
this.friendlyName = client.getFriendlyName();
this.logoUri = client.getLogoUri();
this.ppUri = client.getPolicyUri();
this.policyUri = client.getPolicyUri();
this.tosUri = client.getTosUri();
}
}
49 changes: 46 additions & 3 deletions src/oneid/oneid-ecs-core/src/main/webui/src/pages/login/Login.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,14 @@ type BannerContent = {
description: string;
};

type Client = {
clientID: string;
friendlyName: string;
logoUri: string;
policyUri: string;
tosUri: string;
};

export const spidIcon = () => (
<Icon sx={{ width: '25px', height: '25px' }}>
<img src={SpidIcon} width="25" height="25" />
Expand All @@ -45,6 +53,7 @@ const Login = () => {
identityProviders: [],
richiediSpid: '',
});
const [clientData, setClientData] = useState<Client>();

const mapToArray = (json: { [key: string]: BannerContent }) => {
const mapped = Object.values(json);
Expand Down Expand Up @@ -79,9 +88,28 @@ const Login = () => {
}
};

const getClientData = async (clientBaseListUrl: string) => {
try {
const query = new URLSearchParams(window.location.search);
const clientID = query.get('client_id');

if (clientID && clientID.match(/^[A-Za-z0-9_-]{43}$/)) {
const clientListUrl = `${clientBaseListUrl}/${clientID}`;
const response = await fetch(clientListUrl);
const res: Client = await response.json();
setClientData(res);
} else {
console.warn('no client_id supplied, or not valid 32bit Base64Url');
}
} catch (error) {
console.error(error);
}
};

useEffect(() => {
void alertMessage(ENV.JSON_URL.ALERT);
void getIdpList(ENV.JSON_URL.IDP_LIST);
void getClientData(ENV.JSON_URL.CLIENT_BASE_URL);
}, []);

const { t } = useTranslation();
Expand Down Expand Up @@ -118,7 +146,7 @@ const Login = () => {

const redirectPrivacyLink = () =>
trackEvent('LOGIN_PRIVACY', { SPID_IDP_NAME: 'LOGIN_PRIVACY' }, () =>
window.location.assign(ENV.URL_FOOTER.PRIVACY_DISCLAIMER)
window.location.assign(clientData?.policyUri || ENV.URL_FOOTER.PRIVACY_DISCLAIMER)
);

const columnsOccupiedByAlert = 5;
Expand Down Expand Up @@ -160,8 +188,8 @@ const Login = () => {
<Grid item xs={6}>
<Typography
variant="body1"
mb={5}
color="textPrimary"
mb={5}
sx={{
textAlign: 'center',
}}
Expand All @@ -170,6 +198,19 @@ const Login = () => {
</Typography>
</Grid>
</Grid>
{clientData?.logoUri && (
<Grid container item justifyContent="center" textAlign={"center"} mb={2}>
<Grid item xs={6}>
<Icon>
<img
style={{ display: 'flex', height: 'inherit', width: 'inherit' }}
src={clientData?.logoUri}
alt={clientData?.friendlyName}
/>
</Icon>
</Grid>
</Grid>
)}
{ENV.ENABLED_SPID_TEMPORARY_SELECT && (
<Grid container justifyContent="center" mb={5}>
<Grid item>
Expand Down Expand Up @@ -287,7 +328,9 @@ const Login = () => {
}}
onClick={() => {
trackEvent('LOGIN_TOS', { SPID_IDP_NAME: 'LOGIN_TOS' }, () =>
window.location.assign(ENV.URL_FOOTER.TERMS_AND_CONDITIONS)
window.location.assign(
clientData?.tosUri || ENV.URL_FOOTER.TERMS_AND_CONDITIONS
)
);
}}
>
Expand Down

0 comments on commit ee082a4

Please sign in to comment.