keycloak-aplcache
Changes
integration/js/src/main/resources/keycloak.js 24(+12 -12)
Details
diff --git a/docbook/reference/en/en-US/modules/javascript-adapter.xml b/docbook/reference/en/en-US/modules/javascript-adapter.xml
index 80f04ed..30f8dd0 100755
--- a/docbook/reference/en/en-US/modules/javascript-adapter.xml
+++ b/docbook/reference/en/en-US/modules/javascript-adapter.xml
@@ -305,6 +305,23 @@ keycloak.updateToken(5).success(function(refreshed) {
]]></programlisting>
</simplesect>
+
+ <simplesect>
+ <title>clearToken()</title>
+
+ <para>
+ Clear authentication state, including tokens. This can be useful if application has detected the session
+ has expired, for example if updating token fails. Invoking this results in onAuthLogout callback listener
+ being invoked.
+ </para>
+
+ <programlisting><![CDATA[
+keycloak.updateToken(5).error(function() {
+ keycloak.clearToken();
+});
+]]></programlisting>
+
+ </simplesect>
</section>
<section>
integration/js/src/main/resources/keycloak.js 24(+12 -12)
diff --git a/integration/js/src/main/resources/keycloak.js b/integration/js/src/main/resources/keycloak.js
index 13b813b..7ff1959 100755
--- a/integration/js/src/main/resources/keycloak.js
+++ b/integration/js/src/main/resources/keycloak.js
@@ -336,6 +336,16 @@
return promise.promise;
}
+ kc.clearToken = function() {
+ if (kc.token) {
+ setToken(null, null, null);
+ kc.onAuthLogout && kc.onAuthLogout();
+ if (kc.loginRequired) {
+ kc.login();
+ }
+ }
+ }
+
function getRealmUrl() {
if (kc.authServerUrl.charAt(kc.authServerUrl.length - 1) == '/') {
return kc.authServerUrl + 'realms/' + encodeURIComponent(kc.realm);
@@ -463,16 +473,6 @@
return promise.promise;
}
- function clearToken() {
- if (kc.token) {
- setToken(null, null, null);
- kc.onAuthLogout && kc.onAuthLogout();
- if (kc.loginRequired) {
- kc.login();
- }
- }
- }
-
function setToken(token, refreshToken, idToken) {
if (token) {
kc.token = token;
@@ -697,7 +697,7 @@
if ((!kc.sessionId || kc.sessionId == data.session) && data.loggedIn) {
promise.setSuccess();
} else {
- clearToken();
+ kc.clearToken();
promise.setError();
}
};
@@ -832,7 +832,7 @@
if (error) {
promise.setError();
} else {
- clearToken();
+ kc.clearToken();
promise.setSuccess();
}
});