Creation of PWA on a JSF website with a SSO

Viewed 384

I have a project made in JSF and primefaces. I tryed many things but i'm still having some problem to make it work. My job is implementing the possibility to use the website as a PWA with offline cache.

But i'm facing some issues, in fact, i don't have a proper index.xhtml.

All it begin with a redirection to a SSO made with https://www.keycloak.org/. But we don't have a hand on this.

So i had to find a way to make it work.

In fact :

-first i try to put the manifest.json and the script link for the serviceworker inside the page redirection before the SSO.

-second i try to put it in the page after the SSO.

Therefor, the first way didnt work, and i might need to include all of this in the keycloak SSO. But the second idea didnt work aswell, so i don't know if my problem is about the start_url / scope that is clearly different on each point. I try to find a proper way to make it. But there are nothing on the internet and this kind of question. The serviceworker doesnt work, and the manifest is not found.

Our pages use a template show below

<h:head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
    <meta name="viewport" content="width=device-width, height=device-height,  initial-scale=1.0, user-scalable=no;user-scalable=0, shrink-to-fit=no;"/>
    <link rel="shortcut icon" type="image/x-icon" href="#{request.contextPath}/resources/img/flash-23.png"/>

    <ui:include src="../head.xhtml"/>
<!--    <ui:include src="../serviceworker.xhtml"/>-->
</h:head>

and inside the head :

    <link rel="apple-touch-icon" href="#{request.contextPath}/resources/img/icon-pwa-192x192.png"/>
    <link rel="manifest" href="#{request.contextPath}/resources/manifest/manifest.json"/>
    <link type="text/css" rel="stylesheet"
          href="#{request.contextPath}/javax.faces.resource/theme.css.faces?ln=primefaces-alice&amp;v=#{utilBean.version}"/>

I will give you aswell the manifest.json

{
    "dir" : "ltr",
    "lang" : "fr",
    "name": "Espace Client ÉS",
    "scope" : "/",
    "description": "« description »Espace client ÉS qui permet de gérer ses contrats ÉS. Gérez vos contrats ÉS. Consultez vos factures en ligne. Et suivre vos consommations.",
    "short_name": "ÉS & Moi",
    "start_url": "https://auth.es.fr/auth/realms/espace-client-sso/protocol/openid-connect/auth?response_type=code&client_id=ALICE_CLIENT&redirect_uri=http%3A%2F%2Fespaceclient.es.fr%2Falice-ael%2Fsso%2Flogin&state=4696387f-46b2-4cbf-aa1c-8adefe9dc35f&login=true&scope=openid",
    "background_color": "transparent",
    "display": "standalone",
    "orientation": "any",
    "theme_color": "transparent",
    "related_applications" : [],
    "prefer_related_applications" : false,
    "generated" : "true",
    "icons": [
        {
            "src": "/alice-ael/resources/img/icon-pwa-96x96.png",
            "sizes": "96x96",
            "type": "image/png"
        },
        {
            "src": "/alice-ael/resources/img/icon-pwa-144x144.png",
            "sizes": "144x144",
            "type": "image/png"
        },
        {
            "src": "/alice-ael/resources/img/icon-pwa-192x192.png",
            "sizes": "192x192",
            "type": "image/png"
        },
        {
            "src": "/alice-ael/resources/img/icon-pwa-512x512.png",
            "sizes": "512x512",
            "type": "image/png"
        }
    ]

and for finishing the serviceworker :

<ui:composition xmlns="http://www.w3.org/1999/xhtml"
                xmlns:ui="http://java.sun.com/jsf/facelets">

    <script type="text/javascript">
        if("serviceWorker" in navigator) {
            if (navigator.serviceWorker.controller) {
                console.log("Service worker trouver");
            } else {
                navigator.serviceWorker.register("/alice-ael/resources/js/service-worker.js", {
                    scope: './'
                })
                .then((reg) => {
                    console.log("Service worker authentifier" + reg.scope);
                });
            }
        }
    </script>

</ui:composition>

Thanks, for your help.

1 Answers

You can use https://www.pwabuilder.com/ to analyze the issues (related to PWA) in your site by just putting the URL and also helps achieving the same.

Hope it helps!

Related