<!DOCTYPE html><!--
~ Copyright 2016 Red Hat, Inc. and/or its affiliates
~ and other contributors as indicated by the @author tags.
~
~ Licensed under the Apache License, Version 2.0 (the "License");
~ you may not use this file except in compliance with the License.
~ You may obtain a copy of the License at
~
~ http://www.apache.org/licenses/LICENSE-2.0
~
~ Unless required by applicable law or agreed to in writing, software
~ distributed under the License is distributed on an "AS IS" BASIS,
~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
~ See the License for the specific language governing permissions and
~ limitations under the License.
--><html><head><title>Authentication Example</title><metahttp-equiv="Content-Security-Policy"content="default-src * gap://ready; style-src 'self' 'unsafe-inline'; script-src 'self' 'unsafe-inline' 'unsafe-eval'"><scripttype="text/javascript"charset="utf-8"src="cordova.js"></script><scripttype="text/javascript"charset="utf-8"src="keycloak.js"></script><scripttype="text/javascript"charset="utf-8">var keycloak = new Keycloak();
keycloak.onAuthSuccess = updateState;
keycloak.onAuthRefreshSuccess = updateState;
keycloak.onAuthLogout = updateState;
functionupdateState() {
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 = newDate(keycloak.tokenParsed.exp * 1000).toLocaleString();
document.getElementById('tokenRefreshExpires').innerText = newDate(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';
}
}
functionerror() {
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({
adapter: 'cordova-native',
responseMode: 'query',
onLoad: 'check-sso',
redirectUri: 'android-app://org.keycloak.examples.cordova/https/keycloak-cordova-example.github.io/login'
}).success(updateState).error(error);
}, false);
</script><style>td {
vertical-align: top;
}
tr.oddtd {
background-color: #eee;
}
</style></head><body><divid="authenticated"style="display: none;"><div><buttononclick="keycloak.logout()">Log out</button><buttononclick="keycloak.updateToken()">Refresh token</button><buttononclick="keycloak.updateToken(9999)">Force Refresh token</button><buttononclick="keycloak.accountManagement()">Manage account</button></div><div><table><tr><td>Subject</td><tdid="subject"></td></tr><trclass="odd"><td>Username</td><tdid="username"></td></tr><tr><td>Token expires</td><tdid="tokenExpires"></td></tr><trclass="odd"><td>Refresh token expires</td><tdid="tokenRefreshExpires"></td></tr><tr><td>Token</td><td><preid="token"></pre></td></tr><trclass="odd"><td>ID Token</td><td><preid="idToken"></pre></td></tr></table></div></div><divid="not-authenticated"style="display: none;"><div><buttononclick="keycloak.login()">Log in</button></div><div><pid="error">Not authenticated</p></div></div></body></html>