keycloak JavaScript Adapter

I used ionic to create a mobile app, and when keycloak logged in, keycloak.authenticated=false. Could you tell me how to solve it? Thank you!!!

Authentication Example
<meta http-equiv="Content-Security-Policy" content="default-src * gap://ready; style-src 'self' 'unsafe-inline'; script-src 'self' 'unsafe-inline' 'unsafe-eval'">

<script type="text/javascript" charset="utf-8" src="cordova.js"></script>
 <script type="text/javascript" charset="utf-8" src="./assets/keycloak.js"></script> 
<!-- <script src=""></script> -->
<script type="text/javascript" charset="utf-8">
//  var vConsole = new VConsole();

     //var keycloak = new Keycloak();

var keycloak = new Keycloak(
url: ‘’,
realm: ‘example1’,
clientId: ‘cordova’
keycloak.onAuthSuccess = updateState;
keycloak.onAuthRefreshSuccess = updateState;
keycloak.onAuthLogout = updateState;

    function updateState() {
        if (keycloak.authenticated) {
            document.getElementById('authenticated').style.display = 'block';
            document.getElementById('not-authenticated').style.display = 'none';

            document.getElementById('subject').innerText = keycloak.subject;
            document.getElementById('username').innerText = keycloak.idTokenParsed.preferred_username;
            document.getElementById('tokenExpires').innerText = new Date(keycloak.tokenParsed.exp * 1000).toLocaleString();
            document.getElementById('tokenRefreshExpires').innerText = new Date(keycloak.refreshTokenParsed.exp * 1000).toLocaleString();
            document.getElementById('token').innerText = JSON.stringify(keycloak.tokenParsed, null, '  ');
            document.getElementById('idToken').innerText = JSON.stringify(keycloak.idTokenParsed, null, '  ');
        } else {
            document.getElementById('authenticated').style.display = 'none';
            document.getElementById('not-authenticated').style.display = 'block';

    function error() {
        document.getElementById('authenticated').style.display = 'none';
        document.getElementById('not-authenticated').style.display = 'block';
        document.getElementById('error').innerText = 'Failed to initialize Keycloak adapter';

    document.addEventListener("deviceready", function() {
        keycloak.init({ onLoad: "check-sso" }).success(updateState).error(error);
    }, false);
    td {
        vertical-align: top;

    tr.odd td {
        background-color: #eee;
Log out Refresh token Force Refresh token Manage account
Token expires
Refresh token expires
ID Token
Log in

Not authenticated

Looks like you created some example app. Is it possible to share the source code (including some readme) with us or you can’t reveal? It would be much easier for us to reproduce it given an example app.