The Communication Widget is not loading due to the JWT token issue.

0

401 unauthorized I am using Java implementation for Jwt token generation. and then providing it inside the communication widget's **authenticate **snippet field. but still, it is not loading. Here is my Java implementation:

private static final String CONNECT_SECRET = "nxt6b+vxK5oXduANxx/xTx8UE3B+68FTwIHZs0Kexxx";
    private static final String WIDGET_ID = "1axa7xc8-93x9-4xd7-96a5-c01x52cxxxxx";
    private static final long JWT_EXP_DELTA_SECONDS = 600;

    public String generateJWT() {
        Map<String, Object> payload = new HashMap<>();
        payload.put("sub", WIDGET_ID);
        payload.put("iat", Instant.now().getEpochSecond());
        payload.put("exp", Instant.now().plusSeconds(JWT_EXP_DELTA_SECONDS).getEpochSecond());

        return Jwts.builder()
                .setHeaderParam("typ", "JWT")
                .setHeaderParam("alg", "HS256")
                .setClaims(payload)
                .signWith(SignatureAlgorithm.HS256, CONNECT_SECRET)
                .compact();

    }

and here is my Javascript implementation:

<script  sec:authorize="isAuthenticated() && (hasRole('ROLE_AGENT') || hasRole('ROLE_BUYER'))">
    let loggedInUsername;
    loggedInUsername = document.getElementById("loggedInUserName").textContent;
    if (loggedInUsername === "") {
        loggedInUsername = "Guest";
    }
    (function (w, d, x, id) {
        s = d.createElement('script');
        s.src = 'https://dtn7rvxwwlhud.cloudfront.net/amazon-connect-chat-interface-client.js';
        s.async = 1;
        s.id = id;
        d.getElementsByTagName('head')[0].appendChild(s);
        w[x] = w[x] || function () {
            (w[x].ac = w[x].ac || []).push(arguments)
        };
    })(window, document, 'amazon_connect', '1axa7xc8-93x9-4xd7-96a5-c01x52cxxxxx');
    amazon_connect('styles', {
        iconType: 'CHAT',
        openChat: {color: '#ffffff', backgroundColor: '#123456'},
        closeChat: {color: '#ffffff', backgroundColor: '#123456'}
    });
    amazon_connect('authenticate', function(callback) {
        window.fetch('/user/generateJwtForConnect').then(res => {
            res.json().then(data => {
                console.log("success", data.message);
                callback(data.message);
            });
        });
    });
    amazon_connect('snippetId', [removed_due_to_long_text]');
    amazon_connect('supportedMessagingContentTypes', ['text/plain', 'text/markdown']);
    amazon_connect('customerDisplayName', function(callback) {
        callback(loggedInUsername);
    });
</script>

the connect secret and widget id are correct. still, it is not loading. instead, it shows that I can not load the chat widget right now.

shafin
gefragt vor 2 Monaten106 Aufrufe
Keine Antworten

Du bist nicht angemeldet. Anmelden um eine Antwort zu veröffentlichen.

Eine gute Antwort beantwortet die Frage klar, gibt konstruktives Feedback und fördert die berufliche Weiterentwicklung des Fragenstellers.

Richtlinien für die Beantwortung von Fragen