Partager via


getAuthTokenProvider

Omnicanal pour Customer Service contient une suite de capacités qui étendent la puissance de Dynamics 365 Customer Service Enterprise pour permettre aux organisations de se connecter et d’interagir instantanément avec leurs clients sur les canaux de messagerie numérique. Une licence supplémentaire est requise pour accéder à Omnichannel pour Customer Service. Pour plus d’informations, voir les pages Vue d’ensemble de la tarification de Dynamics 365 Customer Service et Plan de tarification de Dynamics 365 Customer Service.

Obtient le fournisseur de jeton d’authentification actuellement défini, le cas échéant.

Note

Les méthodes SDK de chat en direct doivent être appelées après le déclenchement de l’événement lcw :ready . Vous pouvez écouter cet événement en ajoutant votre propre écouteur d’événements sur l’objet window.

Ce SDK n’est applicable que si l’authentification est activée pour le widget. Pour activer l’authentification de votre widget, consultez la section Créer des paramètres d’authentification de chat.

Syntaxe

Microsoft.Omnichannel.LiveChatWidget.SDK.getAuthTokenProvider();

Paramètres

Aucun

Valeur de retour

Renvoie le fournisseur de jeton d’authentification actuellement défini, le cas échéant. S’il n’y a pas de fournisseur de jeton d’authentification enregistré, il renvoie null.

Example

let payloadToEncrypt = {
    "sub" : "87b4d06c-abc2-e811-a9b0-000d3a10e09e",
    "lwicontexts" :"{\"msdyn_cartvalue\":\"10000\", \"msdyn_isvip\":\"false\"}",
    "iat" : 1542622071,
    "iss" : "contosohelp.com",
    "exp" : 1542625672,
    "nbf" : 1542622072
};

function convertToJwtToken(payloadToEncrypt){
    // Ideally, you should call your service to convert the payload to a valid JSON Web Token
    return Promise.resolve("eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiI4N2I0ZDA2Yy1hYmMyLWU4MTEtYTliMC0wMDBkM2ExMGUwOWUiLCJsd2ljb250ZXh0cyI6IntcIm1zZHluX2NhcnR2YWx1ZVwiOlwiMTAwMDBcIiwgXCJtc2R5bl9pc3ZpcFwiOlwiZmFsc2VcIn0iLCJpYXQiOjE1NDI2MjIwNzEsImlzcyI6ImNvbnRvc29oZWxwLmNvbSIsImV4cCI6MTU0MjYyNTY3MiwibmJmIjoxNTQyNjIyMDcyfQ.r37z1M5rMyRYMOJ-rhyTRYFOgvl9N7KvTMueSFPkiuM");
}

window.addEventListener("lcw:ready", function handleLivechatReadyEvent(){
// Sets the auth-token provider
// Throws an error if authTokenProvider is not a function
    convertToJwtToken(payloadToEncrypt).then(function (jwtToken){
        Microsoft.Omnichannel.LiveChatWidget.SDK.setAuthTokenProvider(function authTokenProvider(callback){
            callback(jwtToken);
        });

        // Gets the currently set authentication token provider
        // If there is no registered authentication token provider, then it returns null
        let registeredAuthTokenProvider = Microsoft.Omnichannel.LiveChatWidget.SDK.getAuthTokenProvider();
    });
});

Référence de l’API JavaScript pour le SDK de chat en direct